tsengiii commited on
Commit
746152a
·
verified ·
1 Parent(s): 955ca3a

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +17 -9
app.py CHANGED
@@ -1,26 +1,34 @@
1
  import gradio as gr
2
  import requests
3
 
4
- # 模型 API 端點 (替換成你選擇的模型 URL)
5
- API_URL = "https://huggingface.co/KappaNeuro/ukiyo-e-art"
6
- headers = {"Authorization": "Bearer YOUR_HUGGINGFACE_API_TOKEN"} # 你需要你的 Hugging Face API token
7
 
8
  def query(payload):
9
  response = requests.post(API_URL, headers=headers, json=payload)
 
 
10
  return response.json()
11
 
12
  def inference(text):
 
13
  output = query({"inputs": text})
14
- return output
 
 
 
 
 
 
15
 
16
  # 創建 Gradio 介面
17
  interface = gr.Interface(
18
  fn=inference,
19
- inputs=gr.Textbox(lines=2, placeholder="輸入文字..."),
20
- outputs="text",
21
- title="最棒第一組模型呼叫",
22
- description="這是一個簡單的應用,用於呼叫 Hugging Face 模型"
23
  )
24
 
25
  interface.launch()
26
-
 
1
  import gradio as gr
2
  import requests
3
 
4
+ # 替換為你選擇的模型 API URL
5
+ API_URL = "https://api-inference.huggingface.co/models/KappaNeuro/ukiyo-e-art"
6
+ headers = {"Authorization": "Bearer YOUR_HUGGINGFACE_API_TOKEN"} # 替換為你的 Hugging Face API token
7
 
8
  def query(payload):
9
  response = requests.post(API_URL, headers=headers, json=payload)
10
+ if response.status_code != 200:
11
+ return f"Error: {response.status_code}, {response.text}"
12
  return response.json()
13
 
14
  def inference(text):
15
+ # 確認 API 回應的格式
16
  output = query({"inputs": text})
17
+
18
+ # 檢查回應是否為 JSON 格式,並避免發生錯誤
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", # 可調整為正確的輸出類型,依據模型回傳的格式
30
+ title="最棒第一組的 Ukiyo-e Art 模型",
31
+ description="這是一個呼叫 Hugging Face 上 Ukiyo-e Art 模型的應用"
32
  )
33
 
34
  interface.launch()