Karthikeyan commited on
Commit
836a196
1 Parent(s): 2b9fffc

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +20 -20
app.py CHANGED
@@ -85,7 +85,7 @@ history_state = gr.State()
85
  summarizer = Summarizer()
86
  sentiment = SentimentAnalyzer()
87
 
88
- class Chat_Bot:
89
 
90
  def __init__(self):
91
  pass
@@ -121,7 +121,7 @@ class Chat_Bot:
121
  scores = sentiment_scores.values()
122
  fig = px.bar(x=scores, y=labels, orientation='h', color=labels, color_discrete_map={"Negative": "red", "Positive": "green", "Neutral": "gray"})
123
  fig.update_traces(texttemplate='%{x:.2f}%', textposition='outside')
124
- fig.update_layout(height=300, width=160)
125
  return fig
126
 
127
  def _history_of_chat(self):
@@ -145,10 +145,10 @@ class Chat_Bot:
145
  start_sequence = "\nCustomer:"
146
  restart_sequence = "\nVodafone Customer Relationship Manager:"
147
  prompt = 'your task is make a conversation between a customer and vodafone telecom customer relationship manager.'
148
- file_path = "vodafone_customer_details.json"
149
  with open(file_path) as file:
150
  customer_details = json.load(file)
151
- prompt += f"{history}{start_sequence}{text}{restart_sequence} if customer ask any information take it from {customer_details} and if customer say thankyou You should end the conversation with greetings."
152
  response = openai.Completion.create(
153
  model="text-davinci-003",
154
  prompt=prompt,
@@ -185,20 +185,20 @@ class Chat_Bot:
185
  scores=self._text_box(customer_emotion,agent_emotion,agent_sentiment_score,customer_sentiment_score)
186
 
187
  customer_fig=self._display_graph(customer_sentiment_score)
188
- customer_fig.update_layout(title="Sentiment Analysis",width=400)
189
 
190
  agent_fig=self._display_graph(agent_sentiment_score)
191
- agent_fig.update_layout(title="Sentiment Analysis",width=400)
192
 
193
  agent_emotion_score = sentiment.emotion_analysis_for_graph(agent_emotion)
194
 
195
  agent_emotion_fig=self._display_graph(agent_emotion_score)
196
- agent_emotion_fig.update_layout(title="Emotion Analysis",width=400)
197
 
198
  customer_emotion_score = sentiment.emotion_analysis_for_graph(customer_emotion)
199
 
200
  customer_emotion_fig=self._display_graph(customer_emotion_score)
201
- customer_emotion_fig.update_layout(title="Emotion Analysis",width=400)
202
 
203
  return scores,customer_fig,agent_fig,customer_emotion_fig,agent_emotion_fig
204
 
@@ -259,17 +259,17 @@ class Chat_Bot:
259
  with gr.Row():
260
  gr.HTML("""<center><h1>Sentiment and Emotion Score Graph</h1></center>""")
261
  with gr.Row():
262
- with gr.Column(scale=0.50, min_width=0):
263
- plot =gr.Plot(label="Customer", size=(300, 400))
264
- # with gr.Row():
265
- with gr.Column(scale=0.50, min_width=0):
266
- plot_2 =gr.Plot(label="Agent", size=(300, 400))
267
  with gr.Row():
268
- with gr.Column(scale=0.50, min_width=0):
269
- plot_3 =gr.Plot(label="Customer_Emotion", size=(300, 400))
270
- # with gr.Row():
271
- with gr.Column(scale=0.50, min_width=0):
272
- plot_4 =gr.Plot(label="Agent_Emotion", size=(300, 400))
 
 
 
273
 
274
 
275
  txt_msg = txt.submit(self._add_text, [chatbot, txt], [chatbot, txt])
@@ -285,5 +285,5 @@ class Chat_Bot:
285
 
286
  demo.title = "Vodafone Generative AI CRM ChatBot"
287
  demo.launch()
288
- bot = Chat_Bot()
289
- bot.gradio_interface()
 
85
  summarizer = Summarizer()
86
  sentiment = SentimentAnalyzer()
87
 
88
+ class LangChain_Document_QA:
89
 
90
  def __init__(self):
91
  pass
 
121
  scores = sentiment_scores.values()
122
  fig = px.bar(x=scores, y=labels, orientation='h', color=labels, color_discrete_map={"Negative": "red", "Positive": "green", "Neutral": "gray"})
123
  fig.update_traces(texttemplate='%{x:.2f}%', textposition='outside')
124
+ fig.update_layout(height=500, width=200)
125
  return fig
126
 
127
  def _history_of_chat(self):
 
145
  start_sequence = "\nCustomer:"
146
  restart_sequence = "\nVodafone Customer Relationship Manager:"
147
  prompt = 'your task is make a conversation between a customer and vodafone telecom customer relationship manager.'
148
+ file_path = "/content/vodafone_customer_details.json"
149
  with open(file_path) as file:
150
  customer_details = json.load(file)
151
+ prompt = f"{history}{start_sequence}{text}{restart_sequence} if customer ask any information take it from {customer_details} and if customer say thankyou You should end the conversation with greetings."
152
  response = openai.Completion.create(
153
  model="text-davinci-003",
154
  prompt=prompt,
 
185
  scores=self._text_box(customer_emotion,agent_emotion,agent_sentiment_score,customer_sentiment_score)
186
 
187
  customer_fig=self._display_graph(customer_sentiment_score)
188
+ customer_fig.update_layout(title="Sentiment Analysis",width=800)
189
 
190
  agent_fig=self._display_graph(agent_sentiment_score)
191
+ agent_fig.update_layout(title="Sentiment Analysis",width=800)
192
 
193
  agent_emotion_score = sentiment.emotion_analysis_for_graph(agent_emotion)
194
 
195
  agent_emotion_fig=self._display_graph(agent_emotion_score)
196
+ agent_emotion_fig.update_layout(title="Emotion Analysis",width=800)
197
 
198
  customer_emotion_score = sentiment.emotion_analysis_for_graph(customer_emotion)
199
 
200
  customer_emotion_fig=self._display_graph(customer_emotion_score)
201
+ customer_emotion_fig.update_layout(title="Emotion Analysis",width=800)
202
 
203
  return scores,customer_fig,agent_fig,customer_emotion_fig,agent_emotion_fig
204
 
 
259
  with gr.Row():
260
  gr.HTML("""<center><h1>Sentiment and Emotion Score Graph</h1></center>""")
261
  with gr.Row():
262
+ with gr.Column(scale=0.70, min_width=0):
263
+ plot =gr.Plot(label="Customer", size=(500, 600))
 
 
 
264
  with gr.Row():
265
+ with gr.Column(scale=0.70, min_width=0):
266
+ plot_2 =gr.Plot(label="Agent", size=(500, 600))
267
+ with gr.Row():
268
+ with gr.Column(scale=0.70, min_width=0):
269
+ plot_3 =gr.Plot(label="Customer_Emotion", size=(500, 600))
270
+ with gr.Row():
271
+ with gr.Column(scale=0.70, min_width=0):
272
+ plot_4 =gr.Plot(label="Agent_Emotion", size=(500, 600))
273
 
274
 
275
  txt_msg = txt.submit(self._add_text, [chatbot, txt], [chatbot, txt])
 
285
 
286
  demo.title = "Vodafone Generative AI CRM ChatBot"
287
  demo.launch()
288
+ document_qa =LangChain_Document_QA()
289
+ document_qa.gradio_interface()