Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
@@ -2,9 +2,9 @@ import gradio as gr
|
|
2 |
import requests
|
3 |
import os
|
4 |
|
5 |
-
#
|
6 |
-
API_URL = "https://api-inference.huggingface.co/models/
|
7 |
-
HF_API_TOKEN = os.getenv("HF_API_TOKEN") #
|
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",
|
32 |
-
title="
|
33 |
-
description="
|
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 應用
|