Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
@@ -18,7 +18,6 @@ def translate_audio(filepath):
|
|
18 |
gr.Warning("No audio found, please retry.")
|
19 |
return ""
|
20 |
|
21 |
-
# Load audio using pydub for chunking
|
22 |
audio = AudioSegment.from_file(filepath)
|
23 |
chunk_length_ms = 30 * 1000 # 30 seconds
|
24 |
chunks = [audio[i:i + chunk_length_ms] for i in range(0, len(audio), chunk_length_ms)]
|
@@ -29,11 +28,9 @@ def translate_audio(filepath):
|
|
29 |
chunk_path = f"chunk_{i}.wav"
|
30 |
chunk.export(chunk_path, format="wav")
|
31 |
|
32 |
-
# Load chunk for model input
|
33 |
waveform, sample_rate = torchaudio.load(chunk_path)
|
34 |
inputs = processor(waveform[0], sampling_rate=sample_rate, return_tensors="pt")
|
35 |
|
36 |
-
# Generate translated output
|
37 |
with torch.no_grad():
|
38 |
generated_ids = model.generate(
|
39 |
inputs["input_features"],
|
@@ -50,27 +47,26 @@ def translate_audio(filepath):
|
|
50 |
# Gradio UI components
|
51 |
mic_transcribe = gr.Interface(
|
52 |
fn=translate_audio,
|
53 |
-
inputs=gr.Audio(sources="microphone",
|
54 |
-
|
55 |
-
|
56 |
-
|
57 |
-
allow_flagging="never")
|
58 |
|
59 |
file_transcribe = gr.Interface(
|
60 |
fn=translate_audio,
|
61 |
-
inputs=gr.Audio(sources="upload",
|
62 |
-
|
63 |
-
|
64 |
-
|
65 |
-
|
|
|
|
|
66 |
|
67 |
with demo:
|
68 |
gr.TabbedInterface(
|
69 |
-
[mic_transcribe,
|
70 |
-
|
71 |
-
["Transcribe Microphone",
|
72 |
-
"Transcribe Audio File"],
|
73 |
)
|
|
|
74 |
server_port = int(os.environ.get("PORT", 7860))
|
75 |
-
demo.launch(share=True,
|
76 |
-
server_port=server_port)
|
|
|
18 |
gr.Warning("No audio found, please retry.")
|
19 |
return ""
|
20 |
|
|
|
21 |
audio = AudioSegment.from_file(filepath)
|
22 |
chunk_length_ms = 30 * 1000 # 30 seconds
|
23 |
chunks = [audio[i:i + chunk_length_ms] for i in range(0, len(audio), chunk_length_ms)]
|
|
|
28 |
chunk_path = f"chunk_{i}.wav"
|
29 |
chunk.export(chunk_path, format="wav")
|
30 |
|
|
|
31 |
waveform, sample_rate = torchaudio.load(chunk_path)
|
32 |
inputs = processor(waveform[0], sampling_rate=sample_rate, return_tensors="pt")
|
33 |
|
|
|
34 |
with torch.no_grad():
|
35 |
generated_ids = model.generate(
|
36 |
inputs["input_features"],
|
|
|
47 |
# Gradio UI components
|
48 |
mic_transcribe = gr.Interface(
|
49 |
fn=translate_audio,
|
50 |
+
inputs=gr.Audio(sources="microphone", type="filepath"),
|
51 |
+
outputs=gr.Textbox(label="Translation (English to Spanish)", lines=3),
|
52 |
+
allow_flagging="never"
|
53 |
+
)
|
|
|
54 |
|
55 |
file_transcribe = gr.Interface(
|
56 |
fn=translate_audio,
|
57 |
+
inputs=gr.Audio(sources="upload", type="filepath"),
|
58 |
+
outputs=gr.Textbox(label="Translation (English to Spanish)", lines=3),
|
59 |
+
allow_flagging="never"
|
60 |
+
)
|
61 |
+
|
62 |
+
# Initialize Blocks properly
|
63 |
+
demo = gr.Blocks()
|
64 |
|
65 |
with demo:
|
66 |
gr.TabbedInterface(
|
67 |
+
[mic_transcribe, file_transcribe],
|
68 |
+
["Transcribe Microphone", "Transcribe Audio File"]
|
|
|
|
|
69 |
)
|
70 |
+
|
71 |
server_port = int(os.environ.get("PORT", 7860))
|
72 |
+
demo.launch(share=True, server_port=server_port)
|
|