Spaces:
Running
Running
Update app.py
Browse files
app.py
CHANGED
@@ -23,18 +23,17 @@ def extract_audio_from_m3u8(url):
|
|
23 |
except Exception as e:
|
24 |
return f"An error occurred: {e}"
|
25 |
|
26 |
-
def transcribe_function(audio, state,
|
|
|
27 |
if m3u8_url:
|
28 |
audio = extract_audio_from_m3u8(m3u8_url)
|
29 |
|
30 |
-
|
31 |
-
audio = uploaded_audio
|
32 |
-
|
33 |
if not audio:
|
34 |
-
return {state_var: state, transcription_var: state}
|
35 |
|
36 |
try:
|
37 |
-
time.sleep(3)
|
38 |
text = p(audio, chunk_length_s=50)["text"]
|
39 |
state += text + "\n"
|
40 |
return {state_var: state, transcription_var: state}
|
@@ -50,13 +49,11 @@ with gr.Blocks() as demo:
|
|
50 |
|
51 |
with gr.Row():
|
52 |
with gr.Column():
|
53 |
-
#
|
54 |
-
|
55 |
-
uploaded_audio = gr.Audio(type="filepath", label="Upload Audio File")
|
56 |
m3u8_url = gr.Textbox(label="m3u8 URL | E.g.: from kvf.fo or logting.fo")
|
57 |
-
|
58 |
with gr.Column():
|
59 |
-
#
|
60 |
transcription_var = gr.Textbox(type="text", label="Transcription", interactive=False)
|
61 |
|
62 |
with gr.Row():
|
@@ -65,7 +62,7 @@ with gr.Blocks() as demo:
|
|
65 |
|
66 |
transcribe_button.click(
|
67 |
transcribe_function,
|
68 |
-
[
|
69 |
[transcription_var, state_var]
|
70 |
)
|
71 |
|
|
|
23 |
except Exception as e:
|
24 |
return f"An error occurred: {e}"
|
25 |
|
26 |
+
def transcribe_function(audio, state, m3u8_url):
|
27 |
+
# If an m3u8 URL is provided, extract audio from the URL
|
28 |
if m3u8_url:
|
29 |
audio = extract_audio_from_m3u8(m3u8_url)
|
30 |
|
31 |
+
# If no audio is provided, return the current state
|
|
|
|
|
32 |
if not audio:
|
33 |
+
return {state_var: state, transcription_var: state}
|
34 |
|
35 |
try:
|
36 |
+
time.sleep(3) # Simulate processing delay
|
37 |
text = p(audio, chunk_length_s=50)["text"]
|
38 |
state += text + "\n"
|
39 |
return {state_var: state, transcription_var: state}
|
|
|
49 |
|
50 |
with gr.Row():
|
51 |
with gr.Column():
|
52 |
+
# Single Audio component supporting both recording and file upload
|
53 |
+
audio_input = gr.Audio(type="filepath", label="Audio (Record or Upload)")
|
|
|
54 |
m3u8_url = gr.Textbox(label="m3u8 URL | E.g.: from kvf.fo or logting.fo")
|
|
|
55 |
with gr.Column():
|
56 |
+
# Use interactive=False to make the textbox read-only
|
57 |
transcription_var = gr.Textbox(type="text", label="Transcription", interactive=False)
|
58 |
|
59 |
with gr.Row():
|
|
|
62 |
|
63 |
transcribe_button.click(
|
64 |
transcribe_function,
|
65 |
+
[audio_input, state_var, m3u8_url],
|
66 |
[transcription_var, state_var]
|
67 |
)
|
68 |
|