tsengiii commited on
Commit
9c7f230
·
verified ·
1 Parent(s): d045353

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +13 -16
app.py CHANGED
@@ -1,19 +1,16 @@
1
- import requests
2
- import os
3
 
4
- # 設置測試模型的 API URL
5
- API_URL = "https://api-inference.huggingface.co/models/gpt2"
6
- HF_API_TOKEN = os.getenv("HF_API_TOKEN") # 從環境變數讀取 API token
7
- headers = {"Authorization": f"Bearer {HF_API_TOKEN}"}
8
 
9
- def query(payload):
10
- response = requests.post(API_URL, headers=headers, json=payload)
11
- if response.status_code != 200:
12
- return f"Error: {response.status_code}, {response.text}"
13
- return response.json()
 
 
 
14
 
15
- # 測試簡單的文本生成
16
- output = query({"inputs": "Hello, world!"})
17
-
18
- # 打印結果
19
- print(output)
 
1
+ import gradio as gr
 
2
 
3
+ def greet(name):
4
+ return f"Hello {name}!"
 
 
5
 
6
+ # 創建 Gradio 介面
7
+ interface = gr.Interface(
8
+ fn=greet,
9
+ inputs="text",
10
+ outputs="text",
11
+ title="簡單應用測試",
12
+ description="輸入一個名稱,返回問候語"
13
+ )
14
 
15
+ # 啟動 Gradio 應用
16
+ interface.launch()