| import gradio as gr |
| import joblib |
| import pandas as pd |
| from huggingface_hub import hf_hub_download |
|
|
| |
| YOUR_HF_USERNAME = "maliksahib1" |
| |
|
|
| |
| |
| try: |
| model_path = hf_hub_download( |
| repo_id=f"{YOUR_HF_USERNAME}/tiktok-transparency-tool", |
| filename="tiktok_fake_follower_model.joblib" |
| ) |
| model = joblib.load(model_path) |
| except Exception as e: |
| |
| |
| raise gr.Error(f"Failed to load the model. Please check your Hugging Face repo and username. Error: {e}") |
|
|
|
|
| |
| def analyze_profile(username): |
| if not username: |
| return "Please enter a TikTok username.", None |
|
|
| |
| |
| |
| |
| print(f"Analyzing {username}...") |
| |
| |
| mock_follower_data = [ |
| {'handle': '@user198237912', 'video_count': 0, 'follower_count': 5, 'following_count': 1500, 'has_bio': 0, 'is_generic_username': 1}, |
| {'handle': '@user987654321', 'video_count': 0, 'follower_count': 2, 'following_count': 500, 'has_bio': 0, 'is_generic_username': 1}, |
| {'handle': '@real_creator_from_demo', 'video_count': 50, 'follower_count': 15000, 'following_count': 200, 'has_bio': 1, 'is_generic_username': 0}, |
| {'handle': '@another_creator_demo', 'video_count': 120, 'follower_count': 250000, 'following_count': 350, 'has_bio': 1, 'is_generic_username': 0}, |
| {'handle': '@suspicious_but_not_generic', 'video_count': 1, 'follower_count': 12, 'following_count': 800, 'has_bio': 0, 'is_generic_username': 0}, |
| {'handle': '@another_bot_account_123', 'video_count': 0, 'follower_count': 1, 'following_count': 100, 'has_bio': 0, 'is_generic_username': 0}, |
| ] |
| |
| |
| df = pd.DataFrame(mock_follower_data) |
| features = ['video_count', 'follower_count', 'following_count', 'has_bio', 'is_generic_username'] |
| X_predict = df[features] |
| |
| |
| predictions_proba = model.predict_proba(X_predict)[:, 1] |
| df['suspicion_score'] = predictions_proba |
| |
| |
| total_followers_analyzed = len(df) |
| |
| suspicious_followers = df[df['suspicion_score'] > 0.70] |
| num_suspicious = len(suspicious_followers) |
| suspicion_rate = (num_suspicious / total_followers_analyzed) * 100 |
| |
| report_text = f""" |
| ### Analysis Report for @{username} |
| - **Followers Analyzed:** {total_followers_analyzed} (Using sample data for this demo) |
| - **Highly Suspicious Followers Found:** {num_suspicious} |
| - **Overall Suspicion Rate:** **{suspicion_rate:.1f}%** |
| |
| *This analysis is for educational purposes and uses pre-loaded sample data, not live data from TikTok.* |
| """ |
| |
| |
| output_df = suspicious_followers[['handle', 'suspicion_score']] |
| output_df = output_df.sort_values(by='suspicion_score', ascending=False).reset_index(drop=True) |
| |
| return report_text, output_df |
|
|
| |
| iface = gr.Interface( |
| fn=analyze_profile, |
| inputs=gr.Textbox(label="TikTok Username", placeholder="e.g., charlidamelio"), |
| outputs=[ |
| gr.Markdown(label="Analysis Summary"), |
| gr.DataFrame(label="Top Suspicious Follower Accounts (from sample)") |
| ], |
| title="TikTok Transparency Tool (T3)", |
| description="Enter a TikTok username to analyze a sample of its followers. This tool uses a machine learning model to detect suspicious accounts based on public profile metrics.", |
| allow_flagging="never" |
| ) |
|
|
| |
| iface.launch() |