Spaces:
Sleeping
Sleeping
Sunghyun Jun
commited on
Commit
ยท
f6c62cd
1
Parent(s):
136f787
Add application file
Browse files
app.py
ADDED
|
@@ -0,0 +1,55 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import gradio as gr
|
| 2 |
+
import requests
|
| 3 |
+
import os # ํ๊ฒฝ ๋ณ์ ์ฌ์ฉ์ ์ํด ํ์
|
| 4 |
+
|
| 5 |
+
# Secrets์์ Private Space URL๊ณผ Access Token ์ฝ๊ธฐ
|
| 6 |
+
PRIVATE_SPACE_URL = os.getenv("PRIVATE_SPACE_URL")
|
| 7 |
+
HF_TOKEN = os.getenv("HF_TOKEN")
|
| 8 |
+
|
| 9 |
+
def fetch_actor_data():
|
| 10 |
+
if not PRIVATE_SPACE_URL:
|
| 11 |
+
return "Error: Private Space URL not found. Please check the Secrets configuration."
|
| 12 |
+
if not HF_TOKEN:
|
| 13 |
+
return "Error: Access token not found. Please check the Secrets configuration."
|
| 14 |
+
|
| 15 |
+
headers = {
|
| 16 |
+
"Authorization": f"Bearer {HF_TOKEN}"
|
| 17 |
+
}
|
| 18 |
+
|
| 19 |
+
try:
|
| 20 |
+
# Private Space์ /api/actor ์๋ํฌ์ธํธ๋ก ์์ฒญ
|
| 21 |
+
url = f"{PRIVATE_SPACE_URL}/api/actor"
|
| 22 |
+
response = requests.get(url, headers=headers)
|
| 23 |
+
|
| 24 |
+
if response.status_code == 200:
|
| 25 |
+
# ์ฑ๊ณต์ ์ผ๋ก ๋ฐ์ดํฐ๋ฅผ ๊ฐ์ ธ์จ ๊ฒฝ์ฐ
|
| 26 |
+
data = response.json()
|
| 27 |
+
|
| 28 |
+
# actor_id ์ถ์ถ
|
| 29 |
+
actor_ids = []
|
| 30 |
+
|
| 31 |
+
# JSON ๊ตฌ์กฐ๋ฅผ ์ํํ๋ฉฐ actor_id ์์ง
|
| 32 |
+
if "results" in data:
|
| 33 |
+
for item in data["results"]:
|
| 34 |
+
if "actor_id" in item:
|
| 35 |
+
actor_ids.append(item["actor_id"])
|
| 36 |
+
|
| 37 |
+
return f"Actor ID: {actor_ids}"
|
| 38 |
+
else:
|
| 39 |
+
# ์คํจํ ๊ฒฝ์ฐ ์ํ ์ฝ๋์ ์๋ฌ ๋ฉ์์ง ๋ฐํ
|
| 40 |
+
return f"Error {response.status_code}: {response.text}"
|
| 41 |
+
except Exception as e:
|
| 42 |
+
return f"Request failed: {str(e)}"
|
| 43 |
+
|
| 44 |
+
# Gradio ์ธํฐํ์ด์ค ์ ์
|
| 45 |
+
iface = gr.Interface(
|
| 46 |
+
fn=fetch_actor_data,
|
| 47 |
+
inputs=None, # ์
๋ ฅ๊ฐ ํ์ ์์
|
| 48 |
+
outputs="text", # ํ
์คํธ ๊ฒฐ๊ณผ ์ถ๋ ฅ
|
| 49 |
+
title="Fetch Actor Data",
|
| 50 |
+
description="Fetches actor data from the private Hugging Face Space using the /api/actor endpoint."
|
| 51 |
+
)
|
| 52 |
+
|
| 53 |
+
# ์ฑ ์คํ
|
| 54 |
+
if __name__ == "__main__":
|
| 55 |
+
iface.launch()
|