Update app.py
Browse files
app.py
CHANGED
|
@@ -332,7 +332,7 @@ def comment_length_vs_sentiment(comment_results):
|
|
| 332 |
# =========================
|
| 333 |
# Dash App
|
| 334 |
# =========================
|
| 335 |
-
app = Dash(__name__)
|
| 336 |
|
| 337 |
app.layout = html.Div([
|
| 338 |
html.H1("Content Analysis Dashboard", style={
|
|
@@ -393,10 +393,10 @@ app.layout = html.Div([
|
|
| 393 |
State("input-link", "value"),
|
| 394 |
State("link-type", "value")
|
| 395 |
)
|
|
|
|
| 396 |
def process_link(n_clicks, link, link_type):
|
| 397 |
if n_clicks == 0 or not link:
|
| 398 |
return html.P("Please enter a link and click Process.")
|
| 399 |
-
paragraph_sentiments = paragraph_sentiment_analysis(link)
|
| 400 |
|
| 401 |
# ================= NEWS =================
|
| 402 |
if link_type == "news":
|
|
@@ -440,66 +440,30 @@ def process_link(n_clicks, link, link_type):
|
|
| 440 |
}
|
| 441 |
),
|
| 442 |
|
| 443 |
-
|
| 444 |
-
|
| 445 |
-
|
| 446 |
-
|
| 447 |
-
|
| 448 |
-
|
| 449 |
-
|
| 450 |
-
|
| 451 |
-
|
| 452 |
-
|
| 453 |
-
|
| 454 |
-
|
| 455 |
-
|
| 456 |
-
|
| 457 |
-
'whiteSpace': 'pre-wrap'
|
| 458 |
-
}),
|
| 459 |
-
|
| 460 |
-
html.P(
|
| 461 |
-
f"Sentiment: {ps['label']} | Confidence: {ps['score']}%",
|
| 462 |
-
style={
|
| 463 |
-
'color': 'green' if ps['label'].lower() == 'positive'
|
| 464 |
-
else 'red' if ps['label'].lower() == 'negative'
|
| 465 |
-
else 'orange',
|
| 466 |
-
'fontWeight': 'bold'
|
| 467 |
-
}
|
| 468 |
-
),
|
| 469 |
-
|
| 470 |
-
html.Hr()
|
| 471 |
-
], style={
|
| 472 |
-
'padding': '10px',
|
| 473 |
-
'border': '1px solid #ddd',
|
| 474 |
-
'marginBottom': '10px',
|
| 475 |
-
'backgroundColor': "#AC8BF80F"
|
| 476 |
-
})
|
| 477 |
-
|
| 478 |
-
for i, ps in enumerate(paragraph_sentiments)
|
| 479 |
-
]),
|
| 480 |
-
html.Hr(),
|
| 481 |
|
| 482 |
-
html.
|
| 483 |
|
| 484 |
-
dcc.Graph(
|
| 485 |
-
figure=paragraph_sentiment_lineplot(paragraph_sentiments)
|
| 486 |
-
),
|
| 487 |
html.Hr(),
|
| 488 |
|
| 489 |
dcc.Graph(figure=top_words_figure(text)),
|
| 490 |
|
| 491 |
html.H4("Sentiment Analysis"),
|
| 492 |
dcc.Graph(figure=fig_sent),
|
| 493 |
-
html.P(
|
| 494 |
-
confidence,
|
| 495 |
-
style={
|
| 496 |
-
'fontSize': '16px',
|
| 497 |
-
'fontWeight': 'bold',
|
| 498 |
-
'color': 'green'
|
| 499 |
-
}
|
| 500 |
-
),
|
| 501 |
-
|
| 502 |
-
|
| 503 |
])
|
| 504 |
|
| 505 |
# ================= FACEBOOK =================
|
|
@@ -553,6 +517,46 @@ def process_link(n_clicks, link, link_type):
|
|
| 553 |
html.H3("π Comment Length vs Sentiment"),
|
| 554 |
dcc.Graph(figure=fig_scatter)
|
| 555 |
])
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 556 |
|
| 557 |
|
| 558 |
|
|
|
|
| 332 |
# =========================
|
| 333 |
# Dash App
|
| 334 |
# =========================
|
| 335 |
+
app = Dash(__name__, suppress_callback_exceptions=True)
|
| 336 |
|
| 337 |
app.layout = html.Div([
|
| 338 |
html.H1("Content Analysis Dashboard", style={
|
|
|
|
| 393 |
State("input-link", "value"),
|
| 394 |
State("link-type", "value")
|
| 395 |
)
|
| 396 |
+
|
| 397 |
def process_link(n_clicks, link, link_type):
|
| 398 |
if n_clicks == 0 or not link:
|
| 399 |
return html.P("Please enter a link and click Process.")
|
|
|
|
| 400 |
|
| 401 |
# ================= NEWS =================
|
| 402 |
if link_type == "news":
|
|
|
|
| 440 |
}
|
| 441 |
),
|
| 442 |
|
| 443 |
+
html.Button(
|
| 444 |
+
"π Show Paragraph-wise Analysis",
|
| 445 |
+
id="para-btn",
|
| 446 |
+
n_clicks=0,
|
| 447 |
+
style={
|
| 448 |
+
'backgroundColor': '#6a0dad',
|
| 449 |
+
'color': '#ffffff',
|
| 450 |
+
'border': 'none',
|
| 451 |
+
'padding': '10px 15px',
|
| 452 |
+
'borderRadius': '5px',
|
| 453 |
+
'cursor': 'pointer',
|
| 454 |
+
'marginBottom': '20px'
|
| 455 |
+
}
|
| 456 |
+
),
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 457 |
|
| 458 |
+
html.Div(id="paragraph-analysis-container"),
|
| 459 |
|
|
|
|
|
|
|
|
|
|
| 460 |
html.Hr(),
|
| 461 |
|
| 462 |
dcc.Graph(figure=top_words_figure(text)),
|
| 463 |
|
| 464 |
html.H4("Sentiment Analysis"),
|
| 465 |
dcc.Graph(figure=fig_sent),
|
| 466 |
+
html.P(confidence, style={'fontWeight': 'bold', 'color': 'green'})
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 467 |
])
|
| 468 |
|
| 469 |
# ================= FACEBOOK =================
|
|
|
|
| 517 |
html.H3("π Comment Length vs Sentiment"),
|
| 518 |
dcc.Graph(figure=fig_scatter)
|
| 519 |
])
|
| 520 |
+
@app.callback(
|
| 521 |
+
Output("paragraph-analysis-container", "children"),
|
| 522 |
+
Input("para-btn", "n_clicks"),
|
| 523 |
+
State("input-link", "value"),
|
| 524 |
+
prevent_initial_call=True
|
| 525 |
+
)
|
| 526 |
+
def load_paragraph_analysis(n_clicks, link):
|
| 527 |
+
if not link:
|
| 528 |
+
return html.P("No link provided.")
|
| 529 |
+
|
| 530 |
+
paragraph_sentiments = paragraph_sentiment_analysis(link)
|
| 531 |
+
|
| 532 |
+
if not paragraph_sentiments:
|
| 533 |
+
return html.P("No paragraph sentiment data found.")
|
| 534 |
+
|
| 535 |
+
return html.Div([
|
| 536 |
+
html.H3("π Paragraph-wise Sentiment Analysis"),
|
| 537 |
+
|
| 538 |
+
html.Div([
|
| 539 |
+
html.Div([
|
| 540 |
+
html.P(f"π§Ύ Paragraph {i+1}", style={'fontWeight': 'bold'}),
|
| 541 |
+
html.P(ps["text"]),
|
| 542 |
+
html.P(
|
| 543 |
+
f"Sentiment: {ps['label']} | {ps['score']}%",
|
| 544 |
+
style={'fontWeight': 'bold'}
|
| 545 |
+
),
|
| 546 |
+
html.Hr()
|
| 547 |
+
], style={
|
| 548 |
+
'padding': '10px',
|
| 549 |
+
'border': '1px solid #ddd',
|
| 550 |
+
'marginBottom': '10px'
|
| 551 |
+
})
|
| 552 |
+
for i, ps in enumerate(paragraph_sentiments)
|
| 553 |
+
]),
|
| 554 |
+
|
| 555 |
+
dcc.Graph(
|
| 556 |
+
figure=paragraph_sentiment_lineplot(paragraph_sentiments)
|
| 557 |
+
)
|
| 558 |
+
])
|
| 559 |
+
|
| 560 |
|
| 561 |
|
| 562 |
|