-
Notifications
You must be signed in to change notification settings - Fork 1.4k
/
main.py
42 lines (32 loc) · 977 Bytes
/
main.py
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
import requests
import json
import gradio as gr
url = "http://localhost:11434/api/generate"
headers = {
'Content-Type': 'application/json',
}
conversation_history = []
def generate_response(prompt):
conversation_history.append(prompt)
full_prompt = "\n".join(conversation_history)
data = {
"model": "mistral",
"stream": False,
"prompt": full_prompt,
}
response = requests.post(url, headers=headers, data=json.dumps(data))
if response.status_code == 200:
response_text = response.text
data = json.loads(response_text)
actual_response = data["response"]
conversation_history.append(actual_response)
return actual_response
else:
print("Error:", response.status_code, response.text)
return None
iface = gr.Interface(
fn=generate_response,
inputs=gr.inputs.Textbox(lines=2, placeholder="Enter your prompt here..."),
outputs="text"
)
iface.launch()