Nechba commited on
Commit
68d753f
·
verified ·
1 Parent(s): 9d71faf

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +14 -10
app.py CHANGED
@@ -22,19 +22,23 @@ ner_pipeline = pipeline("ner", model=ner_model, tokenizer=ner_tokenizer) # Rena
22
 
23
  @app.route('/transcribe', methods=['POST'])
24
  def transcribe():
25
- # Get the audio file from the request
26
- if 'audio_file' not in request.files:
27
- return jsonify({"error": "No audio file provided"}), 400
 
 
 
 
 
28
 
29
- audio_file = request.files['audio_file']
 
30
 
31
- # Save the file to a temporary location
32
- audio_file_path = "temp_audio.mp3"
33
- audio_file.save(audio_file_path)
34
 
35
- # Transcribe the audio to text
36
- result = whisper_model.transcribe(audio_file_path)
37
- return jsonify({"text": result["text"]})
38
 
39
 
40
 
 
22
 
23
  @app.route('/transcribe', methods=['POST'])
24
  def transcribe():
25
+ try:
26
+ # Read the raw audio bytes
27
+ audio_bytes = request.data # Get raw bytes from request
28
+ if not audio_bytes:
29
+ return jsonify({"error": "No audio data provided"}), 400
30
+
31
+ # Convert bytes to a file-like object
32
+ audio_file = io.BytesIO(audio_bytes)
33
 
34
+ # Transcribe the audio
35
+ result = whisper_model.transcribe(audio_file)
36
 
37
+ return jsonify({"text": result["text"]})
 
 
38
 
39
+ except Exception as e:
40
+ print("Error:", str(e)) # Log the error
41
+ return jsonify({"error": "Internal Server Error", "details": str(e)}), 500
42
 
43
 
44