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()