# 🔐 Login System & User Tracking Guide ## ✅ What I've Added: ### 1. **Hugging Face Login System** - Users see a "🔐 Sign in with Hugging Face" button at the top - They log in once with their HF account (free to create) - Their recipes are saved to their personal account - Stays logged in across sessions ### 2. **User Data Tracking** All user activity is automatically logged to: `/mnt/user-data/users/activity_log.txt` **What's tracked:** - Username - Action (GENERATE_RECIPES, SAVE_RECIPE, VIEW_SAVED_RECIPES) - Details (e.g., "7 meals, ÂŖ3.50/meal") - Timestamp **Example log entry:** ``` 2025-12-30 15:45:23 | john_smith | GENERATE_RECIPES | 7 meals, ÂŖ3.50/meal 2025-12-30 15:48:10 | john_smith | SAVE_RECIPE | Chicken Curry 2025-12-30 16:02:45 | jane_doe | VIEW_SAVED_RECIPES | ``` ### 3. **Personal Recipe Storage** Each user's recipes are saved in their own folder: ``` /mnt/user-data/users/ ├── activity_log.txt (all users) ├── john_smith/ │ └── recipes.pkl (John's saved recipes) ├── jane_doe/ │ └── recipes.pkl (Jane's saved recipes) └── ... ``` ## 📊 How to View Your User Data: ### **Option 1: Download the Activity Log** In your Hugging Face Space: 1. Go to Files tab 2. Navigate to `/mnt/user-data/users/` 3. Download `activity_log.txt` 4. Open in Excel or text editor ### **Option 2: View in Code** Add this to see live stats: ```python # Add this at the bottom of app.py for admin view with gr.TabItem("📊 Admin Stats"): gr.Markdown("## User Activity") def get_user_stats(): log_file = "/mnt/user-data/users/activity_log.txt" if os.path.exists(log_file): with open(log_file, "r") as f: lines = f.readlines() return f"Total actions: {len(lines)}\n\n" + "".join(lines[-20:]) return "No activity yet" stats_text = gr.Textbox(label="Recent Activity", lines=15) refresh_btn = gr.Button("Refresh Stats") refresh_btn.click(get_user_stats, outputs=stats_text) demo.load(get_user_stats, outputs=stats_text) ``` ### **Option 3: Export to CSV** ```python import pandas as pd # Read log file log_file = "/mnt/user-data/users/activity_log.txt" data = [] with open(log_file, "r") as f: for line in f: parts = line.strip().split(" | ") if len(parts) == 4: data.append({ "Timestamp": parts[0], "Username": parts[1], "Action": parts[2], "Details": parts[3] }) # Create DataFrame df = pd.DataFrame(data) df.to_csv("user_activity.csv", index=False) ``` ## 📋 How Users Will Experience It: ### **Before Login:** ``` đŸŊī¸ Bitesized AI Meal Planner 👤 Please log in to save recipes and track your meal plans [🔐 Sign in with Hugging Face] ─────────────────────────────────────── [Can use app but recipes won't save] ``` ### **After Login:** ``` đŸŊī¸ Bitesized AI Meal Planner ✅ Logged in as: john_smith [🔐 Sign in with Hugging Face] ─────────────────────────────────────── [Can use app AND save recipes permanently] ``` ## 💡 About the Info Tooltips (â„šī¸ Icons): **Good news!** The info tooltips are ALREADY working as icons! In Gradio, the `info` parameter shows as a small **â„šī¸ icon** next to the label. When users hover over it, the explanation pops up. **How they appear:** ``` 💷 Cost Per Meal (ÂŖ) â„šī¸ [dropdown] ↑ When hovering here, shows: "How much you want to spend per meal. Higher = better ingredients!" ``` **They DON'T show as full text** - they're already hidden as hover-only icons! This is the default Gradio behavior. If they're showing as full text for you, it might be: - An older version of Gradio (update to latest) - A browser issue (try clearing cache) The code is already perfect - they'll show as icons for users! ✅ ## đŸŽ¯ Summary: ✅ **Login added** - Users sign in with HF account ✅ **Tracking enabled** - All activity logged with username ✅ **Personal storage** - Each user's recipes saved separately ✅ **Info tooltips** - Already work as â„šī¸ icons (no change needed!) ## 📧 Following Up with Users: To contact users: 1. Download `activity_log.txt` 2. See all usernames who used your app 3. Visit their HF profiles: `https://huggingface.co/{username}` 4. Many users have contact info or social links on their profiles 5. You can also post updates in HF Discussions **Note:** You get usernames only, not emails. For emails, you'd need a separate signup form (Google Forms recommended).