Spaces:
Running
Running
Update app.py
Browse files
app.py
CHANGED
@@ -653,25 +653,19 @@ with gr.Blocks(theme='gradio/soft',js=js_func) as demo:
|
|
653 |
df['Positive_ratio'] = df['Positive'] / df['Total_paragraphs']*100
|
654 |
df['Negative_ratio'] = df['Negative'] / df['Total_paragraphs']*100
|
655 |
df['Neutral_ratio'] = df['Neutral'] / df['Total_paragraphs']*100
|
656 |
-
data_table = gr.DataFrame(value=df, label="Sentiment Data")
|
657 |
-
|
658 |
-
|
659 |
-
|
660 |
-
# Pivot the DataFrame
|
661 |
-
melted_df = df.melt(id_vars='Date', value_vars=['Positive_ratio', 'Negative_ratio', 'Neutral_ratio'],
|
662 |
var_name='Ratio_Type', value_name='Rate')
|
663 |
-
return df[['Date', 'Positive_ratio', 'Negative_ratio', 'Neutral_ratio', 'Total_paragraphs']], melted_df[['Date', 'Rate', 'Ratio_Type']]
|
664 |
# Line plot for the ratios
|
665 |
line_plot = gr.LinePlot(
|
|
|
666 |
x='Date',
|
667 |
y='Value',
|
668 |
title="Sentiment Ratios Over Time",
|
669 |
y_lim=[0, 1], # Limit y-axis to 0-1 since it's a ratio
|
670 |
color = 'Ratio_Type'
|
671 |
)
|
672 |
-
|
673 |
-
# Show table and plot
|
674 |
-
display_data_and_plot_btn = gr.Button("Display Data and Plot")
|
675 |
-
display_data_and_plot_btn.click(fn=display_data_and_plot, outputs=[data_table, line_plot])
|
676 |
|
677 |
demo.launch()
|
|
|
653 |
df['Positive_ratio'] = df['Positive'] / df['Total_paragraphs']*100
|
654 |
df['Negative_ratio'] = df['Negative'] / df['Total_paragraphs']*100
|
655 |
df['Neutral_ratio'] = df['Neutral'] / df['Total_paragraphs']*100
|
656 |
+
data_table = gr.DataFrame(value=df[['Date', 'Positive_ratio', 'Negative_ratio', 'Neutral_ratio', 'Total_paragraphs']], label="Sentiment Data")
|
657 |
+
df['Date'] = pd.to_datetime(df['Date']) # Ensure 'Date' is a datetime object
|
658 |
+
# Pivot the DataFrame
|
659 |
+
melted_df = df.melt(id_vars='Date', value_vars=['Positive_ratio', 'Negative_ratio', 'Neutral_ratio'],
|
|
|
|
|
660 |
var_name='Ratio_Type', value_name='Rate')
|
|
|
661 |
# Line plot for the ratios
|
662 |
line_plot = gr.LinePlot(
|
663 |
+
melted_df
|
664 |
x='Date',
|
665 |
y='Value',
|
666 |
title="Sentiment Ratios Over Time",
|
667 |
y_lim=[0, 1], # Limit y-axis to 0-1 since it's a ratio
|
668 |
color = 'Ratio_Type'
|
669 |
)
|
|
|
|
|
|
|
|
|
670 |
|
671 |
demo.launch()
|