Spaces:
Sleeping
Sleeping
import gradio as gr | |
import requests | |
import os # ํ๊ฒฝ ๋ณ์ ์ฌ์ฉ์ ์ํด ํ์ | |
# Secrets์์ Private Space URL๊ณผ Access Token ์ฝ๊ธฐ | |
PRIVATE_SPACE_URL = os.getenv("PRIVATE_SPACE_URL") | |
HF_TOKEN = os.getenv("HF_TOKEN") | |
def fetch_actor_data(): | |
if not PRIVATE_SPACE_URL: | |
return "Error: Private Space URL not found. Please check the Secrets configuration." | |
if not HF_TOKEN: | |
return "Error: Access token not found. Please check the Secrets configuration." | |
headers = { | |
"Authorization": f"Bearer {HF_TOKEN}" | |
} | |
try: | |
# Private Space์ /api/actor ์๋ํฌ์ธํธ๋ก ์์ฒญ | |
url = f"{PRIVATE_SPACE_URL}/api/actor" | |
response = requests.get(url, headers=headers) | |
if response.status_code == 200: | |
# ์ฑ๊ณต์ ์ผ๋ก ๋ฐ์ดํฐ๋ฅผ ๊ฐ์ ธ์จ ๊ฒฝ์ฐ | |
data = response.json() | |
# actor_id ์ถ์ถ | |
actor_ids = [] | |
# JSON ๊ตฌ์กฐ๋ฅผ ์ํํ๋ฉฐ actor_id ์์ง | |
if "results" in data: | |
for item in data["results"]: | |
if "actor_id" in item: | |
actor_ids.append(item["actor_id"]) | |
return f"Actor ID: {actor_ids}" | |
else: | |
# ์คํจํ ๊ฒฝ์ฐ ์ํ ์ฝ๋์ ์๋ฌ ๋ฉ์์ง ๋ฐํ | |
return f"Error {response.status_code}: {response.text}" | |
except Exception as e: | |
return f"Request failed: {str(e)}" | |
# Gradio ์ธํฐํ์ด์ค ์ ์ | |
iface = gr.Interface( | |
fn=fetch_actor_data, | |
inputs=None, # ์ ๋ ฅ๊ฐ ํ์ ์์ | |
outputs="text", # ํ ์คํธ ๊ฒฐ๊ณผ ์ถ๋ ฅ | |
title="Fetch Actor Data", | |
description="Fetches actor data from the private Hugging Face Space using the /api/actor endpoint." | |
) | |
# ์ฑ ์คํ | |
if __name__ == "__main__": | |
iface.launch() | |