Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
@@ -1,10 +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":
|
7 |
-
} # 替換為你的 Hugging Face API token
|
8 |
|
9 |
def query(payload):
|
10 |
response = requests.post(API_URL, headers=headers, json=payload)
|
@@ -13,23 +12,24 @@ def query(payload):
|
|
13 |
return response.json()
|
14 |
|
15 |
def inference(text):
|
16 |
-
#
|
17 |
output = query({"inputs": text})
|
18 |
|
19 |
-
#
|
20 |
if isinstance(output, dict) and "error" in output:
|
21 |
return f"Error: {output['error']}"
|
22 |
|
23 |
-
#
|
24 |
-
return output #
|
25 |
|
26 |
# 創建 Gradio 介面
|
27 |
interface = gr.Interface(
|
28 |
fn=inference,
|
29 |
inputs=gr.Textbox(lines=2, placeholder="輸入生成藝術的描述..."),
|
30 |
-
outputs="text", #
|
31 |
title="最棒第一組的 Ukiyo-e Art 模型",
|
32 |
description="這是一個呼叫 Hugging Face 上 Ukiyo-e Art 模型的應用"
|
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_actual_token_here"} # 在這裡放入你的 Hugging Face 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()
|