NCTCMumbai commited on
Commit
073ef13
·
verified ·
1 Parent(s): 46e071a

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +22 -17
app.py CHANGED
@@ -99,7 +99,7 @@ def add_text(history, text):
99
  return history, gr.Textbox(value="", interactive=False)
100
 
101
  def bot(history, cross_encoder):
102
- global history
103
  top_rerank = 25
104
  top_k_rank = 20
105
  query = history[-1][0] if history else ''
@@ -160,8 +160,8 @@ def bot(history, cross_encoder):
160
 
161
  #def translate_text(response_text, selected_language):
162
 
163
- def translate_text(selected_language):
164
- global history
165
  iso_language_codes = {
166
  "Hindi": "hi",
167
  "Gom": "gom",
@@ -222,6 +222,7 @@ def translate_text(selected_language):
222
 
223
  # Gradio interface
224
  with gr.Blocks(theme='NoCrypt/miku') as CHATBOT:
 
225
  with gr.Row():
226
  with gr.Column(scale=10):
227
  gr.HTML(value="""<div style="color: #FF4500;"><h1>ADWITIYA-</h1> <h1><span style="color: #008000">Custom Manual Chatbot and Quizbot</span></h1></div>""")
@@ -264,22 +265,26 @@ with gr.Blocks(theme='NoCrypt/miku') as CHATBOT:
264
  prompt_html = gr.HTML()
265
 
266
  translated_textbox = gr.Textbox(label="Translated Response")
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
267
 
268
- txt_btn.click(
269
- add_text, [chatbot, txt], [chatbot, txt], queue=False
270
- ).then(
271
- bot, [cross_encoder], [chatbot, prompt_html]
272
- ).then(
273
- translate_text, [language_dropdown], translated_textbox
274
- )
275
 
276
- txt.submit(
277
- add_text, [chatbot, txt], [chatbot, txt], queue=False
278
- ).then(
279
- bot, [cross_encoder], [chatbot, prompt_html]
280
- ).then(
281
- translate_text, [language_dropdown], translated_textbox
282
- )
283
 
284
 
285
  # txt_msg = txt_btn.click(add_text, [chatbot, txt], [chatbot, txt], queue=False).then(
 
99
  return history, gr.Textbox(value="", interactive=False)
100
 
101
  def bot(history, cross_encoder):
102
+
103
  top_rerank = 25
104
  top_k_rank = 20
105
  query = history[-1][0] if history else ''
 
160
 
161
  #def translate_text(response_text, selected_language):
162
 
163
+ def translate_text(selected_language,history):
164
+
165
  iso_language_codes = {
166
  "Hindi": "hi",
167
  "Gom": "gom",
 
222
 
223
  # Gradio interface
224
  with gr.Blocks(theme='NoCrypt/miku') as CHATBOT:
225
+ history_state = gr.State(initial=[])
226
  with gr.Row():
227
  with gr.Column(scale=10):
228
  gr.HTML(value="""<div style="color: #FF4500;"><h1>ADWITIYA-</h1> <h1><span style="color: #008000">Custom Manual Chatbot and Quizbot</span></h1></div>""")
 
265
  prompt_html = gr.HTML()
266
 
267
  translated_textbox = gr.Textbox(label="Translated Response")
268
+ def update_history_and_translate(txt, cross_encoder, history_state, language_dropdown):
269
+ history = history_state.get()
270
+ history.append((txt, ""))
271
+ history_state.set(history)
272
+
273
+ # Call bot function
274
+ bot_output = list(bot(history, cross_encoder))
275
+ history, prompt_html = bot_output[-1]
276
+
277
+ # Update the history
278
+ history_state.set(history)
279
+
280
+ # Translate text
281
+ translated_text = translate_text(language_dropdown, history)
282
+ return history, prompt_html, translated_text
283
+
284
+ txt_msg = txt_btn.click(update_history_and_translate, [txt, cross_encoder, history_state, language_dropdown], [chatbot, prompt_html, translated_textbox])
285
+ txt_msg = txt.submit(update_history_and_translate, [txt, cross_encoder, history_state, language_dropdown], [chatbot, prompt_html, translated_textbox])
286
 
 
 
 
 
 
 
 
287
 
 
 
 
 
 
 
 
288
 
289
 
290
  # txt_msg = txt_btn.click(add_text, [chatbot, txt], [chatbot, txt], queue=False).then(