Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
@@ -325,62 +325,93 @@ with gr.Blocks() as demo:
|
|
325 |
- For a selected country and topic, describe the adverse growth rate trend over three years using the [**google/flan-t5-base**](https://huggingface.co/google/flan-t5-base).
|
326 |
""")
|
327 |
with gr.Tab("Financial Report Text Analysis"):
|
328 |
-
gr.Markdown("## Financial Report Paragraph Selection and Analysis on
|
329 |
|
330 |
with gr.Row():
|
331 |
# Upload PDFs
|
332 |
with gr.Column():
|
|
|
333 |
pdf1 = gr.Dropdown(choices=get_pdf_files(PDF_FOLDER), label="Select PDF 1")
|
334 |
pdf2 = gr.Dropdown(choices=get_pdf_files(PDF_FOLDER), label="Select PDF 2")
|
335 |
-
|
336 |
with gr.Column():
|
|
|
337 |
b1 = gr.Button("Extract and Display Paragraphs")
|
338 |
paragraph_1_dropdown = gr.Dropdown(label="Select Paragraph from PDF 1")
|
339 |
paragraph_2_dropdown = gr.Dropdown(label="Select Paragraph from PDF 2")
|
340 |
-
|
|
|
341 |
def update_paragraphs(pdf1, pdf2):
|
342 |
global stored_paragraphs_1, stored_paragraphs_2
|
343 |
stored_paragraphs_1, stored_paragraphs_2 = extract_and_paragraph(pdf1, pdf2, True)
|
344 |
updated_dropdown_1 = [f"Paragraph {i+1}: {p[:100]}..." for i, p in enumerate(stored_paragraphs_1)]
|
345 |
updated_dropdown_2 = [f"Paragraph {i+1}: {p[:100]}..." for i, p in enumerate(stored_paragraphs_2)]
|
346 |
return gr.update(choices=updated_dropdown_1), gr.update(choices=updated_dropdown_2)
|
347 |
-
|
348 |
b1.click(fn=update_paragraphs, inputs=[pdf1, pdf2], outputs=[paragraph_1_dropdown, paragraph_2_dropdown])
|
349 |
-
|
350 |
with gr.Row():
|
351 |
# Process the selected paragraph from PDF 1
|
352 |
with gr.Column():
|
353 |
gr.Markdown("### PDF 1 Analysis")
|
|
|
354 |
selected_paragraph_1 = gr.Textbox(label="Selected Paragraph 1 Content", lines=4)
|
|
|
355 |
summarize_btn1 = gr.Button("Summarize Text from PDF 1")
|
356 |
summary_textbox_1 = gr.Textbox(label="Summary for PDF 1", lines=2)
|
|
|
|
|
357 |
summarize_btn1.click(fn=lambda p: process_paragraph_1_sum(p), inputs=paragraph_1_dropdown, outputs=summary_textbox_1)
|
|
|
358 |
sentiment_btn1 = gr.Button("Classify Financial Tone from PDF 1")
|
359 |
sentiment_textbox_1 = gr.Textbox(label="Classification for PDF 1", lines=1)
|
|
|
|
|
360 |
sentiment_btn1.click(fn=lambda p: process_paragraph_1_sent(p), inputs=paragraph_1_dropdown, outputs=sentiment_textbox_1)
|
361 |
-
|
|
|
362 |
fin_spans_1 = gr.HighlightedText(label="Financial Tone Analysis for PDF 1")
|
|
|
|
|
363 |
analyze_btn1.click(fn=lambda p: process_paragraph_1_sent_tone(p), inputs=paragraph_1_dropdown, outputs=fin_spans_1)
|
|
|
364 |
analyze_btn1_ = gr.Button("Analyze Financial Tone on each sentence with ProsusAI/finbert")
|
365 |
-
fin_spans_1_ = gr.HighlightedText(label="Financial Tone Analysis for PDF 1
|
|
|
|
|
366 |
analyze_btn1_.click(fn=lambda p: process_paragraph_1_sent_tone_bis(p), inputs=paragraph_1_dropdown, outputs=fin_spans_1_)
|
367 |
-
|
368 |
# Process the selected paragraph from PDF 2
|
369 |
with gr.Column():
|
370 |
gr.Markdown("### PDF 2 Analysis")
|
|
|
371 |
selected_paragraph_2 = gr.Textbox(label="Selected Paragraph 2 Content", lines=4)
|
372 |
-
|
|
|
|
|
|
|
373 |
summarize_btn2 = gr.Button("Summarize Text from PDF 2")
|
374 |
summary_textbox_2 = gr.Textbox(label="Summary for PDF 2", lines=2)
|
|
|
|
|
375 |
summarize_btn2.click(fn=lambda p: process_paragraph_2_sum(p), inputs=paragraph_2_dropdown, outputs=summary_textbox_2)
|
|
|
376 |
sentiment_btn2 = gr.Button("Classify Financial Tone from PDF 2")
|
377 |
sentiment_textbox_2 = gr.Textbox(label="Classification for PDF 2", lines=1)
|
|
|
|
|
378 |
sentiment_btn2.click(fn=lambda p: process_paragraph_2_sent(p), inputs=paragraph_2_dropdown, outputs=sentiment_textbox_2)
|
379 |
-
|
|
|
380 |
fin_spans_2 = gr.HighlightedText(label="Financial Tone Analysis for PDF 2")
|
|
|
|
|
381 |
analyze_btn2.click(fn=lambda p: process_paragraph_2_sent_tone(p), inputs=paragraph_2_dropdown, outputs=fin_spans_2)
|
|
|
382 |
analyze_btn2_ = gr.Button("Analyze Financial Tone on each sentence with ProsusAI/finbert")
|
383 |
-
fin_spans_2_ = gr.HighlightedText(label="Financial Tone Analysis for PDF 2
|
|
|
|
|
384 |
analyze_btn2_.click(fn=lambda p: process_paragraph_2_sent_tone_bis(p), inputs=paragraph_2_dropdown, outputs=fin_spans_2_)
|
385 |
|
386 |
with gr.Tab("Financial Report Table Analysis"):
|
|
|
325 |
- For a selected country and topic, describe the adverse growth rate trend over three years using the [**google/flan-t5-base**](https://huggingface.co/google/flan-t5-base).
|
326 |
""")
|
327 |
with gr.Tab("Financial Report Text Analysis"):
|
328 |
+
gr.Markdown("## Financial Report Paragraph Selection and Analysis on Adverse Macro-Economy Scenario")
|
329 |
|
330 |
with gr.Row():
|
331 |
# Upload PDFs
|
332 |
with gr.Column():
|
333 |
+
gr.Markdown("### Step 1: Upload PDF Files")
|
334 |
pdf1 = gr.Dropdown(choices=get_pdf_files(PDF_FOLDER), label="Select PDF 1")
|
335 |
pdf2 = gr.Dropdown(choices=get_pdf_files(PDF_FOLDER), label="Select PDF 2")
|
336 |
+
|
337 |
with gr.Column():
|
338 |
+
gr.Markdown("### Step 2: Extract and Display Paragraphs")
|
339 |
b1 = gr.Button("Extract and Display Paragraphs")
|
340 |
paragraph_1_dropdown = gr.Dropdown(label="Select Paragraph from PDF 1")
|
341 |
paragraph_2_dropdown = gr.Dropdown(label="Select Paragraph from PDF 2")
|
342 |
+
|
343 |
+
# Extract paragraphs from PDFs and update dropdowns
|
344 |
def update_paragraphs(pdf1, pdf2):
|
345 |
global stored_paragraphs_1, stored_paragraphs_2
|
346 |
stored_paragraphs_1, stored_paragraphs_2 = extract_and_paragraph(pdf1, pdf2, True)
|
347 |
updated_dropdown_1 = [f"Paragraph {i+1}: {p[:100]}..." for i, p in enumerate(stored_paragraphs_1)]
|
348 |
updated_dropdown_2 = [f"Paragraph {i+1}: {p[:100]}..." for i, p in enumerate(stored_paragraphs_2)]
|
349 |
return gr.update(choices=updated_dropdown_1), gr.update(choices=updated_dropdown_2)
|
350 |
+
|
351 |
b1.click(fn=update_paragraphs, inputs=[pdf1, pdf2], outputs=[paragraph_1_dropdown, paragraph_2_dropdown])
|
352 |
+
|
353 |
with gr.Row():
|
354 |
# Process the selected paragraph from PDF 1
|
355 |
with gr.Column():
|
356 |
gr.Markdown("### PDF 1 Analysis")
|
357 |
+
|
358 |
selected_paragraph_1 = gr.Textbox(label="Selected Paragraph 1 Content", lines=4)
|
359 |
+
|
360 |
summarize_btn1 = gr.Button("Summarize Text from PDF 1")
|
361 |
summary_textbox_1 = gr.Textbox(label="Summary for PDF 1", lines=2)
|
362 |
+
|
363 |
+
# Summarize the selected paragraph from PDF 1
|
364 |
summarize_btn1.click(fn=lambda p: process_paragraph_1_sum(p), inputs=paragraph_1_dropdown, outputs=summary_textbox_1)
|
365 |
+
|
366 |
sentiment_btn1 = gr.Button("Classify Financial Tone from PDF 1")
|
367 |
sentiment_textbox_1 = gr.Textbox(label="Classification for PDF 1", lines=1)
|
368 |
+
|
369 |
+
# Classify the financial tone of the selected paragraph from PDF 1
|
370 |
sentiment_btn1.click(fn=lambda p: process_paragraph_1_sent(p), inputs=paragraph_1_dropdown, outputs=sentiment_textbox_1)
|
371 |
+
|
372 |
+
analyze_btn1 = gr.Button("Analyze Financial Tone on each sentence with FinBERT-tone")
|
373 |
fin_spans_1 = gr.HighlightedText(label="Financial Tone Analysis for PDF 1")
|
374 |
+
|
375 |
+
# Analyze financial tone on each sentence using FinBERT-tone
|
376 |
analyze_btn1.click(fn=lambda p: process_paragraph_1_sent_tone(p), inputs=paragraph_1_dropdown, outputs=fin_spans_1)
|
377 |
+
|
378 |
analyze_btn1_ = gr.Button("Analyze Financial Tone on each sentence with ProsusAI/finbert")
|
379 |
+
fin_spans_1_ = gr.HighlightedText(label="Financial Tone Analysis for PDF 1 (Bis)")
|
380 |
+
|
381 |
+
# Analyze financial tone using ProsusAI/finbert
|
382 |
analyze_btn1_.click(fn=lambda p: process_paragraph_1_sent_tone_bis(p), inputs=paragraph_1_dropdown, outputs=fin_spans_1_)
|
383 |
+
|
384 |
# Process the selected paragraph from PDF 2
|
385 |
with gr.Column():
|
386 |
gr.Markdown("### PDF 2 Analysis")
|
387 |
+
|
388 |
selected_paragraph_2 = gr.Textbox(label="Selected Paragraph 2 Content", lines=4)
|
389 |
+
|
390 |
+
# Display selected paragraph from PDF 2
|
391 |
+
selected_paragraph_2.change(fn=show, inputs=paragraph_2_dropdown, outputs=selected_paragraph_2)
|
392 |
+
|
393 |
summarize_btn2 = gr.Button("Summarize Text from PDF 2")
|
394 |
summary_textbox_2 = gr.Textbox(label="Summary for PDF 2", lines=2)
|
395 |
+
|
396 |
+
# Summarize the selected paragraph from PDF 2
|
397 |
summarize_btn2.click(fn=lambda p: process_paragraph_2_sum(p), inputs=paragraph_2_dropdown, outputs=summary_textbox_2)
|
398 |
+
|
399 |
sentiment_btn2 = gr.Button("Classify Financial Tone from PDF 2")
|
400 |
sentiment_textbox_2 = gr.Textbox(label="Classification for PDF 2", lines=1)
|
401 |
+
|
402 |
+
# Classify the financial tone of the selected paragraph from PDF 2
|
403 |
sentiment_btn2.click(fn=lambda p: process_paragraph_2_sent(p), inputs=paragraph_2_dropdown, outputs=sentiment_textbox_2)
|
404 |
+
|
405 |
+
analyze_btn2 = gr.Button("Analyze Financial Tone on each sentence with FinBERT-tone")
|
406 |
fin_spans_2 = gr.HighlightedText(label="Financial Tone Analysis for PDF 2")
|
407 |
+
|
408 |
+
# Analyze financial tone on each sentence using FinBERT-tone for PDF 2
|
409 |
analyze_btn2.click(fn=lambda p: process_paragraph_2_sent_tone(p), inputs=paragraph_2_dropdown, outputs=fin_spans_2)
|
410 |
+
|
411 |
analyze_btn2_ = gr.Button("Analyze Financial Tone on each sentence with ProsusAI/finbert")
|
412 |
+
fin_spans_2_ = gr.HighlightedText(label="Financial Tone Analysis for PDF 2 (Bis)")
|
413 |
+
|
414 |
+
# Analyze financial tone using ProsusAI/finbert for PDF 2
|
415 |
analyze_btn2_.click(fn=lambda p: process_paragraph_2_sent_tone_bis(p), inputs=paragraph_2_dropdown, outputs=fin_spans_2_)
|
416 |
|
417 |
with gr.Tab("Financial Report Table Analysis"):
|