Spaces:
Build error
Build error
Update app.py
Browse files
app.py
CHANGED
|
@@ -203,94 +203,18 @@ def text_rank_summary(text, num_paragraphs=3):
|
|
| 203 |
ranked_sentences = sorted(((scores[i], s) for i, s in enumerate(sentences)), reverse=True)
|
| 204 |
return ' '.join([ranked_sentences[i][1] for i in range(num_paragraphs)])
|
| 205 |
|
| 206 |
-
|
| 207 |
-
# Save text+summary/PDF
|
| 208 |
-
def save_to_pdf(text, summary):
|
| 209 |
-
pdf = FPDF()
|
| 210 |
-
pdf.add_page()
|
| 211 |
-
pdf.set_font("Arial", size=12)
|
| 212 |
-
|
| 213 |
-
if text:
|
| 214 |
-
pdf.multi_cell(0, 10, "Text:\n" + text)
|
| 215 |
-
|
| 216 |
-
pdf.ln(10) # Paragraph space
|
| 217 |
-
|
| 218 |
-
if summary:
|
| 219 |
-
pdf.multi_cell(0, 10, "Summary:\n" + summary)
|
| 220 |
-
|
| 221 |
-
pdf_output_path = "transcription.pdf"
|
| 222 |
-
pdf.output(pdf_output_path)
|
| 223 |
-
return pdf_output_path
|
| 224 |
-
|
| 225 |
iface = gr.Blocks()
|
| 226 |
|
| 227 |
with iface:
|
| 228 |
-
|
| 229 |
gr.HTML(SIDEBAR_INFO)
|
| 230 |
gr.Markdown(HEADER_INFO)
|
| 231 |
-
|
| 232 |
-
|
| 233 |
-
|
| 234 |
-
|
| 235 |
-
|
| 236 |
-
|
| 237 |
-
|
| 238 |
-
gr.Markdown("""
|
| 239 |
-
**token-based**: similarity matrix edge weights representing token overlap/
|
| 240 |
-
ranked by their centrality in the graph (good with dense inter-sentence relationships)
|
| 241 |
-
""")
|
| 242 |
-
gr.Markdown("""
|
| 243 |
-
*Bjørn*: **gir sammendrag som fanger opp de mest relevante setninger i teksten**
|
| 244 |
-
""")
|
| 245 |
-
|
| 246 |
-
summarize_transcribed_button_graph = gr.Button("Summary of Transcribed Text, Click Here")
|
| 247 |
-
summarize_transcribed_button_graph.click(fn=lambda text: graph_based_summary(text), inputs=[text_output], outputs=[summary_output_graph])
|
| 248 |
-
summarize_uploaded_button_graph = gr.Button("Upload Text to Summarize, Click Here")
|
| 249 |
-
summarize_uploaded_button_graph.click(fn=graph_based_summary, inputs=[text_input_graph], outputs=[summary_output_graph])
|
| 250 |
-
|
| 251 |
-
with gr.TabItem("Summary | LexRank"):
|
| 252 |
-
text_input_lex = gr.Textbox(label="Input Text", placeholder="txt2summarize")
|
| 253 |
-
summary_output_lex = gr.Textbox(label="LexRank | cosine similarity")
|
| 254 |
-
|
| 255 |
-
gr.Markdown("""
|
| 256 |
-
**semantic**: TF-IDF vectorization@cosine similarity matrix, ranked by eigenvector centrality.
|
| 257 |
-
(good for sparse graph structures with thresholding)
|
| 258 |
-
""")
|
| 259 |
-
gr.Markdown("""
|
| 260 |
-
*Bjørn*: **gir sammendrag som best fanger opp betydningen av hele teksten**
|
| 261 |
-
""")
|
| 262 |
-
|
| 263 |
-
summarize_transcribed_button_lex = gr.Button("Summary of Transcribed Text, Click Here")
|
| 264 |
-
summarize_transcribed_button_lex.click(fn=lambda text: lex_rank_summary(text), inputs=[text_output], outputs=[summary_output_lex])
|
| 265 |
-
summarize_uploaded_button_lex = gr.Button("Upload Text to Summarize, Click Here")
|
| 266 |
-
summarize_uploaded_button_lex.click(fn=lex_rank_summary, inputs=[text_input_lex], outputs=[summary_output_lex])
|
| 267 |
-
|
| 268 |
-
with gr.TabItem("Summary | TextRank"):
|
| 269 |
-
text_input_text_rank = gr.Textbox(label="Input Text", placeholder="txt2summarize")
|
| 270 |
-
summary_output_text_rank = gr.Textbox(label="TextRank | lexical similarity")
|
| 271 |
-
|
| 272 |
-
gr.Markdown("""
|
| 273 |
-
**sentence**: graph with weighted edges based on lexical similarity. (i.e" "sentence similarity"word overlap)/sentence similarity
|
| 274 |
-
""")
|
| 275 |
-
gr.Markdown("""
|
| 276 |
-
*Bjørn*: **sammendrag basert på i de setningene som ligner mest på hverandre fra teksten**
|
| 277 |
-
|
| 278 |
-
""")
|
| 279 |
-
|
| 280 |
-
summarize_transcribed_button_text_rank = gr.Button("Summary of Transcribed Text, Click Here")
|
| 281 |
-
summarize_transcribed_button_text_rank.click(fn=lambda text: text_rank_summary(text), inputs=[text_output], outputs=[summary_output_text_rank])
|
| 282 |
-
summarize_uploaded_button_text_rank = gr.Button("Upload Text to Summarize, Click Here")
|
| 283 |
-
summarize_uploaded_button_text_rank.click(fn=text_rank_summary, inputs=[text_input_text_rank], outputs=[summary_output_text_rank])
|
| 284 |
-
|
| 285 |
-
with gr.TabItem("Download PDF"):
|
| 286 |
-
pdf_text_only = gr.Button("Download PDF with Text Only")
|
| 287 |
-
pdf_summary_only = gr.Button("Download PDF with Summary Only")
|
| 288 |
-
pdf_both = gr.Button("Download PDF with Both")
|
| 289 |
-
|
| 290 |
-
pdf_output = gr.File(label="Download PDF")
|
| 291 |
-
|
| 292 |
-
pdf_text_only.click(fn=lambda text: save_to_pdf(text, ""), inputs=[text_output], outputs=[pdf_output])
|
| 293 |
-
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
|
| 294 |
-
pdf_both.click(fn=lambda text, summary: save_to_pdf(text, summary), inputs=[text_output, summary_output_graph], outputs=[pdf_output]) # Defaulting to Graph-based summary
|
| 295 |
|
| 296 |
iface.launch(share=True, debug=True)
|
|
|
|
|
|
| 203 |
ranked_sentences = sorted(((scores[i], s) for i, s in enumerate(sentences)), reverse=True)
|
| 204 |
return ' '.join([ranked_sentences[i][1] for i in range(num_paragraphs)])
|
| 205 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 206 |
iface = gr.Blocks()
|
| 207 |
|
| 208 |
with iface:
|
|
|
|
| 209 |
gr.HTML(SIDEBAR_INFO)
|
| 210 |
gr.Markdown(HEADER_INFO)
|
| 211 |
+
|
| 212 |
+
audio_input = gr.Audio(label="Upload Audio File")
|
| 213 |
+
transcribed_text = gr.Textbox(label="Transcribed Text")
|
| 214 |
+
system_info = gr.Textbox(label="System Info")
|
| 215 |
+
|
| 216 |
+
transcribe_button = gr.Button("Transcribe")
|
| 217 |
+
transcribe_button.click(fn=transcribe_audio, inputs=audio_input, outputs=[transcribed_text, system_info])
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 218 |
|
| 219 |
iface.launch(share=True, debug=True)
|
| 220 |
+
|