tsengiii commited on
Commit
94e9936
·
verified ·
1 Parent(s): 2932f85

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +8 -8
app.py CHANGED
@@ -2,9 +2,9 @@ import gradio as gr
2
  import requests
3
  import os
4
 
5
- # 從環境變數讀取 Hugging Face API token
6
- API_URL = "https://api-inference.huggingface.co/models/KappaNeuro/ukiyo-e-art"
7
- HF_API_TOKEN = os.getenv("HF_API_TOKEN") # 確認您已將此變數在 Hugging Face Spaces 的 Secret 中設定
8
  headers = {"Authorization": f"Bearer {HF_API_TOKEN}"}
9
 
10
  def query(payload):
@@ -22,15 +22,15 @@ def inference(text):
22
  return f"Error: {output['error']}"
23
 
24
  # 返回模型的輸出結果
25
- return output # 根據實際返回的格式處理
26
 
27
  # 創建 Gradio 介面
28
  interface = gr.Interface(
29
  fn=inference,
30
- inputs=gr.Textbox(lines=2, placeholder="輸入生成藝術的描述..."),
31
- outputs="text", # 如果模型輸出的是圖片,可以改為 `outputs="image"`
32
- title="Ukiyo-e Art 模型",
33
- description="這是一個呼叫 Hugging Face Ukiyo-e Art 模型的應用"
34
  )
35
 
36
  # 啟動 Gradio 應用
 
2
  import requests
3
  import os
4
 
5
+ # 使用 GPT-2 模型測試
6
+ API_URL = "https://api-inference.huggingface.co/models/gpt2"
7
+ HF_API_TOKEN = os.getenv("HF_API_TOKEN") # 確保您在 Secrets 中設置了 API token
8
  headers = {"Authorization": f"Bearer {HF_API_TOKEN}"}
9
 
10
  def query(payload):
 
22
  return f"Error: {output['error']}"
23
 
24
  # 返回模型的輸出結果
25
+ return output
26
 
27
  # 創建 Gradio 介面
28
  interface = gr.Interface(
29
  fn=inference,
30
+ inputs=gr.Textbox(lines=2, placeholder="輸入文本..."),
31
+ outputs="text",
32
+ title="GPT-2 模型測試",
33
+ description="測試 Hugging Face API token 與 GPT-2 模型"
34
  )
35
 
36
  # 啟動 Gradio 應用