Update app.py
Browse files
app.py
CHANGED
@@ -81,17 +81,18 @@ def extract_audio_from_video(video_path, output_audio_path):
|
|
81 |
except Exception as e:
|
82 |
raise Exception(f"Failed to extract audio from video: {str(e)}")
|
83 |
|
84 |
-
def send_fcm_data_message(fcm_token, transcription, file_type, created_date, transcription_name):
|
85 |
"""Send an FCM message with transcription details and a notification"""
|
86 |
try:
|
87 |
message = messaging.Message(
|
88 |
notification=messaging.Notification(
|
89 |
title=transcription_name,
|
90 |
-
body=
|
91 |
),
|
92 |
data={
|
93 |
-
'
|
94 |
-
'
|
|
|
95 |
'created_date': created_date,
|
96 |
'transcription_name': transcription_name
|
97 |
},
|
@@ -175,12 +176,12 @@ def transcribe():
|
|
175 |
file_type = 'video' if file_extension in ALLOWED_VIDEO_EXTENSIONS else 'audio'
|
176 |
|
177 |
# Send FCM data message
|
178 |
-
|
179 |
-
send_fcm_data_message(fcm_token, full_text, file_type, created_date, transcription_name)
|
180 |
|
181 |
return jsonify({}), 200
|
182 |
|
183 |
except Exception as e:
|
|
|
184 |
return jsonify({'error': str(e)}), 500
|
185 |
|
186 |
finally:
|
|
|
81 |
except Exception as e:
|
82 |
raise Exception(f"Failed to extract audio from video: {str(e)}")
|
83 |
|
84 |
+
def send_fcm_data_message(fcm_token, transcription, file_type, created_date, transcription_name, message, status):
|
85 |
"""Send an FCM message with transcription details and a notification"""
|
86 |
try:
|
87 |
message = messaging.Message(
|
88 |
notification=messaging.Notification(
|
89 |
title=transcription_name,
|
90 |
+
body=message
|
91 |
),
|
92 |
data={
|
93 |
+
'status': status,
|
94 |
+
'transcription': transcription if transcription else '',
|
95 |
+
'file_type': file_type if file_type else '',
|
96 |
'created_date': created_date,
|
97 |
'transcription_name': transcription_name
|
98 |
},
|
|
|
176 |
file_type = 'video' if file_extension in ALLOWED_VIDEO_EXTENSIONS else 'audio'
|
177 |
|
178 |
# Send FCM data message
|
179 |
+
send_fcm_data_message(fcm_token, full_text, file_type, created_date, transcription_name, 'Transcription completed successfully!', 'success)
|
|
|
180 |
|
181 |
return jsonify({}), 200
|
182 |
|
183 |
except Exception as e:
|
184 |
+
send_fcm_data_message(fcm_token, full_text, file_type, created_date, transcription_name, 'Transcription failed. Please re-upload the file to try again.','fail')
|
185 |
return jsonify({'error': str(e)}), 500
|
186 |
|
187 |
finally:
|