Spaces:
Runtime error
Runtime error
broadfield-dev
commited on
Update app.py
Browse files
app.py
CHANGED
@@ -1,17 +1,21 @@
|
|
1 |
import gradio as gr
|
2 |
-
import
|
|
|
3 |
|
4 |
-
|
5 |
-
OLLAMA_SERVER_URL = "https://https://broadfield-dev-ollama-server.hf.space/api/predict/"
|
6 |
|
7 |
-
|
8 |
-
|
9 |
-
|
10 |
-
|
11 |
-
|
12 |
-
|
13 |
-
|
|
|
|
|
|
|
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,
|