Spaces:
Sleeping
Sleeping
Rowan Martnishn
commited on
Update app.py
Browse files
app.py
CHANGED
@@ -14,6 +14,7 @@ import matplotlib.pyplot as plt
|
|
14 |
from scipy.interpolate import make_interp_spline
|
15 |
from transformers import AutoTokenizer
|
16 |
import matplotlib.font_manager as fm
|
|
|
17 |
|
18 |
# Load models and data (your existing code)
|
19 |
autovectorizer = joblib.load('AutoVectorizer.pkl')
|
@@ -173,8 +174,12 @@ def process_data():
|
|
173 |
ax.fill_between(xnew, pred_smooth, color='#244B48', alpha=0.4)
|
174 |
ax.plot(xnew, pred_smooth, color='#244B48', lw=3, label='Forecast')
|
175 |
ax.scatter(np.arange(7), pred, color='#244B48', s=100, zorder=5)
|
176 |
-
|
177 |
-
|
|
|
|
|
|
|
|
|
178 |
ax.set_xlabel("Day", fontsize=16, fontproperties=custom_font)
|
179 |
ax.set_ylabel("Negative Sentiment (0-1)", fontsize=16, fontproperties=custom_font)
|
180 |
ax.set_xticks(np.arange(7))
|
@@ -209,35 +214,7 @@ def display_plot():
|
|
209 |
return "Processing data..."
|
210 |
|
211 |
|
212 |
-
# process_data()
|
213 |
-
|
214 |
-
# # Schedule daily refresh
|
215 |
-
# def run_daily():
|
216 |
-
# process_data()
|
217 |
-
# print("Data refreshed at:", datetime.datetime.now())
|
218 |
-
|
219 |
-
# schedule.every().day.at("00:00").do(run_daily)
|
220 |
-
|
221 |
-
# def run_schedule():
|
222 |
-
# while True:
|
223 |
-
# schedule.run_pending()
|
224 |
-
# time.sleep(60)
|
225 |
-
|
226 |
-
# import threading
|
227 |
-
# thread = threading.Thread(target=run_schedule)
|
228 |
-
# thread.daemon = True
|
229 |
-
# thread.start()
|
230 |
|
231 |
-
# # Gradio Interface
|
232 |
-
# if prediction_plot_base64:
|
233 |
-
# html_content = f'<img src="data:image/png;base64,{prediction_plot_base64}" alt="Prediction Plot">'
|
234 |
-
# else:
|
235 |
-
# html_content = "Processing data..."
|
236 |
-
|
237 |
-
# iface = gr.Interface(fn=None, inputs=None, outputs=gr.HTML(value=html_content))
|
238 |
-
# iface.launch()
|
239 |
-
|
240 |
-
# Initial data processing
|
241 |
process_data()
|
242 |
|
243 |
# Schedule daily refresh
|
@@ -258,30 +235,7 @@ thread = threading.Thread(target=run_schedule)
|
|
258 |
thread.daemon = True
|
259 |
thread.start()
|
260 |
|
261 |
-
# # Gradio Interface
|
262 |
-
# if prediction_plot_base64:
|
263 |
-
# html_content = (
|
264 |
-
# f'<img src="data:image/png;base64,{prediction_plot_base64}" '
|
265 |
-
# 'alt="Prediction Plot" '
|
266 |
-
# 'style="width: 100vw; height: 100vh; object-fit: contain;">'
|
267 |
-
# )
|
268 |
-
# else:
|
269 |
-
# html_content = "Processing data..."
|
270 |
-
|
271 |
-
# custom_css = """
|
272 |
-
# body, .gradio-container {
|
273 |
-
# margin: 0;
|
274 |
-
# padding: 0;
|
275 |
-
# }
|
276 |
-
# """
|
277 |
-
|
278 |
-
# with gr.Blocks(css=custom_css) as demo:
|
279 |
-
# gr.HTML(value=html_content)
|
280 |
-
|
281 |
-
|
282 |
-
# print("Data refreshed at:", datetime.datetime.now())
|
283 |
|
284 |
-
# demo.launch()
|
285 |
|
286 |
|
287 |
custom_css = """
|
|
|
14 |
from scipy.interpolate import make_interp_spline
|
15 |
from transformers import AutoTokenizer
|
16 |
import matplotlib.font_manager as fm
|
17 |
+
import pytz
|
18 |
|
19 |
# Load models and data (your existing code)
|
20 |
autovectorizer = joblib.load('AutoVectorizer.pkl')
|
|
|
174 |
ax.fill_between(xnew, pred_smooth, color='#244B48', alpha=0.4)
|
175 |
ax.plot(xnew, pred_smooth, color='#244B48', lw=3, label='Forecast')
|
176 |
ax.scatter(np.arange(7), pred, color='#244B48', s=100, zorder=5)
|
177 |
+
|
178 |
+
est_timezone = pytz.timezone('America/New_York')
|
179 |
+
est_time = datetime.datetime.now(est_timezone)
|
180 |
+
ax.set_title(f"7-Day Political Sentiment Forecast - {est_time.strftime('%Y-%m-%d %H:%M:%S EST')}",
|
181 |
+
fontsize=22, fontweight='bold', pad=20, fontproperties=custom_font)
|
182 |
+
# ax.set_title(f"7-Day Political Sentiment Forecast - {datetime.datetime.now()}", fontsize=22, fontweight='bold', pad=20, fontproperties=custom_font)
|
183 |
ax.set_xlabel("Day", fontsize=16, fontproperties=custom_font)
|
184 |
ax.set_ylabel("Negative Sentiment (0-1)", fontsize=16, fontproperties=custom_font)
|
185 |
ax.set_xticks(np.arange(7))
|
|
|
214 |
return "Processing data..."
|
215 |
|
216 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
217 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
218 |
process_data()
|
219 |
|
220 |
# Schedule daily refresh
|
|
|
235 |
thread.daemon = True
|
236 |
thread.start()
|
237 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
238 |
|
|
|
239 |
|
240 |
|
241 |
custom_css = """
|