Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
@@ -1,19 +1,15 @@
|
|
1 |
from flask import Flask, request, render_template, redirect, url_for
|
2 |
import os
|
3 |
from moviepy.editor import VideoFileClip
|
4 |
-
|
5 |
-
import torch
|
6 |
-
import torchaudio
|
7 |
|
8 |
app = Flask(__name__)
|
9 |
|
10 |
# Configure the maximum content length for uploads (500 MB)
|
11 |
app.config['MAX_CONTENT_LENGTH'] = 1024 * 1024 * 500 # 500 MB limit
|
12 |
|
13 |
-
# Load the model
|
14 |
-
|
15 |
-
processor = Wav2Vec2Processor.from_pretrained(model_name)
|
16 |
-
model = Wav2Vec2ForCTC.from_pretrained(model_name)
|
17 |
|
18 |
@app.route('/')
|
19 |
def index():
|
@@ -57,19 +53,10 @@ def transcribe_audio(audio_path):
|
|
57 |
raise FileNotFoundError(f"Audio file not found at {audio_path}")
|
58 |
|
59 |
try:
|
60 |
-
|
61 |
-
|
62 |
-
input_values = processor(speech.squeeze().numpy(), return_tensors="pt", sampling_rate=rate).input_values
|
63 |
-
|
64 |
-
# Perform the transcription
|
65 |
-
with torch.no_grad():
|
66 |
-
logits = model(input_values).logits
|
67 |
-
predicted_ids = torch.argmax(logits, dim=-1)
|
68 |
-
transcription = processor.batch_decode(predicted_ids)
|
69 |
-
|
70 |
-
return transcription[0]
|
71 |
except Exception as e:
|
72 |
raise RuntimeError(f"Error during transcription: {e}")
|
73 |
|
74 |
if __name__ == '__main__':
|
75 |
-
app.run(debug=False, host='0.0.0.0', port=7860)
|
|
|
1 |
from flask import Flask, request, render_template, redirect, url_for
|
2 |
import os
|
3 |
from moviepy.editor import VideoFileClip
|
4 |
+
import whisper
|
|
|
|
|
5 |
|
6 |
app = Flask(__name__)
|
7 |
|
8 |
# Configure the maximum content length for uploads (500 MB)
|
9 |
app.config['MAX_CONTENT_LENGTH'] = 1024 * 1024 * 500 # 500 MB limit
|
10 |
|
11 |
+
# Load the Whisper model
|
12 |
+
model = whisper.load_model("base")
|
|
|
|
|
13 |
|
14 |
@app.route('/')
|
15 |
def index():
|
|
|
53 |
raise FileNotFoundError(f"Audio file not found at {audio_path}")
|
54 |
|
55 |
try:
|
56 |
+
result = model.transcribe(audio_path)
|
57 |
+
return result["text"]
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
58 |
except Exception as e:
|
59 |
raise RuntimeError(f"Error during transcription: {e}")
|
60 |
|
61 |
if __name__ == '__main__':
|
62 |
+
app.run(debug=False, host='0.0.0.0', port=7860)
|