ECUiVADE commited on
Commit
563477e
1 Parent(s): 9c95f36

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +40 -19
app.py CHANGED
@@ -48,27 +48,48 @@ def reset_state():
48
  return [], []
49
 
50
 
51
- with gr.Blocks() as demo:
52
- gr.HTML("""<h1 align="center">So Rude</h1>""")
 
 
 
 
 
 
 
 
 
 
 
 
 
 
53
 
54
- chatbot = gr.Chatbot()
55
- with gr.Row():
56
- with gr.Column(scale=4):
57
- user_input = gr.Textbox(show_label=False, placeholder="Input...", lines=8, elem_id="user_input")
58
- submitBtn = gr.Button("Submit", variant="primary", elem_id="submit_btn")
59
- with gr.Column(scale=1):
60
- max_length = gr.Slider(0, 256, value=64, step=1.0, label="Maximum Length", interactive=True)
61
- top_p = gr.Slider(0, 1, value=0.7, step=0.01, label="Top P", interactive=True)
62
- temperature = gr.Slider(0, 2.0, value=0.95, step=0.01, label="Temperature", interactive=True)
63
- emptyBtn = gr.Button("Clear History")
64
 
65
- history = gr.State([])
 
 
66
 
67
- submitBtn.click(
68
- predict, [user_input, chatbot, max_length, top_p, temperature, history], [chatbot, history], show_progress=True
69
- )
70
- submitBtn.click(reset_user_input, [], [user_input])
71
 
72
- emptyBtn.click(reset_state, outputs=[chatbot, history], show_progress=True)
 
73
 
74
- demo.queue().launch(share=False, inbrowser=True)
 
 
 
 
 
 
 
 
 
 
48
  return [], []
49
 
50
 
51
+ def AIPatient(message):
52
+
53
+ global isFirstRun, history,context
54
+
55
+ if isFirstRun:
56
+ context = initContext
57
+ isFirstRun = False
58
+ #else:
59
+ #for turn in history:
60
+ # context += f"\n<|im_start|> Nurse: {turn[0]}\n<|im_start|> Barry: {turn[1]}"
61
+ context += """
62
+ <|im_start|>nurse
63
+ Nurse: """+message+"""
64
+ <|im_start|>barry
65
+ Barry:
66
+ """
67
 
68
+ response = ""
69
+ # Here, you should add the code to generate the response using your model
70
+ # For example:
71
+ while(len(response) < 1):
72
+ output = llm(context, max_tokens=400, stop=["Nurse:"], echo=False)
73
+ response = output["choices"][0]["text"]
74
+ response = response.strip()
 
 
 
75
 
76
+ with feedback_file.open("a") as f:
77
+ f.write(json.dumps({"Nurse": message, "Barry": response},indent=4))
78
+ f.write("\n")
79
 
80
+ context += response
81
+ print (context)
 
 
82
 
83
+ history.append((message,response))
84
+ return history
85
 
86
+ with gr.Blocks() as demo:
87
+ gr.Markdown("# AI Patient Chatbot")
88
+ with gr.Group():
89
+ with gr.Tab("Patient Chatbot"):
90
+ chatbot = gr.Chatbot()
91
+ message = gr.Textbox(label="Enter your message to Barry", placeholder="Type here...", lines=2)
92
+ send_message = gr.Button("Submit")
93
+ send_message.click(AIPatient, inputs=[message], outputs=[chatbot])
94
+ save_chatlog = gr.Button("Save Chatlog")
95
+ #send_message.click(SaveChatlog, inputs=[message], outputs=[chatbot])