File size: 1,441 Bytes
1361a1e
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
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)