Spaces:
Running
Running
Update app.py
Browse files
app.py
CHANGED
@@ -28,13 +28,14 @@ def transcribe_audio(audio_file):
|
|
28 |
# Create Gradio interface
|
29 |
iface = gr.Interface(
|
30 |
fn=transcribe_audio,
|
31 |
-
inputs=gr.Audio(
|
32 |
outputs="text",
|
33 |
title="Audio Transcription App",
|
34 |
description="Upload an audio file to get the transcription",
|
35 |
theme="default",
|
36 |
layout="vertical",
|
37 |
live=False
|
|
|
38 |
|
39 |
|
40 |
from transformers import AutoProcessor, AutoModelForSpeechSeq2Seq, AutoTokenizer, AutoModelForSeq2SeqLM
|
@@ -106,15 +107,15 @@ def transcribe_audio(audio_file, batch_size=4):
|
|
106 |
|
107 |
return transcription.strip(), result
|
108 |
|
109 |
-
|
110 |
inputs = summarization_tokenizer([text], max_length=1024, return_tensors="pt", truncation=True)
|
111 |
inputs = inputs.to(device)
|
112 |
summary_ids = summarization_model.generate(inputs.input_ids, num_beams=4, max_length=150, early_stopping=True)
|
113 |
summary = summarization_tokenizer.decode(summary_ids[0], skip_special_tokens=True)
|
114 |
return summary
|
115 |
|
116 |
-
|
117 |
-
|
118 |
<div style="text-align: center;">
|
119 |
<img src="https://huggingface.co/spaces/camparchimedes/ola_s-audioshop/raw/main/Olas%20AudioSwitch%20Shop.png" alt="Banner" width="87%" height="auto">
|
120 |
</div>
|
@@ -127,7 +128,7 @@ banner_html = """
|
|
127 |
iface = gr.Blocks()
|
128 |
|
129 |
with iface:
|
130 |
-
gr.HTML(
|
131 |
gr.Markdown("# Switch Work Audio Transcription App\nUpload an audio file to get the transcription")
|
132 |
audio_input = gr.Audio(type="filepath")
|
133 |
batch_size_input = gr.Slider(minimum=1, maximum=16, step=1, default=4, label="Batch Size")
|
@@ -136,9 +137,9 @@ with iface:
|
|
136 |
transcribe_button = gr.Button("Transcribe and Summarize")
|
137 |
|
138 |
def transcribe_and_summarize(audio_file, batch_size):
|
139 |
-
transcription = transcribe_audio(audio_file, batch_size)
|
140 |
summary = summarize_text(transcription)
|
141 |
-
return
|
142 |
|
143 |
transcribe_button.click(fn=transcribe_and_summarize, inputs=[audio_input, batch_size_input], outputs=[transcription_output, summary_output])
|
144 |
|
@@ -148,7 +149,7 @@ def save_to_pdf(transcription, summary):
|
|
148 |
pdf.add_page()
|
149 |
pdf.set_font("Arial", size=12)
|
150 |
|
151 |
-
#
|
152 |
pdf.multi_cell(0, 10, "Transcription:\n" + transcription)
|
153 |
|
154 |
# paragraph space
|
@@ -165,7 +166,3 @@ def save_to_pdf(transcription, summary):
|
|
165 |
|
166 |
# run
|
167 |
iface.launch(share=True, debug=True)
|
168 |
-
|
169 |
-
|
170 |
-
|
171 |
-
|
|
|
28 |
# Create Gradio interface
|
29 |
iface = gr.Interface(
|
30 |
fn=transcribe_audio,
|
31 |
+
inputs=gr.Audio(type="filepath"),
|
32 |
outputs="text",
|
33 |
title="Audio Transcription App",
|
34 |
description="Upload an audio file to get the transcription",
|
35 |
theme="default",
|
36 |
layout="vertical",
|
37 |
live=False
|
38 |
+
)
|
39 |
|
40 |
|
41 |
from transformers import AutoProcessor, AutoModelForSpeechSeq2Seq, AutoTokenizer, AutoModelForSeq2SeqLM
|
|
|
107 |
|
108 |
return transcription.strip(), result
|
109 |
|
110 |
+
def summarize_text(text):
|
111 |
inputs = summarization_tokenizer([text], max_length=1024, return_tensors="pt", truncation=True)
|
112 |
inputs = inputs.to(device)
|
113 |
summary_ids = summarization_model.generate(inputs.input_ids, num_beams=4, max_length=150, early_stopping=True)
|
114 |
summary = summarization_tokenizer.decode(summary_ids[0], skip_special_tokens=True)
|
115 |
return summary
|
116 |
|
117 |
+
# HTML syntax for imagery
|
118 |
+
image_html = """
|
119 |
<div style="text-align: center;">
|
120 |
<img src="https://huggingface.co/spaces/camparchimedes/ola_s-audioshop/raw/main/Olas%20AudioSwitch%20Shop.png" alt="Banner" width="87%" height="auto">
|
121 |
</div>
|
|
|
128 |
iface = gr.Blocks()
|
129 |
|
130 |
with iface:
|
131 |
+
gr.HTML(image_html)
|
132 |
gr.Markdown("# Switch Work Audio Transcription App\nUpload an audio file to get the transcription")
|
133 |
audio_input = gr.Audio(type="filepath")
|
134 |
batch_size_input = gr.Slider(minimum=1, maximum=16, step=1, default=4, label="Batch Size")
|
|
|
137 |
transcribe_button = gr.Button("Transcribe and Summarize")
|
138 |
|
139 |
def transcribe_and_summarize(audio_file, batch_size):
|
140 |
+
transcription, result = transcribe_audio(audio_file, batch_size)
|
141 |
summary = summarize_text(transcription)
|
142 |
+
return result, summary
|
143 |
|
144 |
transcribe_button.click(fn=transcribe_and_summarize, inputs=[audio_input, batch_size_input], outputs=[transcription_output, summary_output])
|
145 |
|
|
|
149 |
pdf.add_page()
|
150 |
pdf.set_font("Arial", size=12)
|
151 |
|
152 |
+
# include transcription
|
153 |
pdf.multi_cell(0, 10, "Transcription:\n" + transcription)
|
154 |
|
155 |
# paragraph space
|
|
|
166 |
|
167 |
# run
|
168 |
iface.launch(share=True, debug=True)
|
|
|
|
|
|
|
|