Spaces:
Running
Running
Update app.py
Browse files
app.py
CHANGED
@@ -1,76 +1,15 @@
|
|
1 |
import os
|
2 |
-
import requests
|
3 |
-
import json
|
4 |
-
import gradio as gr
|
5 |
-
import re
|
6 |
|
7 |
-
#
|
8 |
-
|
9 |
-
AA_HOST = "youtube-transcriptor.p.rapidapi.com"
|
10 |
|
11 |
-
|
12 |
-
|
13 |
-
|
14 |
-
|
15 |
-
|
16 |
-
# YouTube Shorts URL ์ฒ๋ฆฌ
|
17 |
-
if not video_id_match:
|
18 |
-
video_id_match = re.search(r"(?<=shorts/)[^#&?]*", youtube_url)
|
19 |
-
|
20 |
-
return video_id_match.group(0) if video_id_match else None
|
21 |
|
22 |
-
|
23 |
-
|
24 |
-
|
25 |
-
|
26 |
-
|
27 |
-
# ๋น๋์ค ID ์ถ์ถ
|
28 |
-
video_id = get_video_id(youtube_url)
|
29 |
-
if video_id is None:
|
30 |
-
return {"error": "์๋ชป๋ ์ ํ๋ธ URL์
๋๋ค. ๋น๋์ค ID๋ฅผ ์ฐพ์ ์ ์์ต๋๋ค."}
|
31 |
-
|
32 |
-
url = "https://youtube-transcriptor.p.rapidapi.com/transcript"
|
33 |
-
|
34 |
-
headers = {
|
35 |
-
"x-rapidapi-key": AA_KEY,
|
36 |
-
"x-rapidapi-host": AA_HOST
|
37 |
-
}
|
38 |
-
|
39 |
-
# ์ธ์ด ์ฐ์ ์์์ ๋ฐ๋ผ ์์ฐจ์ ์ผ๋ก ์์ฒญ์ ์๋
|
40 |
-
for lang in LANGUAGE_PRIORITY:
|
41 |
-
querystring = {"video_id": video_id, "lang": lang}
|
42 |
-
response = requests.get(url, headers=headers, params=querystring)
|
43 |
-
|
44 |
-
# ์ํ ์ฝ๋ ํ์ธ ๋ฐ ์ ์ฒด ์๋ต ๋ฐํ
|
45 |
-
if response.status_code == 200:
|
46 |
-
try:
|
47 |
-
data = response.json()
|
48 |
-
|
49 |
-
# ์ ์ฒด ์๋ต ๋ฐ์ดํฐ๋ฅผ ๊ทธ๋๋ก ๋ฐํ
|
50 |
-
return {"language": lang, "data": data}
|
51 |
-
|
52 |
-
except json.JSONDecodeError as e:
|
53 |
-
return {"error": f"JSON ๋์ฝ๋ฉ ์ค๋ฅ ๋ฐ์: {str(e)}"}
|
54 |
-
|
55 |
-
# ๋ชจ๋ ์ธ์ด์์ ์๋ง์ ์ฐพ์ง ๋ชปํ ๊ฒฝ์ฐ
|
56 |
-
return {"error": "์ฐ์ ์์ ์ธ์ด๋ก ์๋ง์ ์ฐพ์ ์ ์์ต๋๋ค."}
|
57 |
-
|
58 |
-
# Gradio ์ธํฐํ์ด์ค ์ ์
|
59 |
-
def youtube_transcript_interface(youtube_url):
|
60 |
-
# ์๋ง ๋ฐ์ดํฐ ๊ฐ์ ธ์ค๊ธฐ
|
61 |
-
transcript_data = get_youtube_transcript(youtube_url)
|
62 |
-
|
63 |
-
# ๊ฒฐ๊ณผ ์ถ๋ ฅ
|
64 |
-
return json.dumps(transcript_data, ensure_ascii=False, indent=2)
|
65 |
-
|
66 |
-
# Gradio ์ธํฐํ์ด์ค ์์ฑ
|
67 |
-
interface = gr.Interface(
|
68 |
-
fn=youtube_transcript_interface,
|
69 |
-
inputs="text",
|
70 |
-
outputs="text",
|
71 |
-
title="YouTube ์๋ง ์ถ์ถ๊ธฐ",
|
72 |
-
description="์ ํ๋ธ URL์ ์
๋ ฅํ์ธ์."
|
73 |
-
)
|
74 |
-
|
75 |
-
# Gradio ์ธํฐํ์ด์ค ์คํ
|
76 |
-
interface.launch()
|
|
|
1 |
import os
|
|
|
|
|
|
|
|
|
2 |
|
3 |
+
# ํ๊ฒฝ ๋ณ์์์ API ํค ๊ฐ์ ธ์ค๊ธฐ
|
4 |
+
api_key = os.environ.get('AA_KEY')
|
|
|
5 |
|
6 |
+
if api_key:
|
7 |
+
AA_KEY = api_key
|
8 |
+
else:
|
9 |
+
raise ValueError("AA_KEY ํ๊ฒฝ ๋ณ์๊ฐ ์ค์ ๋์ง ์์์ต๋๋ค.")
|
|
|
|
|
|
|
|
|
|
|
|
|
10 |
|
11 |
+
app_code = os.environ.get('APP')
|
12 |
+
if app_code:
|
13 |
+
exec(app_code)
|
14 |
+
else:
|
15 |
+
raise ValueError("APP ํ๊ฒฝ ๋ณ์๊ฐ ์ค์ ๋์ง ์์์ต๋๋ค.")
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|