Karthikeyan commited on
Commit
7b9ee38
β€’
1 Parent(s): 48ec97d

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +56 -65
app.py CHANGED
@@ -14,7 +14,6 @@ import plotly.express as px
14
  class SentimentAnalyzer:
15
  def __init__(self):
16
  self.model="facebook/bart-large-mnli"
17
-
18
  def analyze_sentiment(self, text):
19
  pipe = pipeline("zero-shot-classification", model=self.model)
20
  label=["positive","negative","neutral"]
@@ -61,9 +60,11 @@ Please analyze the text and provide the output in the following format: emotion:
61
  print(score_dict)
62
  return score_dict
63
 
 
64
  class Summarizer:
65
  def __init__(self):
66
  pass
 
67
  def generate_summary(self, text):
68
  model_engine = "text-davinci-003"
69
  prompt = f"""summarize the following conversation delimited by triple backticks.
@@ -80,15 +81,15 @@ class Summarizer:
80
  message = completions.choices[0].text.strip()
81
  return message
82
 
83
-
84
- history_state = gr.State([])
85
  summarizer = Summarizer()
86
  sentiment = SentimentAnalyzer()
87
 
88
  class LangChain_Document_QA:
89
 
90
  def __init__(self):
91
- pass
 
92
  def _add_text(self,history, text):
93
  history = history + [(text, None)]
94
  history_state.value = history
@@ -143,11 +144,11 @@ class LangChain_Document_QA:
143
  history = self._chat_history()
144
  start_sequence = "\nCustomer:"
145
  restart_sequence = "\nVodafone Customer Relationship Manager:"
146
- prompt = 'your task is make a conversation between a customer and vodafone telecom customer relationship manager.at end the conversation thanks for coming'
147
  file_path = "/content/vodafone_customer_details.json"
148
  with open(file_path) as file:
149
  customer_details = json.load(file)
150
- prompt = f"{history}{start_sequence}{text}{restart_sequence} if customer ask any information take it from {customer_details}."
151
  response = openai.Completion.create(
152
  model="text-davinci-003",
153
  prompt=prompt,
@@ -202,97 +203,87 @@ class LangChain_Document_QA:
202
  return scores,customer_fig,agent_fig,customer_emotion_fig,agent_emotion_fig
203
 
204
 
205
- def clear_func(self,history_state):
206
- history_state.clear()
207
-
208
 
209
  def gradio_interface(self):
210
- with gr.Blocks(css="style.css",theme=gr.themes.Soft()) as demo:
211
- with gr.Row():
212
- gr.HTML("""<img class="leftimage" align="left" src="https://templates.images.credential.net/1612472097627370951721412474196.png" alt="Image" width="210" height="210">
213
  <img align="right" class="rightimage" src="https://download.logo.wine/logo/Vodafone/Vodafone-Logo.wine.png" alt="Image" width="230" height="230" >""")
214
-
215
- with gr.Row():
216
- gr.HTML("""<center><h1>Vodafone Generative AI CRM ChatBot</h1></center>""")
217
- gr.HTML(
218
- """<br style="color:white;">"""
219
- )
220
- chatbot = gr.Chatbot([], elem_id="chatbot").style(height=300)
221
- with gr.Row():
222
- with gr.Column(scale=0.50):
223
  txt = gr.Textbox(
224
  show_label=False,
225
  placeholder="Customer",
226
  ).style(container=False)
227
- with gr.Column(scale=0.50):
228
  txt2 = gr.Textbox(
229
  show_label=False,
230
  placeholder="Agent",
231
  ).style(container=False)
232
-
233
- with gr.Column(scale=0.40):
234
  txt3 =gr.Textbox(
235
  show_label=False,
236
  placeholder="GPT_Suggestion",
237
  ).style(container=False)
238
- with gr.Column(scale=0.10, min_width=0):
239
  button=gr.Button(
240
  value="πŸš€"
241
  )
242
- with gr.Row(scale=0.50):
243
- emptyBtn = gr.Button(
244
- "🧹 New Conversation",
245
- )
246
- with gr.Row():
247
- with gr.Column(scale=0.40):
248
  txt4 =gr.Textbox(
249
  show_label=False,
250
  lines=4,
251
  placeholder="Summary",
252
  ).style(container=False)
253
- with gr.Column(scale=0.10, min_width=0):
254
  end_btn=gr.Button(
255
  value="End"
256
  )
257
- with gr.Column(scale=0.40):
258
  txt5 =gr.Textbox(
259
  show_label=False,
260
  lines=4,
261
  placeholder="Sentiment",
262
  ).style(container=False)
263
-
264
- with gr.Column(scale=0.10, min_width=0):
265
  Sentiment_btn=gr.Button(
266
  value="πŸ“Š",callback=self._on_sentiment_btn_click
267
  )
268
- with gr.Row():
269
- gr.HTML("""<center><h1>Sentiment and Emotion Score Graph</h1></center>""")
270
- with gr.Row():
271
- with gr.Column(scale=0.70, min_width=0):
272
- plot =gr.Plot(label="Customer", size=(500, 600))
273
- with gr.Row():
274
- with gr.Column(scale=0.70, min_width=0):
275
- plot_2 =gr.Plot(label="Agent", size=(500, 600))
276
- with gr.Row():
277
- with gr.Column(scale=0.70, min_width=0):
278
- plot_3 =gr.Plot(label="Customer_Emotion", size=(500, 600))
279
- with gr.Row():
280
- with gr.Column(scale=0.70, min_width=0):
281
- plot_4 =gr.Plot(label="Agent_Emotion", size=(500, 600))
282
-
283
-
284
- txt_msg = txt.submit(self._add_text, [chatbot, txt], [chatbot, txt])
285
- txt_msg.then(lambda: gr.update(interactive=True), None, [txt])
286
- txt.submit(self._suggested_answer,txt,txt3)
287
- button.click(self._agent_text, [chatbot,txt3], chatbot)
288
- txt2.submit(self._agent_text, [chatbot, txt2], chatbot).then(
289
  self._agent_text, [chatbot, txt2], chatbot
290
- )
291
- end_btn.click(self._display_history, [], txt4)
292
- emptyBtn.click(self.clear_func,history_state,[])
293
- emptyBtn.click(lambda: None, None, chatbot, queue=False)
294
-
295
- Sentiment_btn.click(self._on_sentiment_btn_click,[],[txt5,plot,plot_2,plot_3,plot_4])
296
-
297
- demo.title = "Vodafone Generative AI CRM ChatBot"
298
- demo.launch()
 
14
  class SentimentAnalyzer:
15
  def __init__(self):
16
  self.model="facebook/bart-large-mnli"
 
17
  def analyze_sentiment(self, text):
18
  pipe = pipeline("zero-shot-classification", model=self.model)
19
  label=["positive","negative","neutral"]
 
60
  print(score_dict)
61
  return score_dict
62
 
63
+
64
  class Summarizer:
65
  def __init__(self):
66
  pass
67
+
68
  def generate_summary(self, text):
69
  model_engine = "text-davinci-003"
70
  prompt = f"""summarize the following conversation delimited by triple backticks.
 
