Nechba commited on
Commit
5020140
·
verified ·
1 Parent(s): 03f0774

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +11 -24
app.py CHANGED
@@ -23,34 +23,21 @@ ner_pipeline = pipeline("ner", model=ner_model, tokenizer=ner_tokenizer) # Rena
23
 
24
 
25
  @app.route('/transcribe', methods=['POST'])
26
- def transcribe_audio():
27
- # Check if a file was uploaded
28
- if 'file' not in request.files:
29
- return jsonify({'error': 'No file uploaded'}), 400
30
 
31
- file = request.files['file']
32
 
33
- # Check if the file is empty
34
- if file.filename == '':
35
- return jsonify({'error': 'No selected file'}), 400
36
 
37
- try:
38
- # Save the uploaded file to a temporary file
39
- with tempfile.NamedTemporaryFile(delete=False, suffix=".mp3") as temp_audio:
40
- file.save(temp_audio)
41
- temp_path = temp_audio.name
42
-
43
- # Transcribe the audio using Whisper
44
- result = whisper_model.transcribe(temp_path)
45
- transcription = result["text"]
46
-
47
- # Clean up the temporary file
48
- os.remove(temp_path)
49
 
50
- return jsonify({'transcription': transcription})
51
-
52
- except Exception as e:
53
- return jsonify({'error': str(e)}), 500
54
 
55
 
56
 
 
23
 
24
 
25
  @app.route('/transcribe', methods=['POST'])
26
+ def transcribe():
27
+ # Get the audio file from the request
28
+ if 'audio_file' not in request.files:
29
+ return jsonify({"error": "No audio file provided"}), 400
30
 
31
+ audio_file = request.files['audio_file']
32
 
33
+ # Save the file to a temporary location
34
+ audio_file_path = "temp_audio.mp3"
35
+ audio_file.save(audio_file_path)
36
 
37
+ # Transcribe the audio to text
38
+ result = whisper_model.transcribe(audio_file_path)
39
+ return jsonify({"text": result["text"]})
 
 
 
 
 
 
 
 
 
40
 
 
 
 
 
41
 
42
 
43