Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
@@ -1,9 +1,9 @@
|
|
1 |
import gradio as gr
|
2 |
import requests
|
3 |
|
4 |
-
#
|
5 |
API_URL = "https://api-inference.huggingface.co/models/KappaNeuro/ukiyo-e-art"
|
6 |
-
headers = {"Authorization": "Bearer
|
7 |
|
8 |
def query(payload):
|
9 |
response = requests.post(API_URL, headers=headers, json=payload)
|
@@ -12,24 +12,24 @@ def query(payload):
|
|
12 |
return response.json()
|
13 |
|
14 |
def inference(text):
|
15 |
-
#
|
16 |
output = query({"inputs": text})
|
17 |
|
18 |
-
#
|
19 |
if isinstance(output, dict) and "error" in output:
|
20 |
return f"Error: {output['error']}"
|
21 |
|
22 |
-
#
|
23 |
-
return output #
|
24 |
|
25 |
-
#
|
26 |
interface = gr.Interface(
|
27 |
fn=inference,
|
28 |
-
inputs=gr.Textbox(lines=2, placeholder="
|
29 |
-
outputs="text", #
|
30 |
-
title="
|
31 |
-
description="
|
32 |
)
|
33 |
|
34 |
-
#
|
35 |
interface.launch()
|
|
|
1 |
import gradio as gr
|
2 |
import requests
|
3 |
|
4 |
+
# 使用你的 Hugging Face API token
|
5 |
API_URL = "https://api-inference.huggingface.co/models/KappaNeuro/ukiyo-e-art"
|
6 |
+
headers = {"Authorization": "Bearer hf_your_valid_token_here"} # 将 'hf_your_valid_token_here' 替换为实际的 API token
|
7 |
|
8 |
def query(payload):
|
9 |
response = requests.post(API_URL, headers=headers, json=payload)
|
|
|
12 |
return response.json()
|
13 |
|
14 |
def inference(text):
|
15 |
+
# 调用模型并获取结果
|
16 |
output = query({"inputs": text})
|
17 |
|
18 |
+
# 如果返回结果中包含错误信息,显示错误
|
19 |
if isinstance(output, dict) and "error" in output:
|
20 |
return f"Error: {output['error']}"
|
21 |
|
22 |
+
# 返回模型输出结果
|
23 |
+
return output # 根据实际的返回格式处理
|
24 |
|
25 |
+
# 创建 Gradio 界面
|
26 |
interface = gr.Interface(
|
27 |
fn=inference,
|
28 |
+
inputs=gr.Textbox(lines=2, placeholder="输入生成艺术的描述..."),
|
29 |
+
outputs="text", # 如果模型返回的是图片,可以改为 `outputs="image"`
|
30 |
+
title="Ukiyo-e Art 模型",
|
31 |
+
description="这是一个调用 Hugging Face 上 Ukiyo-e Art 模型的应用"
|
32 |
)
|
33 |
|
34 |
+
# 启动 Gradio 应用
|
35 |
interface.launch()
|