camparchimedes commited on
Commit
49113b6
·
verified ·
1 Parent(s): 5b098b4

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +23 -31
app.py CHANGED
@@ -107,13 +107,8 @@ def transcribe(microphone, file_upload, batch_size=15):
107
 
108
  return warn_output + text.strip(), system_info
109
 
110
-
111
-
112
-
113
-
114
  # ------------summary section------------
115
 
116
-
117
  # ------------for app integration later------------
118
 
119
  nlp = spacy.blank("nb") # codename 'nb' = Norwegian Bokmål
@@ -145,9 +140,9 @@ def preprocess_text(text, file_upload):
145
 
146
  @spaces.GPU()
147
  def summarize_text(text, file_upload):
148
- #
149
- # ----add same if/elif logic as above here----
150
- #
151
  preprocessed_text = preprocess_text(text)
152
  inputs = summarization_model(preprocessed_text, max_length=1024, return_tensors="pt", truncation=True)
153
  inputs = inputs.to(device)
@@ -167,9 +162,9 @@ def build_similarity_matrix(sentences):
167
  # PageRank
168
  @spaces.GPU()
169
  def graph_based_summary(text, file_upload, num_paragraphs=3):
170
- #
171
- # ----add same if/elif logic as above here----
172
- #
173
  sentences = [sent.text for sent in doc.sents]
174
  if len(sentences) < num_paragraphs:
175
  return ' '.join(sentences)
@@ -211,7 +206,7 @@ def lex_rank_summary(text, file_upload, num_paragraphs=3, threshold=0.1):
211
  @spaces.GPU()
212
  def text_rank_summary(text, file_upload, num_paragraphs=3):
213
 
214
- if (text is not None) and (file_upload is None):
215
  doc = nlp(text)
216
 
217
  elif (text is None) and (file_upload is not None):
@@ -235,9 +230,9 @@ def save_to_pdf(text, summary):
235
  pdf = FPDF()
236
  pdf.add_page()
237
  pdf.set_font("Arial", size=12)
238
- #
239
- # ----add same if/elif logic as above here----
240
- #
241
  if text:
242
  pdf.multi_cell(0, 10, "Text:\n" + text)
243
 
@@ -258,21 +253,20 @@ with iface:
258
  gr.Markdown(HEADER_INFO)
259
 
260
  with gr.Row():
261
- gr.Markdown('''
262
- ##### Here you will get transcription output
263
- ##### ''')
264
- microphone = gr.Audio(sources="microphone", type="filepath")
265
- upload = gr.Audio(sources="upload", type="filepath")
266
-
267
 
268
- transcribe_btn = gr.Button("Transcribe Interview")
269
- text_output = gr.Textbox()
270
- system_info = gr.Textbox(label="System Info")
271
 
272
- transcribe_btn.click(transcribe_audio,
273
- [microphone, upload], [text_output]
274
- [system_info]
275
- )
276
 
277
  with gr.Tabs():
278
 
@@ -294,7 +288,6 @@ with iface:
294
  summarize_uploaded_button_graph.click(fn=graph_based_summary(file_upload), inputs=[text_input_graph], outputs=[summary_output_graph])
295
 
296
  with gr.TabItem("Summary | LexRank"):
297
- with gr.Blocks():
298
  text_output = gr.Textbox(label="Transcription Output")
299
  text_input_lex = gr.Textbox(label="Input Text", placeholder="txt2summarize")
300
  summary_output_lex = gr.Textbox(label="LexRank | cosine similarity")
@@ -321,7 +314,6 @@ with iface:
321
  """)
322
  gr.Markdown("""
323
  *Bjørn*: **sammendrag basert på i de setningene som ligner mest på hverandre fra teksten**
