Cachoups commited on
Commit
ea79eb7
·
verified ·
1 Parent(s): c473846

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +15 -8
app.py CHANGED
@@ -649,23 +649,30 @@ with gr.Blocks(theme='gradio/soft',js=js_func) as demo:
649
  with gr.Tab("Fed data analysis"):
650
  gr.Markdown("## Sentiment Analysis Overview")
651
  # Display DataFrame
 
652
  df = pd.read_csv("data/2008_2024_minutes.csv", header = 0)
653
  df['Total_paragraphs']=df['Total_paragraphs']-df['Neutral']
654
  df['Positive_ratio'] = df['Positive'] / df['Total_paragraphs']*100
655
  df['Negative_ratio'] = df['Negative'] / df['Total_paragraphs']*100
 
 
 
 
 
 
656
  # data_table = gr.DataFrame(value=df[['Date', 'Positive_ratio', 'Negative_ratio', 'Total_paragraphs']], label="Sentiment Data", height=500)
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'],
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='Rate',
666
- title="Sentiment Ratios Over Time",
667
  y_lim=[0, 100], # Limit y-axis to 0-1 since it's a ratio
668
- color = 'Ratio_Type'
669
  )
670
-
 
671
  demo.launch()
 
649
  with gr.Tab("Fed data analysis"):
650
  gr.Markdown("## Sentiment Analysis Overview")
651
  # Display DataFrame
652
+ apply_btn = gr.Button("Apply", scale=0)
653
  df = pd.read_csv("data/2008_2024_minutes.csv", header = 0)
654
  df['Total_paragraphs']=df['Total_paragraphs']-df['Neutral']
655
  df['Positive_ratio'] = df['Positive'] / df['Total_paragraphs']*100
656
  df['Negative_ratio'] = df['Negative'] / df['Total_paragraphs']*100
657
+ df['Date'] = pd.to_datetime(df['Date'])
658
+ with gr.Row():
659
+ start = gr.DateTime(df['Date'].min(), label="Start")
660
+ end = gr.DateTime(df['Date'].max(), label="End")
661
+ apply_btn = gr.Button("Apply", scale=0)
662
+ reset_btn = gr.Button("Reset", scale=0)
663
  # data_table = gr.DataFrame(value=df[['Date', 'Positive_ratio', 'Negative_ratio', 'Total_paragraphs']], label="Sentiment Data", height=500)
 
664
  # Pivot the DataFrame
665
+ #melted_df = df.melt(id_vars='Date', value_vars=['Positive_ratio', 'Negative_ratio'],
666
+ # var_name='Ratio_Type', value_name='Rate')
667
  # Line plot for the ratios
668
  line_plot = gr.LinePlot(
669
+ df,
670
  x='Date',
671
+ y='Positive_ratio',
672
+ title="Positive Rate Over Time",
673
  y_lim=[0, 100], # Limit y-axis to 0-1 since it's a ratio
674
+ #color = 'Ratio_Type'
675
  )
676
+ apply_btn.click(lambda start,end: gr.LinePlot(x_lim=[start, end]), [start, end], line_plot)
677
+ reset_btn.click(lambda : gr.LinePlot(x_lim=[df['Date'].min(), df['Date'].max()]), [], line_plot)
678
  demo.launch()