Curlyblaze commited on
Commit
91ebd3a
·
verified ·
1 Parent(s): 401ed63

Create app.py

Browse files
Files changed (1) hide show
  1. app.py +84 -0
app.py ADDED
@@ -0,0 +1,84 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import gradio as gr
2
+ import json
3
+ import pandas as pd
4
+
5
+ def extract_usernames(file_obj, is_following=False):
6
+ if file_obj is None:
7
+ return set()
8
+
9
+ try:
10
+ # Read the uploaded file
11
+ data = json.load(open(file_obj.name, "r"))
12
+
13
+ # Instagram's JSON structure can vary slightly by account age
14
+ # 'following' usually has a top-level key, 'followers' is often just a list
15
+ if is_following and "relationships_following" in data:
16
+ entries = data["relationships_following"]
17
+ else:
18
+ entries = data if isinstance(data, list) else data.get("relationships_followers", [])
19
+
20
+ usernames = []
21
+ for entry in entries:
22
+ # Extract username from the 'string_list_data' field
23
+ if "string_list_data" in entry:
24
+ usernames.append(entry["string_list_data"][0]["value"])
25
+
26
+ return set(usernames)
27
+ except Exception as e:
28
+ return f"Error: {str(e)}"
29
+
30
+ def analyze_stats(followers_file, following_file):
31
+ followers = extract_usernames(followers_file)
32
+ following = extract_usernames(following_file, is_following=True)
33
+
34
+ if isinstance(followers, str): return followers, None, None
35
+ if isinstance(following, str): return following, None, None
36
+
37
+ # Logic: Who doesn't follow back?
38
+ not_following_back = list(following - followers)
39
+ # Logic: Who do you not follow back?
40
+ fans = list(followers - following)
41
+
42
+ df_not_back = pd.DataFrame(not_following_back, columns=["Username"])
43
+ df_fans = pd.DataFrame(fans, columns=["Username"])
44
+
45
+ summary = f"📊 **Results:**\n- **Not Following You Back:** {len(not_following_back)}\n- **Fans (You don't follow back):** {len(fans)}"
46
+
47
+ return summary, df_not_back, df_fans
48
+
49
+ # --- UI Layout ---
50
+ with gr.Blocks(theme=gr.themes.Soft()) as demo:
51
+ gr.Markdown("# 📸 Instagram Safe Tracker")
52
+ gr.Markdown("""
53
+ ### 🛡️ 100% Account Safe
54
+ No login required. This app only analyzes the data files you download from Instagram.
55
+
56
+ **How to get your files:**
57
+ 1. Go to Instagram **Settings** > **Your Activity** > **Download your information**.
58
+ 2. Click **Download or transfer information**.
59
+ 3. Select **Followers and Following**.
60
+ 4. Select **Format: JSON** (NOT HTML) and **Date Range: All Time**.
61
+ 5. Once you get the email, upload `followers_1.json` and `following.json` below.
62
+ """)
63
+
64
+ with gr.Row():
65
+ file_followers = gr.File(label="Upload followers_1.json")
66
+ file_following = gr.File(label="Upload following.json")
67
+
68
+ btn = gr.Button("🔍 Find Unfollowers", variant="primary")
69
+
70
+ out_summary = gr.Markdown()
71
+
72
+ with gr.Tabs():
73
+ with gr.TabItem("Not Following You Back"):
74
+ out_not_back = gr.DataFrame()
75
+ with gr.TabItem("Fans (You don't follow back)"):
76
+ out_fans = gr.DataFrame()
77
+
78
+ btn.click(
79
+ analyze_stats,
80
+ inputs=[file_followers, file_following],
81
+ outputs=[out_summary, out_not_back, out_fans]
82
+ )
83
+
84
+ demo.launch()