Spaces:
Running
Running
Update app.py
Browse files
app.py
CHANGED
@@ -96,25 +96,26 @@ def process_youtube():
|
|
96 |
return jsonify({"error": "No YouTube URL provided"}), 400
|
97 |
|
98 |
try:
|
99 |
-
|
100 |
-
|
101 |
-
|
102 |
-
|
103 |
-
|
104 |
-
|
105 |
-
|
106 |
-
# Concatenate the text from each segment into a single transcript
|
107 |
-
transcript = " ".join([segment['text'] for segment in transcript_data])
|
108 |
-
|
109 |
-
|
110 |
-
except Exception as e:
|
111 |
-
print(f"Error fetching transcript for video ID {video_id}: {e}")
|
112 |
|
113 |
-
|
114 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
115 |
|
116 |
# Send the transcript to the Gemini API for structured data
|
117 |
structured_data = query_gemini_api(transcript)
|
|
|
118 |
|
119 |
# Return the structured data
|
120 |
return jsonify(structured_data)
|
|
|
96 |
return jsonify({"error": "No YouTube URL provided"}), 400
|
97 |
|
98 |
try:
|
99 |
+
|
100 |
+
"""
|
101 |
+
Fetches the transcript of a YouTube video using the YouTube Transcript API.
|
102 |
+
"""
|
103 |
+
|
104 |
+
# Extract the video ID from the YouTube URL
|
105 |
+
video_id = youtube_url.split("v=")[-1].split("&")[0]
|
|
|
|
|
|
|
|
|
|
|
|
|
106 |
|
107 |
+
# Fetch the transcript for the given video ID
|
108 |
+
transcript_data = YouTubeTranscriptApi.get_transcript(video_id)
|
109 |
+
|
110 |
+
# Print transcript to console
|
111 |
+
print(f"Transcript for video ID {video_id}:")
|
112 |
+
transcript = " ".join([segment['text'] for segment in transcript_data])
|
113 |
+
|
114 |
+
|
115 |
|
116 |
# Send the transcript to the Gemini API for structured data
|
117 |
structured_data = query_gemini_api(transcript)
|
118 |
+
|
119 |
|
120 |
# Return the structured data
|
121 |
return jsonify(structured_data)
|