Spaces:
Running
Running
Update app.py
Browse files
app.py
CHANGED
|
@@ -88,6 +88,42 @@ def process_audio():
|
|
| 88 |
print(f"Temporary WAV file deleted: {temp_audio_path}")
|
| 89 |
|
| 90 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 91 |
@app.route('/process-youtube', methods=['POST'])
|
| 92 |
def process_youtube():
|
| 93 |
youtube_url = request.json.get('youtube_url')
|
|
@@ -96,28 +132,29 @@ def process_youtube():
|
|
| 96 |
return jsonify({"error": "No YouTube URL provided"}), 400
|
| 97 |
|
| 98 |
try:
|
| 99 |
-
|
| 100 |
-
|
| 101 |
# Extract the video ID from the YouTube URL
|
| 102 |
video_id = youtube_url.split("v=")[-1].split("&")[0]
|
|
|
|
| 103 |
|
| 104 |
-
|
| 105 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
| 106 |
|
| 107 |
-
#
|
| 108 |
-
print(f"Transcript for video ID {video_id}:")
|
| 109 |
transcript = " ".join([segment['text'] for segment in transcript_data])
|
|
|
|
| 110 |
|
| 111 |
-
|
| 112 |
-
|
| 113 |
-
# Send the transcript to the Gemini API for structured data
|
| 114 |
structured_data = query_gemini_api(transcript)
|
| 115 |
-
|
| 116 |
|
| 117 |
-
# Return
|
| 118 |
return jsonify(structured_data)
|
| 119 |
|
| 120 |
except Exception as e:
|
|
|
|
| 121 |
return jsonify({"error": str(e)}), 500
|
| 122 |
|
| 123 |
|
|
|
|
| 88 |
print(f"Temporary WAV file deleted: {temp_audio_path}")
|
| 89 |
|
| 90 |
|
| 91 |
+
# @app.route('/process-youtube', methods=['POST'])
|
| 92 |
+
# def process_youtube():
|
| 93 |
+
# youtube_url = request.json.get('youtube_url')
|
| 94 |
+
|
| 95 |
+
# if not youtube_url:
|
| 96 |
+
# return jsonify({"error": "No YouTube URL provided"}), 400
|
| 97 |
+
|
| 98 |
+
# try:
|
| 99 |
+
|
| 100 |
+
|
| 101 |
+
# # Extract the video ID from the YouTube URL
|
| 102 |
+
# video_id = youtube_url.split("v=")[-1].split("&")[0]
|
| 103 |
+
|
| 104 |
+
# # Fetch the transcript for the given video ID
|
| 105 |
+
# transcript_data = YouTubeTranscriptApi.get_transcript(video_id)
|
| 106 |
+
|
| 107 |
+
# # Print transcript to console
|
| 108 |
+
# print(f"Transcript for video ID {video_id}:")
|
| 109 |
+
# transcript = " ".join([segment['text'] for segment in transcript_data])
|
| 110 |
+
|
| 111 |
+
|
| 112 |
+
|
| 113 |
+
# # Send the transcript to the Gemini API for structured data
|
| 114 |
+
# structured_data = query_gemini_api(transcript)
|
| 115 |
+
|
| 116 |
+
|
| 117 |
+
# # Return the structured data
|
| 118 |
+
# return jsonify(structured_data)
|
| 119 |
+
|
| 120 |
+
# except Exception as e:
|
| 121 |
+
# return jsonify({"error": str(e)}), 500
|
| 122 |
+
|
| 123 |
+
|
| 124 |
+
import logging
|
| 125 |
+
logging.basicConfig(level=logging.DEBUG)
|
| 126 |
+
|
| 127 |
@app.route('/process-youtube', methods=['POST'])
|
| 128 |
def process_youtube():
|
| 129 |
youtube_url = request.json.get('youtube_url')
|
|
|
|
| 132 |
return jsonify({"error": "No YouTube URL provided"}), 400
|
| 133 |
|
| 134 |
try:
|
|
|
|
|
|
|
| 135 |
# Extract the video ID from the YouTube URL
|
| 136 |
video_id = youtube_url.split("v=")[-1].split("&")[0]
|
| 137 |
+
logging.debug(f"Processing video ID: {video_id}")
|
| 138 |
|
| 139 |
+
try:
|
| 140 |
+
# Fetch transcript
|
| 141 |
+
transcript_data = YouTubeTranscriptApi.get_transcript(video_id)
|
| 142 |
+
except YouTubeTranscriptApiException as e:
|
| 143 |
+
logging.error(f"Error fetching transcript for {video_id}: {e}")
|
| 144 |
+
return jsonify({"error": f"Could not retrieve transcript for video {video_id}: {str(e)}"}), 500
|
| 145 |
|
| 146 |
+
# Concatenate transcript
|
|
|
|
| 147 |
transcript = " ".join([segment['text'] for segment in transcript_data])
|
| 148 |
+
logging.debug(f"Transcript: {transcript}")
|
| 149 |
|
| 150 |
+
# Send to Gemini API
|
|
|
|
|
|
|
| 151 |
structured_data = query_gemini_api(transcript)
|
|
|
|
| 152 |
|
| 153 |
+
# Return structured data
|
| 154 |
return jsonify(structured_data)
|
| 155 |
|
| 156 |
except Exception as e:
|
| 157 |
+
logging.error(f"Unexpected error: {str(e)}")
|
| 158 |
return jsonify({"error": str(e)}), 500
|
| 159 |
|
| 160 |
|