Update app.py
Browse files
app.py
CHANGED
@@ -48,27 +48,48 @@ def reset_state():
|
|
48 |
return [], []
|
49 |
|
50 |
|
51 |
-
|
52 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
53 |
|
54 |
-
|
55 |
-
|
56 |
-
|
57 |
-
|
58 |
-
|
59 |
-
|
60 |
-
|
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 |
-
|
|
|
|
|
66 |
|
67 |
-
|
68 |
-
|
69 |
-
)
|
70 |
-
submitBtn.click(reset_user_input, [], [user_input])
|
71 |
|
72 |
-
|
|
|
73 |
|
74 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
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])
|