Spaces:
Sleeping
Sleeping
File size: 2,488 Bytes
f6c62cd ef15d8b f6c62cd ef15d8b f6c62cd ef15d8b f6c62cd ef15d8b f6c62cd ef15d8b f6c62cd ef15d8b f6c62cd ef15d8b f6c62cd ef15d8b f6c62cd ef15d8b f6c62cd ef15d8b f6c62cd ef15d8b f6c62cd ef15d8b f6c62cd |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 |
import gradio as gr
import requests
import os
import json
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. Check Secrets."
if not HF_TOKEN:
return "Error: HF_TOKEN not found. Check Secrets."
headers = {
"Authorization": f"Bearer {HF_TOKEN}"
}
try:
response = requests.get(f"{PRIVATE_SPACE_URL}/api/actor", headers=headers)
if response.status_code == 200:
# 응답 JSON 파싱
data = response.json()
# 기대 구조: data["data"]["result"] => list of actor items
actor_ids = []
if (
"data" in data
and isinstance(data["data"], dict)
and "result" in data["data"]
and isinstance(data["data"]["result"], list)
):
for item in data["data"]["result"]:
if "actor_id" in item:
actor_ids.append(item["actor_id"])
if len(actor_ids) >= 10:
break
if actor_ids:
return f"Found actor_ids: {actor_ids}"
else:
# actor_id가 없을 경우 구조 파악용 반환
top_level_keys = list(data["data"].keys()) if "data" in data and isinstance(data["data"], dict) else []
first_item = data["data"]["result"][0] if "data" in data and "result" in data["data"] and len(data["data"]["result"]) > 0 else {}
return (
"No actor_id found.\n\n"
f"Keys in data['data']: {top_level_keys}\n\n"
"First item in data['data']['result']:\n" +
json.dumps(first_item, indent=2, ensure_ascii=False)
)
else:
return f"Error {response.status_code}\nResponse Text:\n{response.text}"
except Exception as e:
return f"Request failed: {str(e)}"
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.\n"
"Assumes structure: {status_code:..., data:{count:..., result:[{actor_id:...}]}}\n"
"If no actor_id found, shows partial keys for debugging."
)
)
if __name__ == "__main__":
iface.launch()
|