Update monetization/user_dashboard.py
Browse files
monetization/user_dashboard.py
CHANGED
@@ -0,0 +1,46 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
# user_dashboard.py - Gradio-based interface to view token usage and affiliate stats
|
2 |
+
|
3 |
+
import gradio as gr
|
4 |
+
from monetization.token_manager import TokenManager
|
5 |
+
from monetization.affiliate_engine import get_affiliate_recommendations
|
6 |
+
|
7 |
+
# Simulated app + earnings tracker
|
8 |
+
USER_APPS = {
|
9 |
+
"user_001": [
|
10 |
+
{"title": "WaveBot", "category": "retail", "clicks": 8, "revenue": 2.55},
|
11 |
+
{"title": "EduHelper", "category": "educational", "clicks": 13, "revenue": 5.20}
|
12 |
+
]
|
13 |
+
}
|
14 |
+
|
15 |
+
tm = TokenManager()
|
16 |
+
tm.register_user("user_001")
|
17 |
+
|
18 |
+
def dashboard_view(user_id):
|
19 |
+
balance = tm.check_balance(user_id)
|
20 |
+
apps = USER_APPS.get(user_id, [])
|
21 |
+
total_revenue = sum(app['revenue'] for app in apps)
|
22 |
+
|
23 |
+
app_display = "\n".join([f"π¦ {a['title']} ({a['category']}): ${a['revenue']:.2f} from {a['clicks']} clicks" for a in apps])
|
24 |
+
recs = get_affiliate_recommendations(apps[0]['category'] if apps else "creative")
|
25 |
+
rec_display = "\n".join([f"π [{r['name']}]({r['url']})" for r in recs])
|
26 |
+
|
27 |
+
return f"""
|
28 |
+
πͺ Tokens: {balance}
|
29 |
+
π° Total Affiliate Revenue: ${total_revenue:.2f}
|
30 |
+
|
31 |
+
**Your Apps:**
|
32 |
+
{app_display}
|
33 |
+
|
34 |
+
**Suggested Monetization Products:**
|
35 |
+
{rec_display}
|
36 |
+
"""
|
37 |
+
|
38 |
+
# Launch dashboard
|
39 |
+
if __name__ == "__main__":
|
40 |
+
with gr.Blocks() as dash:
|
41 |
+
gr.Markdown("""# π Your RoboSage Creator Dashboard""")
|
42 |
+
uid = gr.Textbox(label="Enter your User ID", value="user_001")
|
43 |
+
output = gr.Markdown()
|
44 |
+
go = gr.Button("Load Dashboard")
|
45 |
+
go.click(fn=dashboard_view, inputs=uid, outputs=output)
|
46 |
+
dash.launch()
|