GoodML commited on
Commit
b6e7946
·
verified ·
1 Parent(s): c139644

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +21 -31
app.py CHANGED
@@ -208,41 +208,31 @@ def process_audio():
208
 
209
  audio_file = request.files['audio']
210
  print("AUDIO FILE NAME: ", audio_file)
 
211
  try:
212
- print("SAVING THE FILE TEMPO, ANIKET")
213
- # Step 1: Save audio to a temporary file
214
- with tempfile.NamedTemporaryFile(delete=False, suffix=".wav") as temp_audio_file:
215
- audio_file.save(temp_audio_file.name)
216
- print(f"Audio file saved: {temp_audio_file.name}")
217
-
218
- print("STARTING TRANSCRIPTION, ANIKET")
219
- # Step 2: Transcribe the audio using Whisper AI
220
- transcription = transcribe_audio(temp_audio_file.name)
221
-
222
- print("BEFORE THE transcription FAILED ERROR, CHECKING IF I GOT THE TRANSCRIPTION", transcription)
223
-
224
- if not transcription:
225
- return jsonify({"error": "Audio transcription failed"}), 500
226
-
227
- print("GOT THE transcription")
228
-
229
- print("Starting the GEMINI REQUEST TO STRUCTURE IT")
230
- # Step 3: Generate structured recipe information using Gemini API
231
- structured_data = query_gemini_api(transcription)
232
-
233
- print("GOT THE STRUCTURED DATA", structured_data)
234
- # Step 4: Return the structured data
235
- return jsonify(structured_data)
236
-
237
  except Exception as e:
238
  return jsonify({"error": str(e)}), 500
239
 
240
- finally:
241
- # Clean up temporary files
242
- if os.path.exists(temp_audio_file.name):
243
- os.remove(temp_audio_file.name)
244
-
245
-
246
  def transcribe_audio(audio_path):
247
  """
248
  Transcribe audio using Whisper AI.
 
208
 
209
  audio_file = request.files['audio']
210
  print("AUDIO FILE NAME: ", audio_file)
211
+
212
  try:
213
+ print("STARTING TRANSCRIPTION, ANIKET")
214
+ # Step 1: Transcribe the uploaded audio file directly
215
+ audio_file = request.files['audio']
216
+ transcription = transcribe_audio(audio_file)
217
+
218
+ print("BEFORE THE transcription FAILED ERROR, CHECKING IF I GOT THE TRANSCRIPTION", transcription)
219
+
220
+ if not transcription:
221
+ return jsonify({"error": "Audio transcription failed"}), 500
222
+
223
+ print("GOT THE transcription")
224
+
225
+ print("Starting the GEMINI REQUEST TO STRUCTURE IT")
226
+ # Step 2: Generate structured recipe information using Gemini API
227
+ structured_data = query_gemini_api(transcription)
228
+
229
+ print("GOT THE STRUCTURED DATA", structured_data)
230
+ # Step 3: Return the structured data
231
+ return jsonify(structured_data)
232
+
 
 
 
 
 
233
  except Exception as e:
234
  return jsonify({"error": str(e)}), 500
235
 
 
 
 
 
 
 
236
  def transcribe_audio(audio_path):
237
  """
238
  Transcribe audio using Whisper AI.