Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
|
@@ -3,7 +3,8 @@ import requests
|
|
| 3 |
|
| 4 |
# --- 配置資訊 ---
|
| 5 |
API_KEY = "d72ef10876b9403a9479c6e31f27a4be".strip()
|
| 6 |
-
UPLOAD_URL = "https://www.runninghub.cn/
|
|
|
|
| 7 |
|
| 8 |
# --- 核心函式 ---
|
| 9 |
def test_upload_image(image_path):
|
|
@@ -13,14 +14,18 @@ def test_upload_image(image_path):
|
|
| 13 |
try:
|
| 14 |
with open(image_path, "rb") as f:
|
| 15 |
files = {"file": f}
|
| 16 |
-
data = {
|
| 17 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
| 18 |
response.raise_for_status()
|
| 19 |
result = response.json()
|
| 20 |
print(result) # 除錯用
|
| 21 |
|
| 22 |
if result.get("code") == 0:
|
| 23 |
-
return f"
|
| 24 |
else:
|
| 25 |
return f"上傳失敗!訊息: {result.get('msg')}"
|
| 26 |
|
|
@@ -31,11 +36,11 @@ def test_upload_image(image_path):
|
|
| 31 |
with gr.Blocks() as demo:
|
| 32 |
gr.Markdown("# RunningHub 上傳測試")
|
| 33 |
gr.Markdown("上傳一張圖片,測試 API Key 是否有效。")
|
| 34 |
-
|
| 35 |
image_input = gr.Image(type="filepath", label="上傳圖片")
|
| 36 |
status_output = gr.Textbox(label="狀態", interactive=False)
|
| 37 |
upload_button = gr.Button("測試上傳")
|
| 38 |
-
|
| 39 |
upload_button.click(fn=test_upload_image, inputs=image_input, outputs=status_output)
|
| 40 |
|
| 41 |
if __name__ == "__main__":
|
|
|
|
| 3 |
|
| 4 |
# --- 配置資訊 ---
|
| 5 |
API_KEY = "d72ef10876b9403a9479c6e31f27a4be".strip()
|
| 6 |
+
UPLOAD_URL = "https://www.runninghub.cn/task/openapi/upload"
|
| 7 |
+
HEADERS = {"Host": "www.runninghub.cn"}
|
| 8 |
|
| 9 |
# --- 核心函式 ---
|
| 10 |
def test_upload_image(image_path):
|
|
|
|
| 14 |
try:
|
| 15 |
with open(image_path, "rb") as f:
|
| 16 |
files = {"file": f}
|
| 17 |
+
data = {
|
| 18 |
+
"apiKey": API_KEY,
|
| 19 |
+
"fileType": "image" # 圖片固定為 image
|
| 20 |
+
}
|
| 21 |
+
|
| 22 |
+
response = requests.post(UPLOAD_URL, headers=HEADERS, data=data, files=files)
|
| 23 |
response.raise_for_status()
|
| 24 |
result = response.json()
|
| 25 |
print(result) # 除錯用
|
| 26 |
|
| 27 |
if result.get("code") == 0:
|
| 28 |
+
return f"上傳成功!fileName: {result['data']['fileName']}"
|
| 29 |
else:
|
| 30 |
return f"上傳失敗!訊息: {result.get('msg')}"
|
| 31 |
|
|
|
|
| 36 |
with gr.Blocks() as demo:
|
| 37 |
gr.Markdown("# RunningHub 上傳測試")
|
| 38 |
gr.Markdown("上傳一張圖片,測試 API Key 是否有效。")
|
| 39 |
+
|
| 40 |
image_input = gr.Image(type="filepath", label="上傳圖片")
|
| 41 |
status_output = gr.Textbox(label="狀態", interactive=False)
|
| 42 |
upload_button = gr.Button("測試上傳")
|
| 43 |
+
|
| 44 |
upload_button.click(fn=test_upload_image, inputs=image_input, outputs=status_output)
|
| 45 |
|
| 46 |
if __name__ == "__main__":
|