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