Spaces:
Build error
Build error
Update app.py
Browse files
app.py
CHANGED
@@ -50,7 +50,7 @@ from sklearn.feature_extraction.text import TfidfVectorizer
|
|
50 |
from sklearn.metrics.pairwise import cosine_similarity
|
51 |
warnings.filterwarnings("ignore")
|
52 |
|
53 |
-
#
|
54 |
HEADER_INFO = """
|
55 |
# WEB APP ✨| Norwegian WHISPER Model
|
56 |
Switch Work [Transkribering av lydfiler til norsk skrift]
|
@@ -107,9 +107,9 @@ def transcribe(microphone, file_upload, batch_size=15):
|
|
107 |
|
108 |
return warn_output + text.strip(), system_info
|
109 |
|
110 |
-
#
|
111 |
|
112 |
-
#
|
113 |
|
114 |
nlp = spacy.blank("nb") # codename 'nb' = Norwegian Bokmål
|
115 |
nlp.add_pipe('sentencizer')
|
@@ -143,7 +143,7 @@ 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)
|
149 |
summary_ids = summarization_model.generate(inputs.input_ids, num_beams=5, max_length=150, early_stopping=True)
|
@@ -262,9 +262,9 @@ with iface:
|
|
262 |
transcribe_btn = gr.Button("Transcribe Interview")
|
263 |
text_output = gr.Textbox()
|
264 |
system_info = gr.Textbox(label="System Info")
|
265 |
-
# --basic syntax!: positional argument ")" follows keyword argument, e.g ..., system_info :P
|
266 |
-
transcribe_btn.click(fn=transcribe_audio,[microphone, upload], outputs=[text_output, system_info])
|
267 |
|
|
|
|
|
268 |
|
269 |
with gr.Tabs():
|
270 |
|
@@ -281,9 +281,9 @@ with iface:
|
|
281 |
""")
|
282 |
|
283 |
summarize_transcribed_button_graph = gr.Button("Summary of Transcribed Text, Click Here")
|
284 |
-
summarize_transcribed_button_graph.click(fn=lambda text: graph_based_summary(text), inputs=[
|
285 |
summarize_uploaded_button_graph = gr.Button("Upload Text to Summarize, Click Here")
|
286 |
-
summarize_uploaded_button_graph.click(fn=graph_based_summary
|
287 |
|
288 |
with gr.TabItem("Summary | LexRank"):
|
289 |
text_output = gr.Textbox(label="Transcription Output")
|
@@ -299,9 +299,9 @@ with iface:
|
|
299 |
""")
|
300 |
|
301 |
summarize_transcribed_button_lex = gr.Button("Summary of Transcribed Text, Click Here")
|
302 |
-
summarize_transcribed_button_lex.click(fn=lambda text: lex_rank_summary(text), inputs=[
|
303 |
summarize_uploaded_button_lex = gr.Button("Upload Text to Summarize, Click Here")
|
304 |
-
summarize_uploaded_button_lex.click(fn=lex_rank_summary
|
305 |
|
306 |
with gr.TabItem("Summary | TextRank"):
|
307 |
text_input_text_rank = gr.Textbox(label="Input Text", placeholder="txt2summarize")
|
@@ -315,10 +315,9 @@ with iface:
|
|
315 |
""")
|
316 |
|
317 |
summarize_transcribed_button_text_rank = gr.Button("Summary of Transcribed Text, Click Here")
|
318 |
-
summarize_transcribed_button_text_rank.click(fn=lambda text: text_rank_summary(text), inputs=[
|
319 |
summarize_uploaded_button_text_rank = gr.Button("Upload Text to Summarize, Click Here")
|
320 |
-
summarize_uploaded_button_text_rank.click(fn=text_rank_summary
|
321 |
-
|
322 |
|
323 |
with gr.TabItem("Download PDF"):
|
324 |
pdf_text_only = gr.Button("Download PDF with Transcribed Text Only")
|
@@ -327,6 +326,7 @@ with iface:
|
|
327 |
|
328 |
pdf_output = gr.File(label="Download PDF")
|
329 |
|
330 |
-
pdf_text_only.click(fn=lambda text: save_to_pdf(text, ""), inputs=[
|
331 |
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
|
332 |
-
pdf_both.click(fn=lambda text, summary: save_to_pdf(text, summary), inputs=[
|
|
|
|
50 |
from sklearn.metrics.pairwise import cosine_similarity
|
51 |
warnings.filterwarnings("ignore")
|
52 |
|
53 |
+
# ------------header section------------
|
54 |
HEADER_INFO = """
|
55 |
# WEB APP ✨| Norwegian WHISPER Model
|
56 |
Switch Work [Transkribering av lydfiler til norsk skrift]
|
|
|
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
|
115 |
nlp.add_pipe('sentencizer')
|
|
|
143 |
#
|
144 |
# ----add same if/elif logic as above here----
|
145 |
#
|
146 |
+
preprocessed_text = preprocess_text(text, file_upload)
|
147 |
inputs = summarization_model(preprocessed_text, max_length=1024, return_tensors="pt", truncation=True)
|
148 |
inputs = inputs.to(device)
|
149 |
summary_ids = summarization_model.generate(inputs.input_ids, num_beams=5, max_length=150, early_stopping=True)
|
|
|
262 |
transcribe_btn = gr.Button("Transcribe Interview")
|
263 |
text_output = gr.Textbox()
|
264 |
system_info = gr.Textbox(label="System Info")
|
|
|
|
|
265 |
|
266 |
+
# Corrected the order of arguments here to prevent the SyntaxError
|
267 |
+
transcribe_btn.click(fn=transcribe, inputs=[microphone, upload], outputs=[text_output, system_info])
|
268 |
|
269 |
with gr.Tabs():
|
270 |
|
|
|
281 |
""")
|
282 |
|
283 |
summarize_transcribed_button_graph = gr.Button("Summary of Transcribed Text, Click Here")
|
284 |
+
summarize_transcribed_button_graph.click(fn=lambda text: graph_based_summary(text, None), inputs=[text_input_graph], outputs=[summary_output_graph])
|
285 |
summarize_uploaded_button_graph = gr.Button("Upload Text to Summarize, Click Here")
|
286 |
+
summarize_uploaded_button_graph.click(fn=graph_based_summary, inputs=[None, upload], outputs=[summary_output_graph])
|
287 |
|
288 |
with gr.TabItem("Summary | LexRank"):
|
289 |
text_output = gr.Textbox(label="Transcription Output")
|
|
|
299 |
""")
|
300 |
|
301 |
summarize_transcribed_button_lex = gr.Button("Summary of Transcribed Text, Click Here")
|
302 |
+
summarize_transcribed_button_lex.click(fn=lambda text: lex_rank_summary(text, None), inputs=[text_input_lex], outputs=[summary_output_lex])
|
303 |
summarize_uploaded_button_lex = gr.Button("Upload Text to Summarize, Click Here")
|
304 |
+
summarize_uploaded_button_lex.click(fn=lex_rank_summary, inputs=[None, upload], outputs=[summary_output_lex])
|
305 |
|
306 |
with gr.TabItem("Summary | TextRank"):
|
307 |
text_input_text_rank = gr.Textbox(label="Input Text", placeholder="txt2summarize")
|
|
|
315 |
""")
|
316 |
|
317 |
summarize_transcribed_button_text_rank = gr.Button("Summary of Transcribed Text, Click Here")
|
318 |
+
summarize_transcribed_button_text_rank.click(fn=lambda text: text_rank_summary(text, None), inputs=[text_input_text_rank], outputs=[summary_output_text_rank])
|
319 |
summarize_uploaded_button_text_rank = gr.Button("Upload Text to Summarize, Click Here")
|
320 |
+
summarize_uploaded_button_text_rank.click(fn=text_rank_summary, inputs=[None, upload], outputs=[summary_output_text_rank])
|
|
|
321 |
|
322 |
with gr.TabItem("Download PDF"):
|
323 |
pdf_text_only = gr.Button("Download PDF with Transcribed Text Only")
|
|
|
326 |
|
327 |
pdf_output = gr.File(label="Download PDF")
|
328 |
|
329 |
+
pdf_text_only.click(fn=lambda text: save_to_pdf(text, ""), inputs=[text_output], outputs=[pdf_output])
|
330 |
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
|
331 |
+
pdf_both.click(fn=lambda text, summary: save_to_pdf(text, summary), inputs=[text_output, summary_output_graph], outputs=[pdf_output])
|
332 |
+
|