import json, os from flask import Flask, render_template app = Flask(__name__, template_folder="templates", static_folder="static") def load_insights(): with open("final_trend_insights.json", "r", encoding="utf-8") as f: return json.load(f) @app.route("/") def dashboard(): data = load_insights() clusters = data.get("section_1_Cluster_Summary", []) desired_order = [ "Explosive Viral Hit", "Momentum Builder", "Consistent Performer", "Gradual Climber", "Organic Riser", ] order_index = {name: i for i, name in enumerate(desired_order)} clusters.sort(key=lambda c: order_index.get(c.get("trend_archetype", ""), 999)) topics = data.get("section_2_Viral_Topics", []) nascent = data.get("section_3_Nascent_Trends", {}) or {} nt_summary = nascent.get("Nascent_Topics_summary", {}) or {} nv_summary = nascent.get("Nascent_Videos_summary", {}) or {} nt_list = nt_summary.get("Nascent_Topics", []) or [] nv_list = nv_summary.get("Nascent_Videos", []) or [] return render_template("dashboard.html", data=data,clusters=clusters, viral_topics=topics,nascent=nascent, nt_summary=nt_summary, nv_summary=nv_summary, nt_list=nt_list, nv_list=nv_list ) if __name__ == "__main__": app.run(debug=True)