alibidaran commited on
Commit
00a08a3
·
verified ·
1 Parent(s): df7397a

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +47 -30
app.py CHANGED
@@ -1,30 +1,47 @@
1
- import gradio as gr
2
- import requests
3
-
4
- # Function to interact with the Ollama backend
5
- def chat_with_ollama(message):
6
- try:
7
- # Ollama server running on localhost:11434
8
- ollama_endpoint = "http://localhost:11434/api/generate"
9
- payload = {"message": message}
10
-
11
- response = requests.post(ollama_endpoint, json=payload)
12
- response_data = response.json()
13
-
14
- if response.status_code == 200:
15
- return response_data.get("response", "No response from Ollama.")
16
- else:
17
- return f"Error: {response_data.get('error', 'Unknown error')}"
18
- except Exception as e:
19
- return f"An error occurred: {str(e)}"
20
-
21
- # Gradio interface
22
- iface = gr.Interface(
23
- fn=chat_with_ollama,
24
- inputs=gr.Textbox(lines=2, placeholder="Type your message..."),
25
- outputs="text",
26
- title="Gradio Chatbot with Ollama Backend"
27
- )
28
-
29
- if __name__ == "__main__":
30
- iface.launch(server_name="0.0.0.0", server_port=7860)
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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)