Spaces:
Sleeping
Sleeping
| import gradio as gr | |
| import json | |
| import pandas as pd | |
| def extract_usernames(file_obj, is_following=False): | |
| if file_obj is None: | |
| return set() | |
| try: | |
| # Read the uploaded file | |
| data = json.load(open(file_obj.name, "r")) | |
| # Instagram's JSON structure can vary slightly by account age | |
| # 'following' usually has a top-level key, 'followers' is often just a list | |
| if is_following and "relationships_following" in data: | |
| entries = data["relationships_following"] | |
| else: | |
| entries = data if isinstance(data, list) else data.get("relationships_followers", []) | |
| usernames = [] | |
| for entry in entries: | |
| # Extract username from the 'string_list_data' field | |
| if "string_list_data" in entry: | |
| usernames.append(entry["string_list_data"][0]["value"]) | |
| return set(usernames) | |
| except Exception as e: | |
| return f"Error: {str(e)}" | |
| def analyze_stats(followers_file, following_file): | |
| followers = extract_usernames(followers_file) | |
| following = extract_usernames(following_file, is_following=True) | |
| if isinstance(followers, str): return followers, None, None | |
| if isinstance(following, str): return following, None, None | |
| # Logic: Who doesn't follow back? | |
| not_following_back = list(following - followers) | |
| # Logic: Who do you not follow back? | |
| fans = list(followers - following) | |
| df_not_back = pd.DataFrame(not_following_back, columns=["Username"]) | |
| df_fans = pd.DataFrame(fans, columns=["Username"]) | |
| summary = f"π **Results:**\n- **Not Following You Back:** {len(not_following_back)}\n- **Fans (You don't follow back):** {len(fans)}" | |
| return summary, df_not_back, df_fans | |
| # --- UI Layout --- | |
| with gr.Blocks(theme=gr.themes.Soft()) as demo: | |
| gr.Markdown("# πΈ Instagram Safe Tracker") | |
| gr.Markdown(""" | |
| ### π‘οΈ 100% Account Safe | |
| No login required. This app only analyzes the data files you download from Instagram. | |
| **How to get your files:** | |
| 1. Go to Instagram **Settings** > **Your Activity** > **Download your information**. | |
| 2. Click **Download or transfer information**. | |
| 3. Select **Followers and Following**. | |
| 4. Select **Format: JSON** (NOT HTML) and **Date Range: All Time**. | |
| 5. Once you get the email, upload `followers_1.json` and `following.json` below. | |
| """) | |
| with gr.Row(): | |
| file_followers = gr.File(label="Upload followers_1.json") | |
| file_following = gr.File(label="Upload following.json") | |
| btn = gr.Button("π Find Unfollowers", variant="primary") | |
| out_summary = gr.Markdown() | |
| with gr.Tabs(): | |
| with gr.TabItem("Not Following You Back"): | |
| out_not_back = gr.DataFrame() | |
| with gr.TabItem("Fans (You don't follow back)"): | |
| out_fans = gr.DataFrame() | |
| btn.click( | |
| analyze_stats, | |
| inputs=[file_followers, file_following], | |
| outputs=[out_summary, out_not_back, out_fans] | |
| ) | |
| demo.launch() |