Spaces:
Sleeping
Sleeping
Rowan Martnishn
commited on
Update app.py
Browse files
app.py
CHANGED
@@ -173,4 +173,56 @@ def process_data():
|
|
173 |
ax.set_xlabel("Day", fontsize=16, fontproperties=custom_font)
|
174 |
ax.set_ylabel("Negative Sentiment (0-1)", fontsize=16, fontproperties=custom_font)
|
175 |
ax.set_xticks(np.arange(7))
|
176 |
-
ax.set_xticklabels(days_str, fontsize=14, fontproperties=custom_font)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
173 |
ax.set_xlabel("Day", fontsize=16, fontproperties=custom_font)
|
174 |
ax.set_ylabel("Negative Sentiment (0-1)", fontsize=16, fontproperties=custom_font)
|
175 |
ax.set_xticks(np.arange(7))
|
176 |
+
ax.set_xticklabels(days_str, fontsize=14, fontproperties=custom_font)
|
177 |
+
|
178 |
+
# Continue from previous app.py code
|
179 |
+
|
180 |
+
ax.set_yticklabels([f"{tick:.2f}" for tick in ax.get_yticks()], fontsize=14, fontproperties=custom_font)
|
181 |
+
|
182 |
+
ax.spines['top'].set_visible(False)
|
183 |
+
ax.spines['right'].set_visible(False)
|
184 |
+
ax.spines['left'].set_visible(False)
|
185 |
+
ax.spines['bottom'].set_visible(False)
|
186 |
+
|
187 |
+
ax.legend(fontsize=14, loc='upper right', prop=custom_font)
|
188 |
+
plt.tight_layout()
|
189 |
+
|
190 |
+
import io
|
191 |
+
import base64
|
192 |
+
buffer = io.BytesIO()
|
193 |
+
plt.savefig(buffer, format='png')
|
194 |
+
buffer.seek(0)
|
195 |
+
prediction_plot_base64 = base64.b64encode(buffer.getvalue()).decode()
|
196 |
+
plt.close(fig)
|
197 |
+
|
198 |
+
def display_plot():
|
199 |
+
"""Displays the plot in the Gradio interface."""
|
200 |
+
global prediction_plot_base64
|
201 |
+
if prediction_plot_base64:
|
202 |
+
return f'<img src="data:image/png;base64,{prediction_plot_base64}" alt="Prediction Plot">'
|
203 |
+
else:
|
204 |
+
return "Processing data..."
|
205 |
+
|
206 |
+
# Initial data processing
|
207 |
+
process_data()
|
208 |
+
|
209 |
+
# Schedule daily refresh
|
210 |
+
def run_daily():
|
211 |
+
process_data()
|
212 |
+
print("Data refreshed at:", datetime.datetime.now())
|
213 |
+
|
214 |
+
schedule.every().day.at("00:00").do(run_daily)
|
215 |
+
|
216 |
+
def run_schedule():
|
217 |
+
while True:
|
218 |
+
schedule.run_pending()
|
219 |
+
time.sleep(60)
|
220 |
+
|
221 |
+
import threading
|
222 |
+
thread = threading.Thread(target=run_schedule)
|
223 |
+
thread.daemon = True
|
224 |
+
thread.start()
|
225 |
+
|
226 |
+
# Gradio Interface
|
227 |
+
iface = gr.Interface(fn=display_plot, inputs=None, outputs="html")
|
228 |
+
iface.launch()
|