Cachoups commited on
Commit
1d6377a
·
verified ·
1 Parent(s): 574e6c6

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +11 -7
app.py CHANGED
@@ -650,20 +650,24 @@ with gr.Blocks(theme='gradio/soft',js=js_func) as demo:
650
  gr.Markdown("## Sentiment Analysis Overview")
651
  # Display DataFrame
652
  df = pd.read_csv("data/2019_2024_minutes.csv", header = 0)
653
- df['Positive_ratio'] = df['Positive'] / df['Total_paragraphs']
654
- df['Negative_ratio'] = df['Negative'] / df['Total_paragraphs']
655
- df['Neutral_ratio'] = df['Neutral'] / df['Total_paragraphs']
656
  data_table = gr.DataFrame(value=df, label="Sentiment Data")
657
  def display_data_and_plot():
658
- return df, df[['Date', 'Positive_ratio', 'Negative_ratio', 'Neutral_ratio']]
 
 
 
 
 
659
  # Line plot for the ratios
660
  line_plot = gr.LinePlot(
661
- value=df[['Date', 'Positive_ratio', 'Negative_ratio', 'Neutral_ratio']],
662
  x='Date',
663
- y=['Positive_ratio', 'Negative_ratio', 'Neutral_ratio'],
664
  title="Sentiment Ratios Over Time",
665
  y_lim=[0, 1], # Limit y-axis to 0-1 since it's a ratio
666
- legend=["Positive Ratio", "Negative Ratio", "Neutral Ratio"]
667
  )
668
 
669
  # Show table and plot
 
650
  gr.Markdown("## Sentiment Analysis Overview")
651
  # Display DataFrame
652
  df = pd.read_csv("data/2019_2024_minutes.csv", header = 0)
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
  def display_data_and_plot():
658
+ global df
659
+ df['Date'] = pd.to_datetime(df['Date']) # Ensure 'Date' is a datetime object
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