Update app.py
Browse files
app.py
CHANGED
@@ -1,15 +1,25 @@
|
|
|
|
1 |
import requests
|
2 |
|
3 |
-
|
4 |
-
|
5 |
-
|
6 |
-
|
7 |
-
|
8 |
-
|
9 |
-
|
10 |
-
|
11 |
-
|
12 |
-
|
13 |
-
|
14 |
-
|
15 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
import gradio as gr
|
2 |
import requests
|
3 |
|
4 |
+
# API调用函数
|
5 |
+
def call_api(user_input):
|
6 |
+
url = "https://api-inference.huggingface.co/models/black-forest-labs/FLUX.1-dev" # 替换为你的API URL
|
7 |
+
headers = {"Authorization": "Bearer YOUR_TOKEN"}
|
8 |
+
params = {"query": user_input}
|
9 |
+
|
10 |
+
response = requests.get(url, headers=headers, params=params)
|
11 |
+
if response.status_code == 200:
|
12 |
+
return response.json() # 返回API的响应
|
13 |
+
else:
|
14 |
+
return f"Error: {response.status_code}"
|
15 |
+
|
16 |
+
# 使用Gradio界面
|
17 |
+
iface = gr.Interface(
|
18 |
+
fn=call_api,
|
19 |
+
inputs="text",
|
20 |
+
outputs="json",
|
21 |
+
title="API 调用",
|
22 |
+
description="输入文本并从API获取结果"
|
23 |
+
)
|
24 |
+
|
25 |
+
iface.launch()
|