BitesizedAI / LOGIN_GUIDE.md
Leospencer1's picture
Upload LOGIN_GUIDE.md
2707235 verified
|
Raw History Blame Contribute Delete
4.73 kB

A newer version of the Gradio SDK is available: 6.32.0

Upgrade

πŸ” 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:

# 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

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).