Spaces:
Build error
Build error
Create app.py
Browse files
app.py
ADDED
|
@@ -0,0 +1,41 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import requests
|
| 2 |
+
import json
|
| 3 |
+
import gradio as gr
|
| 4 |
+
|
| 5 |
+
|
| 6 |
+
url = "http://localhost:11434/api/generate"
|
| 7 |
+
|
| 8 |
+
headers = {
|
| 9 |
+
"Content-Type":"application/json",
|
| 10 |
+
}
|
| 11 |
+
|
| 12 |
+
|
| 13 |
+
history=[]
|
| 14 |
+
|
| 15 |
+
def generate_response(prompt):
|
| 16 |
+
# history.append(prompt)
|
| 17 |
+
# final_prompt="\n".join(history)
|
| 18 |
+
|
| 19 |
+
data = {
|
| 20 |
+
"model":"gtm-serve",
|
| 21 |
+
"prompt": prompt, # final_prompt,
|
| 22 |
+
"stream": False
|
| 23 |
+
}
|
| 24 |
+
|
| 25 |
+
response = requests.post(url,headers=headers,data=json.dumps(data))
|
| 26 |
+
|
| 27 |
+
if response.status_code==200:
|
| 28 |
+
response=response.text
|
| 29 |
+
data = json.loads(response)
|
| 30 |
+
actual_response = data['response']
|
| 31 |
+
return actual_response
|
| 32 |
+
else:
|
| 33 |
+
print("Error:",response.text)
|
| 34 |
+
|
| 35 |
+
interface = gr.Interface(
|
| 36 |
+
fn=generate_response,
|
| 37 |
+
inputs=gr.Textbox(lines=2,placeholder="Please enter your prompt"),
|
| 38 |
+
outputs="text",
|
| 39 |
+
# live=True
|
| 40 |
+
)
|
| 41 |
+
interface.launch(share=True)
|