Create app.py
Browse files
app.py
ADDED
|
@@ -0,0 +1,17 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import gradio as gr
|
| 2 |
+
import requests
|
| 3 |
+
|
| 4 |
+
# 设置 Ollama API 地址
|
| 5 |
+
OLLAMA_API_URL = "http://localhost:8000" # 这个是你本地 Ollama 服务的 URL
|
| 6 |
+
|
| 7 |
+
# 定义请求 Ollama API 的函数
|
| 8 |
+
def get_ollama_response(query):
|
| 9 |
+
# 发送请求到 Ollama API
|
| 10 |
+
response = requests.post(OLLAMA_API_URL, json={"query": query})
|
| 11 |
+
return response.json()["answer"] # 假设返回的 JSON 格式包含 "answer"
|
| 12 |
+
|
| 13 |
+
# 使用 Gradio 创建界面
|
| 14 |
+
iface = gr.Interface(fn=get_ollama_response, inputs="text", outputs="text")
|
| 15 |
+
|
| 16 |
+
# 启动 Gradio 应用
|
| 17 |
+
iface.launch()
|