324
-
325
  """)
326
 
327
  summarize_transcribed_button_text_rank = gr.Button("Summary of Transcribed Text, Click Here")
@@ -339,4 +331,4 @@ with iface:
339
 
340
  pdf_text_only.click(fn=lambda text: save_to_pdf(text, ""), inputs=[transcribed_text], outputs=[pdf_output])
341
  pdf_summary_only.click(fn=lambda summary: save_to_pdf("", summary), inputs=[summary_output_graph, summary_output_lex, summary_output_text_rank], outputs=[pdf_output]) # Includes all summary outputs
342
- pdf_both.click(fn=lambda text, summary: save_to_pdf(text, summary), inputs=[transcribed_text, summary_output_graph], outputs=[pdf_output])
 
107
 
108
  return warn_output + text.strip(), system_info
109
 
 
 
 
 
110
  # ------------summary section------------
111
 
 
112
  # ------------for app integration later------------
113
 
114
  nlp = spacy.blank("nb") # codename 'nb' = Norwegian Bokmål
 
140
 
141
  @spaces.GPU()
142
  def summarize_text(text, file_upload):
143
+ #
144
+ # ----add same if/elif logic as above here----
145
+ #
146
  preprocessed_text = preprocess_text(text)
147
  inputs = summarization_model(preprocessed_text, max_length=1024, return_tensors="pt", truncation=True)
148
  inputs = inputs.to(device)
 
162
  # PageRank
163
  @spaces.GPU()
164
  def graph_based_summary(text, file_upload, num_paragraphs=3):
165
+ #
166
+ # ----add same if/elif logic as above here----
167
+ #
168
  sentences = [sent.text for sent in doc.sents]
169
  if len(sentences) < num_paragraphs:
170
  return ' '.join(sentences)
 
206
  @spaces.GPU()
207
  def text_rank_summary(text, file_upload, num_paragraphs=3):
208
 
209
+ if (text is not None) and (file_upload is not None):
210
  doc = nlp(text)
211
 
212
  elif (text is None) and (file_upload is not None):
 
230
  pdf = FPDF()
231
  pdf.add_page()
232
  pdf.set_font("Arial", size=12)
233
+ #
234
+ # ----add same if/elif logic as above here----
235
+ #
236
  if text:
237
  pdf.multi_cell(0, 10, "Text:\n" + text)
238
 
 
253
  gr.Markdown(HEADER_INFO)
254
 
255
  with gr.Row():
256
+ gr.Markdown('''
257
+ ##### Here you will get transcription output
258
+ ##### ''')
259
+ microphone = gr.Audio(sources="microphone", type="filepath")
260
+ upload = gr.Audio(sources="upload", type="filepath")
 
261
 
262
+ transcribe_btn = gr.Button("Transcribe Interview")
263
+ text_output = gr.Textbox()
264
+ system_info = gr.Textbox(label="System Info")
265
 
266
+ transcribe_btn.click(transcribe_audio,
267
+ [microphone, upload], [text_output]
268
+ [system_info]
269
+ )
270
 
271
  with gr.Tabs():
272
 
 
288
  summarize_uploaded_button_graph.click(fn=graph_based_summary(file_upload), inputs=[text_input_graph], outputs=[summary_output_graph])
289
 
290
  with gr.TabItem("Summary | LexRank"):
 
291
  text_output = gr.Textbox(label="Transcription Output")
292
  text_input_lex = gr.Textbox(label="Input Text", placeholder="txt2summarize")
293
  summary_output_lex = gr.Textbox(label="LexRank | cosine similarity")
 
314
  """)
315
  gr.Markdown("""
316
  *Bjørn*: **sammendrag basert på i de setningene som ligner mest på hverandre fra teksten**
 
317
  """)
318
 
319
  summarize_transcribed_button_text_rank = gr.Button("Summary of Transcribed Text, Click Here")
 
331
 
332
  pdf_text_only.click(fn=lambda text: save_to_pdf(text, ""), inputs=[transcribed_text], outputs=[pdf_output])
333
  pdf_summary_only.click(fn=lambda summary: save_to_pdf("", summary), inputs=[summary_output_graph, summary_output_lex, summary_output_text_rank], outputs=[pdf_output]) # Includes all summary outputs
334
+ pdf_both.click(fn=lambda text, summary: save_to_pdf(text, summary), inputs=[transcribed_text, summary_output_graph], outputs=[pdf_output])