Vera-ZWY commited on
Commit
6ce4a98
·
verified ·
1 Parent(s): 4ebe04e

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +18 -30
app.py CHANGED
@@ -5,7 +5,7 @@ import matplotlib.pyplot as plt
5
  import os
6
  import pandas as pd
7
  from io import StringIO
8
- from linePlot import plot_stacked_time_series, plot_emotion_topic_grid
9
 
10
  # Define your Hugging Face token (make sure to set it as an environment variable)
11
  HF_TOKEN = os.getenv("HF_TOKEN") # Replace with your actual token if not using an environment variable
@@ -80,21 +80,21 @@ def heatmap(top_n):
80
 
81
  return plt.gcf()
82
 
83
- def linePlot_time_series(viz_type, weight, top_n):
84
- result = client.predict(
85
- viz_type=viz_type,
86
- weight=weight,
87
- top_n=top_n,
88
- api_name="/linePlot_time_series"
89
- )
90
 
91
- print("============== timeseries df transfer from pivate to public ===============")
92
- print(result)
93
- print(type(result))
94
 
95
- df = pd.DataFrame(result['data'], columns=result['headers'])
96
- df.set_index('Index', inplace=True)
97
- return df
98
 
99
 
100
  # def update_visualization(viz_type, weight, top_n):
@@ -142,7 +142,9 @@ def linePlot_time_series(viz_type, weight, top_n):
142
 
143
  # except Exception as e:
144
  # return None, f"Error: {str(e)}"
145
-
 
 
146
  def decode_plot(plot_base64):
147
  plot_bytes = base64.b64decode(plot_base64['plot'].split(',')[1])
148
  img = plt.imread(BytesIO(plot_bytes), format='PNG')
@@ -153,7 +155,7 @@ def decode_plot(plot_base64):
153
 
154
 
155
  def linePlot(viz_type, weight, top_n):
156
- client = Client("mangoesai/Elections_Comparison_Agent_V4.1")
157
  result = client.predict(
158
  viz_type=viz_type,
159
  weight=weight,
@@ -165,8 +167,6 @@ def linePlot(viz_type, weight, top_n):
165
 
166
 
167
 
168
-
169
-
170
  # Create Gradio interface
171
  with gr.Blocks(title="Reddit Election Analysis") as demo:
172
  gr.Markdown("# Reddit Public sentiment & Social topic distribution ")
@@ -205,18 +205,6 @@ with gr.Blocks(title="Reddit Election Analysis") as demo:
205
  label="Top N Items"
206
  )
207
 
208
- # start_date_picker = gr.Date(
209
- # value=date_min.date(),
210
- # label="Start Date",
211
- # info=f"Available from: {date_min.strftime('%Y-%m-%d')}"
212
- # )
213
-
214
- # end_date_picker = gr.Date(
215
- # value=date_max.date(),
216
- # label="End Date",
217
- # info=f"Available until: {date_min.strftime('%Y-%m-%d')}"
218
- # )
219
-
220
 
221
  # with gr.Column():
222
  viz_dropdown = gr.Dropdown(
 
5
  import os
6
  import pandas as pd
7
  from io import StringIO
8
+ # from linePlot import plot_stacked_time_series, plot_emotion_topic_grid
9
 
10
  # Define your Hugging Face token (make sure to set it as an environment variable)
11
  HF_TOKEN = os.getenv("HF_TOKEN") # Replace with your actual token if not using an environment variable
 
80
 
81
  return plt.gcf()
82
 
83
+ # def linePlot_time_series(viz_type, weight, top_n):
84
+ # result = client.predict(
85
+ # viz_type=viz_type,
86
+ # weight=weight,
87
+ # top_n=top_n,
88
+ # api_name="/linePlot_time_series"
89
+ # )
90
 
91
+ # print("============== timeseries df transfer from pivate to public ===============")
92
+ # print(result)
93
+ # print(type(result))
94
 
95
+ # df = pd.DataFrame(result['data'], columns=result['headers'])
96
+ # df.set_index('Index', inplace=True)
97
+ # return df
98
 
99
 
100
  # def update_visualization(viz_type, weight, top_n):
 
142
 
143
  # except Exception as e:
144
  # return None, f"Error: {str(e)}"
145
+
146
+
147
+
148
  def decode_plot(plot_base64):
149
  plot_bytes = base64.b64decode(plot_base64['plot'].split(',')[1])
150
  img = plt.imread(BytesIO(plot_bytes), format='PNG')
 
155
 
156
 
157
  def linePlot(viz_type, weight, top_n):
158
+ # client = Client("mangoesai/Elections_Comparison_Agent_V4.1")
159
  result = client.predict(
160
  viz_type=viz_type,
161
  weight=weight,
 
167
 
168
 
169
 
 
 
170
  # Create Gradio interface
171
  with gr.Blocks(title="Reddit Election Analysis") as demo:
172
  gr.Markdown("# Reddit Public sentiment & Social topic distribution ")
 
205
  label="Top N Items"
206
  )
207
 
 
 
 
 
 
 
 
 
 
 
 
 
208
 
209
  # with gr.Column():
210
  viz_dropdown = gr.Dropdown(