broadfield-dev commited on
Commit
55b26e3
·
verified ·
1 Parent(s): e6c35a2

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +14 -10
app.py CHANGED
@@ -1,17 +1,21 @@
1
  import gradio as gr
2
- import requests
 
3
 
4
- # URL of the Ollama server running on port 8000
5
- OLLAMA_SERVER_URL = "https://https://broadfield-dev-ollama-server.hf.space/api/predict/"
6
 
7
- def chat_with_ollama(prompt):
8
- # Send a request to the Ollama server
9
- response = requests.post(OLLAMA_SERVER_URL, json={"data": [prompt]})
10
- if response.status_code == 200:
11
- return response.json()["data"][0]
12
- else:
13
- return "Error communicating with the Ollama server."
 
 
 
14
 
 
15
  # Create a Gradio interface
16
  iface = gr.Interface(
17
  fn=chat_with_ollama,
 
1
  import gradio as gr
2
+ import os
3
+ os.system("pip install ollama")
4
 
5
+ from ollama import chat
 
6
 
7
+ stream = chat(
8
+ model='llama3.2',
9
+ messages=[{'role': 'user', 'content': 'Why is the sky blue?'}],
10
+ stream=True,
11
+ )
12
+ output=""
13
+ for chunk in stream:
14
+ print(chunk['message']['content'], end='', flush=True)
15
+ output+=chunk['message']['content']
16
+ yield output
17
 
18
+
19
  # Create a Gradio interface
20
  iface = gr.Interface(
21
  fn=chat_with_ollama,