Spaces:
Runtime error
Runtime error
Update app.py
Browse files
app.py
CHANGED
@@ -1,30 +1,47 @@
|
|
1 |
-
import gradio as gr
|
2 |
-
import
|
3 |
-
|
4 |
-
|
5 |
-
|
6 |
-
|
7 |
-
|
8 |
-
|
9 |
-
|
10 |
-
|
11 |
-
|
12 |
-
|
13 |
-
|
14 |
-
|
15 |
-
|
16 |
-
|
17 |
-
|
18 |
-
|
19 |
-
|
20 |
-
|
21 |
-
|
22 |
-
|
23 |
-
|
24 |
-
|
25 |
-
|
26 |
-
|
27 |
-
|
28 |
-
|
29 |
-
|
30 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
import gradio as gr
|
2 |
+
import shutil
|
3 |
+
import os
|
4 |
+
import ollama
|
5 |
+
import time
|
6 |
+
#import pandas as pd
|
7 |
+
global Modelfile # Declare Modelfile as a global variable
|
8 |
+
|
9 |
+
|
10 |
+
#def Generate_report(history,model_flags):
|
11 |
+
# data={'steps':model_flags,
|
12 |
+
# 'turns':history}
|
13 |
+
# dataframe=pd.DataFrame.from_dict(data)
|
14 |
+
#dataframe.to_csv('Repports.csv',index=False)
|
15 |
+
|
16 |
+
|
17 |
+
def user(user_message,history):
|
18 |
+
return "", history+[{'role': 'user', 'content':user_message}]
|
19 |
+
def respond(history):
|
20 |
+
text=f"<s> ###Human: {history[-1]['content']} ###Asistant: "
|
21 |
+
response=ollama.generate(
|
22 |
+
model='LLAMA3.2 Virtual_doctor2:latest',
|
23 |
+
prompt=text,
|
24 |
+
stream=False,
|
25 |
+
)
|
26 |
+
history.append({'role':'assistant','content':""})
|
27 |
+
for character in response['response']:
|
28 |
+
history[-1]['content']+=character
|
29 |
+
time.sleep(0.02)
|
30 |
+
yield history
|
31 |
+
|
32 |
+
|
33 |
+
|
34 |
+
with gr.Blocks() as demo:
|
35 |
+
gr.Markdown('# AI Therapist for (CBT and FIT)')
|
36 |
+
with gr.Tab('Chat Interface'):
|
37 |
+
gr.HTML('<h1> Fake client chatbot </h2>')
|
38 |
+
chatbot = gr.Chatbot(type="messages")
|
39 |
+
msg = gr.Textbox()
|
40 |
+
btn=gr.Button('Send')
|
41 |
+
|
42 |
+
clear = gr.ClearButton([msg, chatbot])
|
43 |
+
btn.click(user, [msg, chatbot], [msg, chatbot],queue=False).then(respond,chatbot,chatbot)
|
44 |
+
clear.click(lambda:None,None,chatbot,queue=False)
|
45 |
+
|
46 |
+
if __name__=='__main__':
|
47 |
+
demo.launch(server_name="0.0.0.0", server_port=7860)
|