-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmain.py
More file actions
45 lines (34 loc) · 997 Bytes
/
main.py
File metadata and controls
45 lines (34 loc) · 997 Bytes
1
2
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
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
import json
import gradio as gr
import requests
from requests import HTTPError
url = "http://0.0.0.0:8080/api/generate"
headers = {
'Content-Type': 'application/json'
}
history = []
def make_a_post_request_to_ollama_serve(prompt):
history.append(prompt)
final_prompt = "\n".join(history)
data = {
"model": "example",
"prompt": final_prompt,
"stream": False
}
try:
response = requests.post(url, headers=headers, data=json.dumps(data))
if response.status_code == 200:
response = response.text
data = json.loads(response)
actual_response = data['response']
return actual_response
else:
raise HTTPError(f'Error: \n {response.text}')
except HTTPError as h:
print(h)
interface = gr.Interface(
fn=make_a_post_request_to_ollama_serve,
inputs=gr.Textbox(lines=4, placeholder="Enter your Python Query"),
outputs="text"
)
interface.launch()