Spaces:
Sleeping
Sleeping
File size: 4,726 Bytes
2707235 | 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 | # π 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).
|