Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
|
@@ -80,9 +80,9 @@ def process_paragraph_1_sent(paragraph):
|
|
| 80 |
try:
|
| 81 |
paragraph_index = int(paragraph.split(':')[0].replace('Paragraph ', '')) - 1
|
| 82 |
selected_paragraph = stored_paragraphs_1[paragraph_index]
|
| 83 |
-
|
| 84 |
-
|
| 85 |
-
return
|
| 86 |
except (IndexError, ValueError):
|
| 87 |
return "Error"
|
| 88 |
def process_paragraph_1_sent_tone(paragraph):
|
|
@@ -113,9 +113,9 @@ def process_paragraph_2_sent(paragraph):
|
|
| 113 |
try:
|
| 114 |
paragraph_index = int(paragraph.split(':')[0].replace('Paragraph ', '')) - 1
|
| 115 |
selected_paragraph = stored_paragraphs_2[paragraph_index]
|
| 116 |
-
|
| 117 |
-
|
| 118 |
-
return
|
| 119 |
except (IndexError, ValueError):
|
| 120 |
return "Error"
|
| 121 |
def process_paragraph_2_sent_tone(paragraph):
|
|
@@ -448,29 +448,30 @@ with gr.Blocks(theme='gradio/soft',js=js_func) as demo:
|
|
| 448 |
|
| 449 |
selected_paragraph_1 = gr.Textbox(label="Selected Paragraph 1 Content", lines=4)
|
| 450 |
paragraph_1_dropdown.select(fn=show1, inputs = paragraph_1_dropdown, outputs=selected_paragraph_1)
|
| 451 |
-
|
| 452 |
-
|
| 453 |
-
|
| 454 |
-
|
| 455 |
-
|
| 456 |
-
|
| 457 |
-
|
| 458 |
-
|
| 459 |
-
|
| 460 |
-
|
| 461 |
-
|
| 462 |
-
|
| 463 |
-
|
| 464 |
-
|
| 465 |
-
|
| 466 |
-
|
| 467 |
-
|
| 468 |
-
|
| 469 |
-
|
| 470 |
-
|
| 471 |
-
|
| 472 |
-
|
| 473 |
-
|
|
|
|
| 474 |
|
| 475 |
# Process the selected paragraph from PDF 2
|
| 476 |
with gr.Column():
|
|
@@ -478,32 +479,33 @@ with gr.Blocks(theme='gradio/soft',js=js_func) as demo:
|
|
| 478 |
|
| 479 |
selected_paragraph_2 = gr.Textbox(label="Selected Paragraph 2 Content", lines=4)
|
| 480 |
paragraph_2_dropdown.select(fn=show2, inputs = paragraph_2_dropdown, outputs=selected_paragraph_2)
|
| 481 |
-
|
| 482 |
-
|
| 483 |
-
|
| 484 |
-
|
| 485 |
-
|
| 486 |
-
|
| 487 |
-
|
| 488 |
-
|
| 489 |
-
|
| 490 |
-
|
| 491 |
-
|
| 492 |
-
|
| 493 |
-
|
| 494 |
-
|
| 495 |
-
|
| 496 |
-
|
| 497 |
-
|
| 498 |
-
|
| 499 |
-
|
| 500 |
-
|
| 501 |
-
|
| 502 |
-
|
| 503 |
-
|
| 504 |
-
|
| 505 |
-
|
| 506 |
-
|
|
|
|
| 507 |
|
| 508 |
|
| 509 |
with gr.Tab("Financial Report Table Analysis"):
|
|
|
|
| 80 |
try:
|
| 81 |
paragraph_index = int(paragraph.split(':')[0].replace('Paragraph ', '')) - 1
|
| 82 |
selected_paragraph = stored_paragraphs_1[paragraph_index]
|
| 83 |
+
result = text_to_sentiment(selected_paragraph)
|
| 84 |
+
formatted_results = "\n".join([f"{result['label']}: {result['score']:.2f}" for result in results])
|
| 85 |
+
return formatted_results
|
| 86 |
except (IndexError, ValueError):
|
| 87 |
return "Error"
|
| 88 |
def process_paragraph_1_sent_tone(paragraph):
|
|
|
|
| 113 |
try:
|
| 114 |
paragraph_index = int(paragraph.split(':')[0].replace('Paragraph ', '')) - 1
|
| 115 |
selected_paragraph = stored_paragraphs_2[paragraph_index]
|
| 116 |
+
result = text_to_sentiment(selected_paragraph)
|
| 117 |
+
formatted_results = "\n".join([f"{result['label']}: {result['score']:.2f}" for result in results])
|
| 118 |
+
return formatted_results
|
| 119 |
except (IndexError, ValueError):
|
| 120 |
return "Error"
|
| 121 |
def process_paragraph_2_sent_tone(paragraph):
|
|
|
|
| 448 |
|
| 449 |
selected_paragraph_1 = gr.Textbox(label="Selected Paragraph 1 Content", lines=4)
|
| 450 |
paragraph_1_dropdown.select(fn=show1, inputs = paragraph_1_dropdown, outputs=selected_paragraph_1)
|
| 451 |
+
with gr.Group():
|
| 452 |
+
summarize_btn1 = gr.Button("Summarize Text from PDF 1")
|
| 453 |
+
summary_textbox_1 = gr.Textbox(label="Summary for PDF 1", lines=2)
|
| 454 |
+
|
| 455 |
+
# Summarize the selected paragraph from PDF 1
|
| 456 |
+
summarize_btn1.click(fn=lambda p: process_paragraph_1_sum(p), inputs=paragraph_1_dropdown, outputs=summary_textbox_1)
|
| 457 |
+
|
| 458 |
+
sentiment_btn1 = gr.Button("Classify Financial Tone from PDF 1")
|
| 459 |
+
sentiment_textbox_1 = gr.Label(label="Classification for PDF 1", lines=1)
|
| 460 |
+
|
| 461 |
+
# Classify the financial tone of the selected paragraph from PDF 1
|
| 462 |
+
sentiment_btn1.click(fn=lambda p: process_paragraph_1_sent(p), inputs=paragraph_1_dropdown, outputs=sentiment_textbox_1)
|
| 463 |
+
|
| 464 |
+
analyze_btn1 = gr.Button("Analyze Financial Tone on each sentence with FinBERT-tone")
|
| 465 |
+
fin_spans_1 = gr.HighlightedText(label="Financial Tone Analysis for PDF 1")
|
| 466 |
+
|
| 467 |
+
# Analyze financial tone on each sentence using FinBERT-tone
|
| 468 |
+
analyze_btn1.click(fn=lambda p: process_paragraph_1_sent_tone(p), inputs=paragraph_1_dropdown, outputs=fin_spans_1)
|
| 469 |
+
|
| 470 |
+
analyze_btn1_ = gr.Button("Analyze Financial Tone on each sentence with ProsusAI/finbert")
|
| 471 |
+
fin_spans_1_ = gr.HighlightedText(label="Financial Tone Analysis for PDF 1 (Bis)")
|
| 472 |
+
|
| 473 |
+
# Analyze financial tone using ProsusAI/finbert
|
| 474 |
+
analyze_btn1_.click(fn=lambda p: process_paragraph_1_sent_tone_bis(p), inputs=paragraph_1_dropdown, outputs=fin_spans_1_)
|
| 475 |
|
| 476 |
# Process the selected paragraph from PDF 2
|
| 477 |
with gr.Column():
|
|
|
|
| 479 |
|
| 480 |
selected_paragraph_2 = gr.Textbox(label="Selected Paragraph 2 Content", lines=4)
|
| 481 |
paragraph_2_dropdown.select(fn=show2, inputs = paragraph_2_dropdown, outputs=selected_paragraph_2)
|
| 482 |
+
with gr.Group():
|
| 483 |
+
# Display selected paragraph from PDF 2
|
| 484 |
+
selected_paragraph_2.change(fn=show2, inputs=paragraph_2_dropdown, outputs=selected_paragraph_2)
|
| 485 |
+
|
| 486 |
+
summarize_btn2 = gr.Button("Summarize Text from PDF 2")
|
| 487 |
+
summary_textbox_2 = gr.Textbox(label="Summary for PDF 2", lines=2)
|
| 488 |
+
|
| 489 |
+
# Summarize the selected paragraph from PDF 2
|
| 490 |
+
summarize_btn2.click(fn=lambda p: process_paragraph_2_sum(p), inputs=paragraph_2_dropdown, outputs=summary_textbox_2)
|
| 491 |
+
|
| 492 |
+
sentiment_btn2 = gr.Button("Classify Financial Tone from PDF 2")
|
| 493 |
+
sentiment_textbox_2 = gr.Textbox(label="Classification for PDF 2", lines=1)
|
| 494 |
+
|
| 495 |
+
# Classify the financial tone of the selected paragraph from PDF 2
|
| 496 |
+
sentiment_btn2.click(fn=lambda p: process_paragraph_2_sent(p), inputs=paragraph_2_dropdown, outputs=sentiment_textbox_2)
|
| 497 |
+
|
| 498 |
+
analyze_btn2 = gr.Button("Analyze Financial Tone on each sentence with FinBERT-tone")
|
| 499 |
+
fin_spans_2 = gr.HighlightedText(label="Financial Tone Analysis for PDF 2")
|
| 500 |
+
|
| 501 |
+
# Analyze financial tone on each sentence using FinBERT-tone for PDF 2
|
| 502 |
+
analyze_btn2.click(fn=lambda p: process_paragraph_2_sent_tone(p), inputs=paragraph_2_dropdown, outputs=fin_spans_2)
|
| 503 |
+
|
| 504 |
+
analyze_btn2_ = gr.Button("Analyze Financial Tone on each sentence with ProsusAI/finbert")
|
| 505 |
+
fin_spans_2_ = gr.HighlightedText(label="Financial Tone Analysis for PDF 2 (Bis)")
|
| 506 |
+
|
| 507 |
+
# Analyze financial tone using ProsusAI/finbert for PDF 2
|
| 508 |
+
analyze_btn2_.click(fn=lambda p: process_paragraph_2_sent_tone_bis(p), inputs=paragraph_2_dropdown, outputs=fin_spans_2_)
|
| 509 |
|
| 510 |
|
| 511 |
with gr.Tab("Financial Report Table Analysis"):
|