letrunglinh commited on
Commit
13db79f
1 Parent(s): 29ba7fe

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +23 -10
app.py CHANGED
@@ -56,13 +56,26 @@ def get_answer_e2e(question):
56
 
57
  return best_answer
58
 
59
- if __name__ == "__main__":
60
- title = "CHATBOT - I know what you want 💬"
61
- description = "This is demo that developed by AI team (Main contributor : Mr.Nguyen Thanh Dat)"
62
- #inputs = gr.inputs.Textbox(label="Enter your question", lines=10)
63
- #outputs = gr.outputs.Textbox(label="Answer", lines=10)
64
- icon = "icon.png"
65
- bot = gr.Interface(fn=get_answer_e2e, inputs=["text"], outputs=["textbox"], theme = "huggingface" , title=title, description=description, favicon=icon)
66
- #bot.enable_chat()
67
- bot.launch()
68
- #gr.chatbot(get_answer_e2e, title=title, description=description, favicon=icon, theme="huggingface").launch()
 
 
 
 
 
 
 
 
 
 
 
 
 
 
56
 
57
  return best_answer
58
 
59
+ with gr.Blocks(theme=gr.themes.Soft()) as demo:
60
+ gr.Markdown("<h1><center>CHATBOT - I know what you want 💬</center></h1>")
61
+ chatbot = gr.Chatbot(show_label=True, value=[[None,'Hi👋,How can i help you?']])
62
+ msg = gr.Textbox(label="Question",placeholder="Enter your question and press Enter...")
63
+ clear = gr.Button("Clear")
64
+
65
+ def user(user_message, history):
66
+ return "", history + [[user_message, None]]
67
+
68
+ def bot(history):
69
+
70
+ best_answer = get_answer_e2e(history[-1][0])
71
+
72
+ history[-1][1] = best_answer
73
+
74
+ return history
75
+
76
+ msg.submit(user, [msg, chatbot], [msg, chatbot], queue=False ,scroll_to_output=True, show_progress=True, ).then(
77
+ bot, chatbot, chatbot
78
+ )
79
+ clear.click(lambda: None, None, chatbot, queue=False)
80
+
81
+ demo.launch()