camparchimedes commited on
Commit
7735671
·
verified ·
1 Parent(s): cb42a20

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +76 -23
app.py CHANGED
@@ -124,7 +124,7 @@ def summarize_text(text):
124
  # HTML syntax for imagery
125
  image_html = """
126
  <div style="text-align: center;">
127
- <img src="https://huggingface.co/spaces/camparchimedes/ola_s-audioshop/raw/main/picture.png" alt="Banner" width="auto" height="auto">
128
  </div>
129
  """
130
 
@@ -151,31 +151,84 @@ iface = gr.Blocks()
151
 
152
  with iface:
153
  gr.HTML(image_html)
154
- gr.Markdown("# Vi har nå muligheten til å oversette lydfiler til norsk skrift. Denne fungerer på norsk og oversetter norsk tale til tekst.")
155
- audio_input = gr.Audio(type="filepath")
156
- batch_size_input = gr.Slider(minimum=7, maximum=16, step=1, label="Batch Size")
157
- transcription_output = gr.Textbox(label="Transcription | nb-whisper-large-semantic")
158
- summary_output = gr.Textbox(label="Summary | TextRank, graph-based")
159
- pdf_output = gr.File(label="Download PDF")
160
- transcribe_button = gr.Button("Transcribe and Summarize")
161
-
162
- def transcribe_and_summarize(audio_file, batch_size):
163
- transcription, result = transcribe_audio(audio_file, batch_size)
164
- summary = summarize_text(transcription)
165
- pdf_path = save_to_pdf(transcription, summary)
166
- return result, summary, pdf_path
167
-
168
- transcribe_button.click(
169
- fn=transcribe_and_summarize,
170
- inputs=[audio_input, batch_size_input],
171
- outputs=[transcription_output, summary_output, pdf_output]
172
- )
 
 
173
 
174
- # run
175
- iface.launch(share=True, debug=True)
 
 
 
 
 
 
 
 
 
 
 
 
 
 
176
 
177
-
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
178
 
179
 
180
  # run
181
  iface.launch(share=True, debug=True)
 
 
 
124
  # HTML syntax for imagery
125
  image_html = """
126
  <div style="text-align: center;">
127
+ <img src="https://huggingface.co/spaces/camparchimedes/ola_s-audioshop/raw/main/picture.png" alt="Banner" width="100%" height="auto">
128
  </div>
129
  """
130
 
 
151
 
152
  with iface:
153
  gr.HTML(image_html)
154
+ gr.Markdown("# Vi har nå muligheten til å oversette lydfiler til norsk skrift.")
155
+
156
+ with gr.Tabs():
157
+
158
+ # First Tab: Transcription
159
+ with gr.TabItem("Transcription"):
160
+ audio_input = gr.Audio(type="filepath")
161
+ batch_size_input = gr.Slider(minimum=7, maximum=16, step=1, label="Batch Size")
162
+ transcription_output = gr.Textbox(label="Transcription | nb-whisper-large-semantic")
163
+ result_output = gr.Textbox(label="Time taken and Number of words")
164
+ transcribe_button = gr.Button("Transcribe")
165
+
166
+ def transcribe(audio_file, batch_size):
167
+ transcription, result = transcribe_audio(audio_file, batch_size)
168
+ return transcription, result
169
+
170
+ transcribe_button.click(
171
+ fn=transcribe,
172
+ inputs=[audio_input, batch_size_input],
173
+ outputs=[transcription_output, result_output]
174
+ )
175
 
176
+ # Second Tab: Summary
177
+ with gr.TabItem("Summary"):
178
+ summary_output = gr.Textbox(label="Summary | TextRank, graph-based")
179
+ summarize_button = gr.Button("Summarize")
180
+
181
+ def summarize(transcription):
182
+ if not transcription:
183
+ return "Warning: a transcription must be available."
184
+ summary = summarize_text(transcription)
185
+ return summary
186
+
187
+ summarize_button.click(
188
+ fn=summarize,
189
+ inputs=[transcription_output], # Use the transcription from the first tab
190
+ outputs=summary_output
191
+ )
192
 
193
+ # Third Tab: PDF Download Options
194
+ with gr.TabItem("Download PDF"):
195
+ pdf_transcription_only = gr.Button("Download PDF with Transcription Only")
196
+ pdf_summary_only = gr.Button("Download PDF with Summary Only")
197
+ pdf_both = gr.Button("Download PDF with Both")
198
+
199
+ pdf_output_transcription_only = gr.File(label="Download PDF")
200
+ pdf_output_summary_only = gr.File(label="Download PDF")
201
+ pdf_output_both = gr.File(label="Download PDF")
202
+
203
+ def generate_pdf_transcription_only(transcription):
204
+ return save_to_pdf(transcription, "")
205
+
206
+ def generate_pdf_summary_only(summary):
207
+ return save_to_pdf("", summary)
208
+
209
+ def generate_pdf_both(transcription, summary):
210
+ return save_to_pdf(transcription, summary)
211
+
212
+ pdf_transcription_only.click(
213
+ fn=generate_pdf_transcription_only,
214
+ inputs=[transcription_output],
215
+ outputs=[pdf_output_transcription_only]
216
+ )
217
+
218
+ pdf_summary_only.click(
219
+ fn=generate_pdf_summary_only,
220
+ inputs=[summary_output],
221
+ outputs=[pdf_output_summary_only]
222
+ )
223
+
224
+ pdf_both.click(
225
+ fn=generate_pdf_both,
226
+ inputs=[transcription_output, summary_output],
227
+ outputs=[pdf_output_both]
228
+ )
229
 
230
 
231
  # run
232
  iface.launch(share=True, debug=True)
233
+
234
+