Sunghyun Jun commited on
Commit
f6c62cd
ยท
1 Parent(s): 136f787

Add application file

Browse files
Files changed (1) hide show
  1. app.py +55 -0
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()