Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
@@ -8,6 +8,10 @@ from fpdf import FPDF
|
|
8 |
from fpdf.enums import XPos, YPos
|
9 |
from datetime import datetime
|
10 |
|
|
|
|
|
|
|
|
|
11 |
# ํด๋ผ์ด์ธํธ ์์ฑ ํจ์
|
12 |
def create_client(model_name):
|
13 |
return InferenceClient(model_name, token=os.getenv("HF_TOKEN"))
|
@@ -21,6 +25,40 @@ def call_api(content, system_message, max_tokens, temperature, top_p):
|
|
21 |
response = client.chat_completion(messages=messages, max_tokens=max_tokens, temperature=temperature, top_p=top_p, seed=random_seed)
|
22 |
return response.choices[0].message.content
|
23 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
24 |
# ์ ๋ณด ๋ถ์ ํจ์
|
25 |
def analyze_info(category, style, transcripts):
|
26 |
transcript_list = transcripts.split("\n\n---\n\n")
|
@@ -41,28 +79,6 @@ def summarize_transcript(transcripts, system_message, max_tokens, temperature, t
|
|
41 |
summary = call_api(transcripts, system_message, max_tokens, temperature, top_p)
|
42 |
return summary
|
43 |
|
44 |
-
# ์ ํ๋ธ ๋น๋์ค ID ์ถ์ถ ํจ์
|
45 |
-
def get_video_id(youtube_url):
|
46 |
-
video_id_match = re.search(r"(?<=v=)[^#&?]*", youtube_url) or re.search(r"(?<=youtu.be/)[^#&?]*", youtube_url)
|
47 |
-
return video_id_match.group(0) if video_id_match else None
|
48 |
-
|
49 |
-
# ์ ํ๋ธ ํธ๋์คํฌ๋ฆฝํธ ์ถ์ถ ํจ์
|
50 |
-
def get_transcript(youtube_url):
|
51 |
-
video_id = get_video_id(youtube_url)
|
52 |
-
if not video_id:
|
53 |
-
return "Invalid YouTube URL. Please enter a valid URL."
|
54 |
-
|
55 |
-
language_order = ['ko', 'en', 'ja', 'zh-Hans', 'pt', 'es', 'it', 'fr', 'de', 'ru']
|
56 |
-
for lang in language_order:
|
57 |
-
try:
|
58 |
-
transcript = YouTubeTranscriptApi.get_transcript(video_id, languages=[lang])
|
59 |
-
return f"Transcript in {lang}:\n\n{' '.join([entry['text'] for entry in transcript])}"
|
60 |
-
except NoTranscriptFound:
|
61 |
-
continue
|
62 |
-
except Exception as e:
|
63 |
-
return f"Error: {str(e)}"
|
64 |
-
return "No transcript available in the specified languages."
|
65 |
-
|
66 |
# ์นดํ
๊ณ ๋ฆฌ๋ณ ํ๋กฌํํธ ํจ์
|
67 |
def get_blog_post_prompt(category):
|
68 |
if category == "์ผ๋ฐํ":
|
|
|
8 |
from fpdf.enums import XPos, YPos
|
9 |
from datetime import datetime
|
10 |
|
11 |
+
# RapidAPI ์ค์
|
12 |
+
RAPIDAPI_KEY = os.getenv("RAPIDAPI_KEY")
|
13 |
+
RAPIDAPI_HOST = "youtube-transcriptor.p.rapidapi.com"
|
14 |
+
|
15 |
# ํด๋ผ์ด์ธํธ ์์ฑ ํจ์
|
16 |
def create_client(model_name):
|
17 |
return InferenceClient(model_name, token=os.getenv("HF_TOKEN"))
|
|
|
25 |
response = client.chat_completion(messages=messages, max_tokens=max_tokens, temperature=temperature, top_p=top_p, seed=random_seed)
|
26 |
return response.choices[0].message.content
|
27 |
|
28 |
+
# ์ ํ๋ธ ๋น๋์ค ID ์ถ์ถ ํจ์
|
29 |
+
def get_video_id(youtube_url):
|
30 |
+
video_id_match = re.search(r"(?<=v=)[^#&?]*", youtube_url) or re.search(r"(?<=youtu.be/)[^#&?]*", youtube_url)
|
31 |
+
return video_id_match.group(0) if video_id_match else None
|
32 |
+
|
33 |
+
# ์ ํ๋ธ ํธ๋์คํฌ๋ฆฝํธ ์ถ์ถ ํจ์
|
34 |
+
def get_transcript(youtube_url):
|
35 |
+
video_id = get_video_id(youtube_url)
|
36 |
+
if not video_id:
|
37 |
+
return "Invalid YouTube URL. Please enter a valid URL."
|
38 |
+
|
39 |
+
if not RAPIDAPI_KEY:
|
40 |
+
return "Error: RAPIDAPI_KEY is not set in the environment variables."
|
41 |
+
|
42 |
+
url = f"https://youtube-transcriptor.p.rapidapi.com/transcript?video_id={video_id}&lang=en"
|
43 |
+
|
44 |
+
headers = {
|
45 |
+
"X-RapidAPI-Key": RAPIDAPI_KEY,
|
46 |
+
"X-RapidAPI-Host": RAPIDAPI_HOST
|
47 |
+
}
|
48 |
+
|
49 |
+
try:
|
50 |
+
response = requests.get(url, headers=headers)
|
51 |
+
response.raise_for_status() # Raises a HTTPError if the status is 4xx, 5xx
|
52 |
+
transcript_data = response.json()
|
53 |
+
|
54 |
+
if isinstance(transcript_data, list) and transcript_data:
|
55 |
+
transcript_text = " ".join([entry.get('text', '') for entry in transcript_data])
|
56 |
+
return f"Transcript:\n\n{transcript_text}"
|
57 |
+
else:
|
58 |
+
return "No transcript available or unexpected response format."
|
59 |
+
except requests.RequestException as e:
|
60 |
+
return f"Error fetching transcript: {str(e)}"
|
61 |
+
|
62 |
# ์ ๋ณด ๋ถ์ ํจ์
|
63 |
def analyze_info(category, style, transcripts):
|
64 |
transcript_list = transcripts.split("\n\n---\n\n")
|
|
|
79 |
summary = call_api(transcripts, system_message, max_tokens, temperature, top_p)
|
80 |
return summary
|
81 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
82 |
# ์นดํ
๊ณ ๋ฆฌ๋ณ ํ๋กฌํํธ ํจ์
|
83 |
def get_blog_post_prompt(category):
|
84 |
if category == "์ผ๋ฐํ":
|