81
  message = completions.choices[0].text.strip()
82
  return message
83
 
84
+ history_state = gr.State()
 
85
  summarizer = Summarizer()
86
  sentiment = SentimentAnalyzer()
87
 
88
  class LangChain_Document_QA:
89
 
90
  def __init__(self):
91
+ pass
92
+
93
  def _add_text(self,history, text):
94
  history = history + [(text, None)]
95
  history_state.value = history
 
144
  history = self._chat_history()
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,
 
203
  return scores,customer_fig,agent_fig,customer_emotion_fig,agent_emotion_fig
204
 
205
 
 
 
 
206
 
207
  def gradio_interface(self):
208
+ with gr.Blocks(css="style.css",theme=gr.themes.Soft()) as demo:
209
+ with gr.Row():
210
+ gr.HTML("""<img class="leftimage" align="left" src="https://templates.images.credential.net/1612472097627370951721412474196.png" alt="Image" width="210" height="210">
211
  <img align="right" class="rightimage" src="https://download.logo.wine/logo/Vodafone/Vodafone-Logo.wine.png" alt="Image" width="230" height="230" >""")
212
+
213
+ with gr.Row():
214
+ gr.HTML("""<center><h1>Vodafone Generative AI CRM ChatBot</h1></center>""")
215
+ chatbot = gr.Chatbot([], elem_id="chatbot").style(height=300)
216
+ with gr.Row():
217
+ with gr.Column(scale=0.50):
 
 
 
218
  txt = gr.Textbox(
219
  show_label=False,
220
  placeholder="Customer",
221
  ).style(container=False)
222
+ with gr.Column(scale=0.50):
223
  txt2 = gr.Textbox(
224
  show_label=False,
225
  placeholder="Agent",
226
  ).style(container=False)
227
+
228
+ with gr.Column(scale=0.40):
229
  txt3 =gr.Textbox(
230
  show_label=False,
231
  placeholder="GPT_Suggestion",
232
  ).style(container=False)
233
+ with gr.Column(scale=0.10, min_width=0):
234
  button=gr.Button(
235
  value="πŸš€"
236
  )
237
+ with gr.Row():
238
+ with gr.Column(scale=0.40):
 
 
 
 
239
  txt4 =gr.Textbox(
240
  show_label=False,
241
  lines=4,
242
  placeholder="Summary",
243
  ).style(container=False)
244
+ with gr.Column(scale=0.10, min_width=0):
245
  end_btn=gr.Button(
246
  value="End"
247
  )
248
+ with gr.Column(scale=0.40):
249
  txt5 =gr.Textbox(
250
  show_label=False,
251
  lines=4,
252
  placeholder="Sentiment",
253
  ).style(container=False)
254
+
255
+ with gr.Column(scale=0.10, min_width=0):
256
  Sentiment_btn=gr.Button(
257
  value="πŸ“Š",callback=self._on_sentiment_btn_click
258
  )
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])
276
+ txt_msg.then(lambda: gr.update(interactive=True), None, [txt])
277
+ txt.submit(self._suggested_answer,txt,txt3)
278
+ button.click(self._agent_text, [chatbot,txt3], chatbot)
279
+ txt2.submit(self._agent_text, [chatbot, txt2], chatbot).then(
280
  self._agent_text, [chatbot, txt2], chatbot
281
+ )
282
+ end_btn.click(self._display_history, [], txt4)
283
+
284
+ Sentiment_btn.click(self._on_sentiment_btn_click,[],[txt5,plot,plot_2,plot_3,plot_4])
285
+
286
+ demo.title = "Vodafone Generative AI CRM ChatBot"
287
+ demo.launch()
288
+ document_qa =LangChain_Document_QA()
289
+ document_qa.gradio_interface()