tsengiii commited on
Commit
60edab6
·
verified ·
1 Parent(s): aad652f

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +12 -12
app.py CHANGED
@@ -1,9 +1,9 @@
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,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
- # 創建 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()
 
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()