Create app.py
Browse files
app.py
ADDED
|
@@ -0,0 +1,31 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import ollama
|
| 2 |
+
import gradio
|
| 3 |
+
import os
|
| 4 |
+
|
| 5 |
+
|
| 6 |
+
def query(q):
|
| 7 |
+
while True:
|
| 8 |
+
client = ollama.Client(host="localhost:11434")
|
| 9 |
+
print(q)
|
| 10 |
+
if not q:
|
| 11 |
+
q="what is a dog?"
|
| 12 |
+
print(q)
|
| 13 |
+
#query = q['q']
|
| 14 |
+
query = q
|
| 15 |
+
out=""
|
| 16 |
+
r = client.chat(
|
| 17 |
+
model='tinyllama',
|
| 18 |
+
messages=[{'role': 'system', 'content': 'You are a Survival Expert'}],
|
| 19 |
+
stream=True,
|
| 20 |
+
)
|
| 21 |
+
for chunk in r:
|
| 22 |
+
chat_back = chunk['message']['content']
|
| 23 |
+
yield chat_back
|
| 24 |
+
|
| 25 |
+
with gr.Blocks() as app:
|
| 26 |
+
with gr.Row():
|
| 27 |
+
inp = gr.Textbox()
|
| 28 |
+
sub = gr.Button()
|
| 29 |
+
outp = gr.Textbox()
|
| 30 |
+
sub.click(query,inp,outp)
|
| 31 |
+
|