Gordonkl commited on
Commit
2952395
·
verified ·
1 Parent(s): 203836b

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +23 -13
app.py CHANGED
@@ -1,15 +1,25 @@
 
1
  import requests
2
 
3
- API_URL = "https://api-inference.huggingface.co/models/KappaNeuro/ukiyo-e-art"
4
- headers = {"Authorization": "Bearer hf_xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx"}
5
-
6
- def query(payload):
7
- response = requests.post(API_URL, headers=headers, json=payload)
8
- return response.content
9
- image_bytes = query({
10
- "inputs": "Astronaut riding a horse",
11
- })
12
- # You can access the image with PIL.Image for example
13
- import io
14
- from PIL import Image
15
- image = Image.open(io.BytesIO(image_bytes))
 
 
 
 
 
 
 
 
 
 
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()