Create app.py
Browse files123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244import gradio as gr
# ------------------------------# Data (minimal, in-file)# ------------------------------RUBRIC_WEIGHTS = { "grit": 0.18, "risk": 0.12, "time_per_week": 0.14, "runway_months": 0.16, "customer_access": 0.12, "validation_skill": 0.10, "ops_skill": 0.08, "finance_skill": 0.10}
PATHS = { "tech": [ {"path":"Micro-SaaS","difficulty":3,"benefits":"High margins, scalable, global reach", "skills":["customer interviews","MVP scoping","pricing","analytics"], "starter":["Define niche pain","5–10 interviews","Landing page test","Iterate"]}, {"path":"No-code automation agency","difficulty":2,"benefits":"Service revenue funds experiments", "skills":["workflow mapping","Zapier/Make","sales","onboarding"], "starter":["Pick niche","3 pilot clients","SOPs","Retainers"]}, {"path":"Educational apps","difficulty":3,"benefits":"Recurring revenue via schools/parents", "skills":["curriculum","UX","distribution partnerships"], "starter":["Niche curriculum","Prototype","Parent/teacher tests"]} ], "cooking": [ {"path":"Meal-prep delivery","difficulty":4,"benefits":"Tangible product; recurring subs", "skills":["food safety","menu costing","logistics","support"], "starter":["Permits","Menu tests","Delivery loop","Subscriptions"]}, {"path":"Cooking classes","difficulty":2,"benefits":"Low capex; community", "skills":["lesson design","facilitation","marketing"], "starter":["Pilot class","Testimonials","Cohorts","Bundles"]} ], "education": [ {"path":"Tutoring niche","difficulty":2,"benefits":"Fast validation; referrals", "skills":["subject mastery","scheduling","sales"], "starter":["ICP","5 trial students","Packages","Referrals"]} ], "fitness": [ {"path":"Online coaching","difficulty":2,"benefits":"Low overhead; trust", "skills":["programming","accountability","content"], "starter":["Niche offer","Clients 1–3","Testimonials","Packages"]} ], "content": [ {"path":"Newsletter + paid tiers","difficulty":2,"benefits":"Audience compounds", "skills":["editorial","conversion","email ops"], "starter":["Niche POV","Weekly cadence","Lead magnet","Feedback loop"]} ], "games": [ {"path":"Indie premium","difficulty":4,"benefits":"Creative control; wishlists matter", "skills":["scope control","playtesting","marketing"], "starter":["Core loop","Vertical slice","Store page","Playtests"]} ], "fashion": [ {"path":"Print-on-demand niche","difficulty":2,"benefits":"Low inventory risk", "skills":["design","niche research","ads"], "starter":["Mockups","POD store","Ad test","Iterate"]} ]}
SYSTEM_PROMPT = ( "You are a friendly tutor for Entrepreneurial Readiness and Paths. " "Be practical and concise. If the user ran the assessment or path explorer, use that info.")
# ------------------------------# Readiness scoring (0–100)# ------------------------------def compute_readiness(payload): # normalize grit = payload["grit"]/10 risk = payload["risk"]/10 time_norm = min(payload["time_per_week"], 40)/40 runway_norm = min(payload["runway_months"], 24)/24 customer_access = payload["customer_access"]/10 validation_skill = payload["validation_skill"]/10 ops_skill = payload["ops_skill"]/10 finance_skill = payload["finance_skill"]/10
score = 100 * ( RUBRIC_WEIGHTS["grit"]*grit + RUBRIC_WEIGHTS["risk"]*risk + RUBRIC_WEIGHTS["time_per_week"]*time_norm + RUBRIC_WEIGHTS["runway_months"]*runway_norm + RUBRIC_WEIGHTS["customer_access"]*customer_access + RUBRIC_WEIGHTS["validation_skill"]*validation_skill + RUBRIC_WEIGHTS["ops_skill"]*ops_skill + RUBRIC_WEIGHTS["finance_skill"]*finance_skill ) score = int(round(score)) tier = "Starter" if score < 55 else ("Building" if score < 75 else "Launch-ready")
tips = [] if runway_norm < 0.35: tips.append("Build 6–12 months runway or run as a side project.") if time_norm < 0.5: tips.append("Protect ~8–12 hrs/week for interviews & experiments.") if customer_access < 0.6: tips.append("Line up 10–20 target users for interviews.") if validation_skill < 0.6: tips.append("Run a demand test (landing page/preorder) before building.") if finance_skill < 0.5: tips.append("Track cash runway monthly.") if ops_skill < 0.5: tips.append("Create a weekly ops checklist to reduce chaos.") return {"score":score, "tier":tier, "tips":tips}
# ------------------------------# Path suggestions helper# ------------------------------def suggest_paths(interests, experience): results = [] for domain in interests or []: for item in PATHS.get(domain, []): diff = item["difficulty"] # adjust for experience if experience == "beginner": diff = min(5, diff + 1) if experience == "advanced": diff = max(1, diff - 1) results.append({ "domain": domain, "path": item["path"], "difficulty_1to5": diff, "benefits": item["benefits"], "key_skills": item["skills"], "starter_plan": item["starter"], }) # keep it short return results[:6]
# ------------------------------# Simple rule-based "chat"# ------------------------------def local_reply(user_msg, history, assessment_state, path_state): text = (user_msg or "").lower()
# reference readiness if "score" in text or "ready" in text or "readiness" in text: if isinstance(assessment_state, dict) and "score" in assessment_state: s = assessment_state["score"] t = assessment_state.get("tier", "?") return f"Your readiness is **{s}/100 ({t})**. Top tip: {assessment_state.get('tips', ['Run small demand tests first.'])[0]}" else: return "Run **Assess readiness** on the right, then ask me again 🙂"
# reference paths if "path" in text or "idea" in text or "domain" in text: if isinstance(path_state, dict) and path_state.get("suggestions"): sug = path_state["suggestions"][0] return (f"Try **{sug['domain']} → {sug['path']}**. " f"Difficulty ~{sug['difficulty_1to5']}/5. " f"Benefits: {sug['benefits']}. " f"First steps: {', '.join(sug['starter_plan'][:3])}. Want more options?") else: return "Pick a few interests under **Path Explorer**, hit **Suggest paths**, then ask me which to start with."
# detect domain mention for domain in PATHS.keys(): if domain in text: first = PATHS[domain][0] return (f"In **{domain}**, consider **{first['path']}** " f"(difficulty {first['difficulty']}/5). " f"Why it can pay off: {first['benefits']}. " f"Starter plan: {', '.join(first['starter'][:3])}.") # default helpful tip return ("Start with a small **demand test**: a landing page and 5–10 user interviews. " "Measure real intent (signups/preorders) before you build.")
# ------------------------------# Gradio UI# ------------------------------with gr.Blocks(theme="soft", fill_height=True) as demo: gr.Markdown("## Entrepreneurial Tutor (no external model)\nAsk about readiness or paths. Use the tools on the right to feed me context.")
with gr.Row(): # Chat with gr.Column(scale=3): chat = gr.Chatbot(type="tuples", height=460) with gr.Row(): msg = gr.Textbox(placeholder="Ask about Entrepreneurial paths or readiness…", scale=4) send = gr.Button("Send", variant="primary")
# Tools with gr.Column(scale=2): gr.Markdown("### Quick Readiness Assessment") grit = gr.Slider(0,10, value=6, step=1, label="Grit / persistence") risk = gr.Slider(0,10, value=5, step=1, label="Comfort with risk") time_per_week = gr.Slider(0,40, value=8, step=1, label="Time available per week (hrs)") runway_months = gr.Slider(0,24, value=3, step=1, label="Financial runway (months)") customer_access = gr.Slider(0,10, value=5, step=1, label="Access to target customers") validation_skill = gr.Slider(0,10, value=4, step=1, label="Validation / testing skill") ops_skill = gr.Slider(0,10, value=4, step=1, label="Operations / delivery skill") finance_skill = gr.Slider(0,10, value=3, step=1, label="Finance / budgeting")
assess_btn = gr.Button("Assess readiness") assessment_state = gr.State({}) assess_out = gr.JSON(label="Assessment Result")
gr.Markdown("### Path Explorer") interests = gr.CheckboxGroup( choices=list(PATHS.keys()), value=["tech"], label="Interests / domains" ) experience = gr.Radio( choices=["beginner","intermediate","advanced"], value="beginner", label="Experience level" ) suggest_btn = gr.Button("Suggest paths") path_state = gr.State({}) paths_out = gr.JSON(label="Suggested Paths")
# Wiring def do_assess(grit, risk, time_per_week, runway_months, customer_access, validation_skill, ops_skill, finance_skill): payload = { "grit":grit,"risk":risk,"time_per_week":time_per_week,"runway_months":runway_months, "customer_access":customer_access,"validation_skill":validation_skill, "ops_skill":ops_skill,"finance_skill":finance_skill } result = compute_readiness(payload) return result, result # show + store
assess_btn.click( do_assess, inputs=[grit, risk, time_per_week, runway_months, customer_access, validation_skill, ops_skill, finance_skill], outputs=[assess_out, assessment_state] )
def do_paths(interests, experience): res = suggest_paths(interests, experience) state = {"interests": interests, "experience": experience, "suggestions": res} return res, state
suggest_btn.click( do_paths, inputs=[interests, experience], outputs=[paths_out, path_state] )
def on_send(user_message, history, assessment_state, path_state): if not user_message: return gr.update(), history reply = local_reply(user_message, history, assessment_state, path_state) return "", (history or []) + [[user_message, reply]]
send.click( on_send, inputs=[msg, chat, assessment_state, path_state], outputs=[msg, chat] )
if __name__ == "__main__": demo.launch()app.pyAdded+244