Update app.py
Browse files
app.py
CHANGED
@@ -1,30 +1,26 @@
|
|
1 |
import gradio as gr
|
2 |
import requests
|
3 |
|
4 |
-
#
|
5 |
-
OLLAMA_API_URL = "http://127.0.0.1:7860" # 这是内部 API 地址,仅作示例
|
6 |
-
|
7 |
-
# 定义请求 Ollama API 的函数
|
8 |
def get_ollama_response(query):
|
9 |
try:
|
10 |
-
#
|
11 |
-
response = requests.post(
|
12 |
if response.status_code != 200:
|
13 |
return f"Error: Server returned status code {response.status_code}"
|
14 |
|
15 |
-
# 解析 JSON 响应
|
16 |
response_data = response.json()
|
17 |
return response_data.get("answer", "No answer found in response.")
|
18 |
except Exception as e:
|
19 |
return f"Error: {str(e)}"
|
20 |
|
21 |
-
#
|
22 |
iface = gr.Interface(
|
23 |
-
fn=get_ollama_response, #
|
24 |
-
inputs="text",
|
25 |
-
outputs="text",
|
26 |
-
title="
|
27 |
)
|
28 |
|
29 |
-
# 启动 Gradio
|
30 |
-
iface.launch(server_name="0.0.0.0", server_port=7860)
|
|
|
1 |
import gradio as gr
|
2 |
import requests
|
3 |
|
4 |
+
# 定义内部逻辑函数
|
|
|
|
|
|
|
5 |
def get_ollama_response(query):
|
6 |
try:
|
7 |
+
# 模拟 API 请求(替换为实际逻辑)
|
8 |
+
response = requests.post("http://127.0.0.1:7860/api/query", json={"query": query})
|
9 |
if response.status_code != 200:
|
10 |
return f"Error: Server returned status code {response.status_code}"
|
11 |
|
|
|
12 |
response_data = response.json()
|
13 |
return response_data.get("answer", "No answer found in response.")
|
14 |
except Exception as e:
|
15 |
return f"Error: {str(e)}"
|
16 |
|
17 |
+
# 创建 Gradio 界面
|
18 |
iface = gr.Interface(
|
19 |
+
fn=get_ollama_response, # 输入输出处理函数
|
20 |
+
inputs="text", # 输入为文本
|
21 |
+
outputs="text", # 输出为文本
|
22 |
+
title="Hugging Face Gradio App",
|
23 |
)
|
24 |
|
25 |
+
# 启动 Gradio 应用
|
26 |
+
iface.launch(server_name="0.0.0.0", server_port=7860, share=True)
|