Shriya07 commited on
Commit
8f658e6
·
verified ·
1 Parent(s): cc8c2ef
Files changed (1) hide show
  1. app.py +41 -0
app.py CHANGED
@@ -325,6 +325,47 @@ async function sendChat(){
325
 
326
  @app.route("/")
327
  def home(): return render_template_string(HTML)
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
328
 
329
  if __name__ == "__main__":
330
  app.run(host="0.0.0.0", port=7860)
 
325
 
326
  @app.route("/")
327
  def home(): return render_template_string(HTML)
328
+ # -----------------------------------------------------
329
+ # Download Endpoints (CSV export)
330
+ # -----------------------------------------------------
331
+ from flask import Response
332
+
333
+ def df_to_csv_response(dataframe, filename):
334
+ """Convert a DataFrame to downloadable CSV response."""
335
+ csv_data = dataframe.to_csv(index=False)
336
+ return Response(
337
+ csv_data,
338
+ mimetype="text/csv",
339
+ headers={"Content-Disposition": f"attachment;filename={filename}.csv"}
340
+ )
341
+
342
+ @app.route("/download/summary")
343
+ def download_summary():
344
+ bs = block_summary_df()
345
+ if bs.empty:
346
+ return jsonify({"error": "No data available"}), 404
347
+ return df_to_csv_response(bs, "block_summary")
348
+
349
+ @app.route("/download/focus")
350
+ def download_focus():
351
+ top2, _ = actionable_focus_df()
352
+ if top2.empty:
353
+ return jsonify({"error": "No data available"}), 404
354
+ return df_to_csv_response(top2, "actionable_focus")
355
+
356
+ @app.route("/download/multiple")
357
+ def download_multiple():
358
+ mb = multiple_block_df()
359
+ if mb.empty:
360
+ return jsonify({"error": "No data available"}), 404
361
+ return df_to_csv_response(mb, "multiple_blocks")
362
+
363
+ @app.route("/download/quarter")
364
+ def download_quarter():
365
+ qdf = quarter_trends_df()
366
+ if qdf.empty:
367
+ return jsonify({"error": "No data available"}), 404
368
+ return df_to_csv_response(qdf, "quarter_trends")
369
 
370
  if __name__ == "__main__":
371
  app.run(host="0.0.0.0", port=7860)