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|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
|
| 2 |
+
!pip install -q gradio transformers requests beautifulsoup4
|
| 3 |
+
|
| 4 |
+
|
| 5 |
+
import gradio as gr
|
| 6 |
+
import requests, json, os, datetime
|
| 7 |
+
from bs4 import BeautifulSoup
|
| 8 |
+
from transformers import pipeline
|
| 9 |
+
|
| 10 |
+
LEADERBOARD_FILE = "/content/road2success_leaderboard.json"
|
| 11 |
+
if not os.path.exists(LEADERBOARD_FILE):
|
| 12 |
+
with open(LEADERBOARD_FILE, "w") as f:
|
| 13 |
+
json.dump({"scores": []}, f)
|
| 14 |
+
|
| 15 |
+
_gen = None
|
| 16 |
+
def get_generator():
|
| 17 |
+
global _gen
|
| 18 |
+
if _gen is None:
|
| 19 |
+
try:
|
| 20 |
+
_gen = pipeline("text-generation", model="distilgpt2", device=-1) # CPU Colab
|
| 21 |
+
except Exception as e:
|
| 22 |
+
_gen = None
|
| 23 |
+
print("Failed to load generator:", e)
|
| 24 |
+
return _gen
|
| 25 |
+
|
| 26 |
+
def ai_mentor_query(prompt, short_answer=True, eli5=False):
|
| 27 |
+
if not prompt or not prompt.strip():
|
| 28 |
+
return "Ask a clear question about study plans, hackathons, or projects."
|
| 29 |
+
gen = get_generator()
|
| 30 |
+
if gen is None:
|
| 31 |
+
return "AI model failed to load. Try restarting the Colab runtime."
|
| 32 |
+
# craft prompt variants
|
| 33 |
+
modifier = ""
|
| 34 |
+
if short_answer:
|
| 35 |
+
modifier += " Provide a concise answer in <= 3 sentences."
|
| 36 |
+
if eli5:
|
| 37 |
+
modifier += " Explain like I'm 5 (simple, clear language)."
|
| 38 |
+
request = prompt.strip() + modifier
|
| 39 |
+
out = gen(request, max_length=120, num_return_sequences=1)[0]["generated_text"]
|
| 40 |
+
|
| 41 |
+
out = out.replace("\n", " ").strip()
|
| 42 |
+
|
| 43 |
+
return out[:900]
|
| 44 |
+
|
| 45 |
+
|
| 46 |
+
ROADMAPS = {
|
| 47 |
+
"Class 5": {
|
| 48 |
+
"objective": "Spark curiosity, build number sense, foundations of reading, and light coding exposure.",
|
| 49 |
+
"subjects": [
|
| 50 |
+
"Math: number sense, addition/subtraction, basic fractions, time & money",
|
| 51 |
+
"Science: living things, plants, simple experiments",
|
| 52 |
+
"Language: reading, small essays, comprehension",
|
| 53 |
+
"Coding: block-based (Scratch) — basics of sequence & loops"
|
| 54 |
+
],
|
| 55 |
+
"projects": ["Plant growth journal (measure & graph)", "Scratch storytelling animation"],
|
| 56 |
+
"resources": [("Khan Academy - Kids", "https://www.khanacademy.org/"), ("Code.org - Learn", "https://code.org/learn")],
|
| 57 |
+
"videos": [("Fun Science for Kids", "https://www.youtube.com/")],
|
| 58 |
+
"coding_questions": []
|
| 59 |
+
},
|
| 60 |
+
"Class 6": {
|
| 61 |
+
"objective": "Build curiosity, logical thinking, basic problem-solving and gentle programming.",
|
| 62 |
+
"subjects": ["Fractions, Decimals, Basic Geometry, Intro to Algebra", "Basics of Physics, Chemistry, Biology", "Scratch / Python Turtle basics"],
|
| 63 |
+
"projects": ["Simple games in Scratch", "Science fair volcano or plant growth"],
|
| 64 |
+
"resources": [("Khan Academy Math", "https://www.khanacademy.org/"), ("Scratch", "https://scratch.mit.edu/")],
|
| 65 |
+
"videos": [("Scratch for Beginners", "https://www.youtube.com/watch?v=jXUZaf5D12E")],
|
| 66 |
+
"coding_questions": []
|
| 67 |
+
},
|
| 68 |
+
"Class 7": {
|
| 69 |
+
"objective": "Strengthen reasoning, begin structured coding and deeper science.",
|
| 70 |
+
"subjects": ["Integers, Fractions, Probability", "Forces, Motion, Biology", "Python basics - loops & conditionals"],
|
| 71 |
+
"projects": ["Python guessing game", "Science experiments logbook"],
|
| 72 |
+
"resources": [("Khan Academy Science", "https://www.khanacademy.org/science")],
|
| 73 |
+
"videos": [("Python for Kids", "https://www.youtube.com/watch?v=8ext9G7xspg")],
|
| 74 |
+
"coding_questions": []
|
| 75 |
+
},
|
| 76 |
+
"Class 8": {
|
| 77 |
+
"objective": "Structured thinking, algebra foundation, and applied coding.",
|
| 78 |
+
"subjects": ["Algebra, Linear equations, Geometry", "Electricity basics, Chemistry", "Python lists & functions"],
|
| 79 |
+
"projects": ["Calculator in Python", "Water filtration model"],
|
| 80 |
+
"resources": [("GeeksforGeeks - Python lists", "https://www.geeksforgeeks.org/python-list/")],
|
| 81 |
+
"videos": [],
|
| 82 |
+
"coding_questions": []
|
| 83 |
+
},
|
| 84 |
+
"Class 9": {
|
| 85 |
+
"objective": "Prepare foundations for high-school STEM and beginner coding competitions.",
|
| 86 |
+
"subjects": ["Geometry, Trigonometry basics, Probability", "Motion, Energy, Chemistry basics", "Python data structures"],
|
| 87 |
+
"projects": ["Mini data analysis in Python", "Tic-Tac-Toe / Snake game"],
|
| 88 |
+
"resources": [("Khan Academy", "https://www.khanacademy.org/")],
|
| 89 |
+
"videos": [("Python for Beginners - freeCodeCamp", "https://www.youtube.com/watch?v=rfscVS0vtbw")],
|
| 90 |
+
"coding_questions": [("Palindrome - LeetCode", "https://leetcode.com/problems/valid-palindrome/"), ("Two Sum - LeetCode", "https://leetcode.com/problems/two-sum/")]
|
| 91 |
+
},
|
| 92 |
+
"Class 10": {
|
| 93 |
+
"objective": "Strong STEM foundation; begin focused JEE/NEET foundations and algorithmic thinking",
|
| 94 |
+
"subjects": ["Algebra, Quadratics, Coordinate Geometry", "Physics/Chem/Biology fundamentals", "Python - algorithms intro"],
|
| 95 |
+
"projects": ["Text-based calculator", "Mini robotics prototype"],
|
| 96 |
+
"resources": [("LeetCode - Practice", "https://leetcode.com/")],
|
| 97 |
+
"videos": [("Physics Galaxy - JEE foundation", "https://www.youtube.com/c/Physicsgalaxy")],
|
| 98 |
+
"coding_questions": [("FizzBuzz", "https://leetcode.com/problems/fizz-buzz/")]
|
| 99 |
+
},
|
| 100 |
+
"Class 11": {
|
| 101 |
+
"objective": "Deepen PCM/PCB subject knowledge; start serious JEE/NEET path.",
|
| 102 |
+
"subjects": ["Calculus intro, Coordinate geometry, Mechanics", "Thermodynamics basics", "Organic fundamentals"],
|
| 103 |
+
"projects": ["Projectile motion simulation", "Chemistry reaction observations (safe)"],
|
| 104 |
+
"resources": [("NCERT Books", "https://ncert.nic.in/")],
|
| 105 |
+
"videos": [],
|
| 106 |
+
"coding_questions": []
|
| 107 |
+
},
|
| 108 |
+
"Class 12": {
|
| 109 |
+
"objective": "Revision, mocks, strengthen weak areas, and test-taking strategies.",
|
| 110 |
+
"subjects": ["Advanced calculus, Vectors, Electromagnetism, Organic mechanisms, Human physiology"],
|
| 111 |
+
"projects": ["Capstone lab-style report", "Mock full-length test plan"],
|
| 112 |
+
"resources": [("JEE Main Official", "https://jeemain.nta.nic.in/")],
|
| 113 |
+
"videos": [],
|
| 114 |
+
"coding_questions": []
|
| 115 |
+
},
|
| 116 |
+
"B.Tech 1st Year": {
|
| 117 |
+
"objective": "Strengthen programming, DSA basics, and system thinking.",
|
| 118 |
+
"subjects": ["Python / C / C++", "Arrays, Linked Lists, Recursion", "Discrete Math"],
|
| 119 |
+
"projects": ["Student Management System", "Simple Game"],
|
| 120 |
+
"resources": [("Coursera - Python", "https://www.coursera.org/")],
|
| 121 |
+
"videos": [],
|
| 122 |
+
"coding_questions": [("Reverse Linked List", "https://leetcode.com/problems/reverse-linked-list/")]
|
| 123 |
+
},
|
| 124 |
+
"B.Tech 2nd Year": {
|
| 125 |
+
"objective": "Web basics, DBMS, OOP, intermediate DSA.",
|
| 126 |
+
"subjects": ["Stacks/Queues/Trees/Graphs", "SQL/MySQL", "HTML/CSS/JS"],
|
| 127 |
+
"projects": ["Online Quiz System", "Portfolio Website"],
|
| 128 |
+
"resources": [],
|
| 129 |
+
"coding_questions": []
|
| 130 |
+
},
|
| 131 |
+
"B.Tech 3rd Year": {
|
| 132 |
+
"objective": "Specialize: DS/Backend/Cloud and prepare for internships.",
|
| 133 |
+
"subjects": ["Pandas/NumPy/ML basics", "Node/React/Django", "AWS basics"],
|
| 134 |
+
"projects": ["Recommendation System", "E-commerce backend"],
|
| 135 |
+
"resources": [],
|
| 136 |
+
"coding_questions": [("LRU Cache", "https://leetcode.com/problems/lru-cache/")]
|
| 137 |
+
},
|
| 138 |
+
"B.Tech Final Year": {
|
| 139 |
+
"objective": "Capstone project, system design, placements, and open-source contributions.",
|
| 140 |
+
"subjects": ["Advanced algorithms", "System design basics", "Cloud architecture"],
|
| 141 |
+
"projects": ["AI Chatbot capstone", "Inventory SaaS app"],
|
| 142 |
+
"resources": [("System Design - FreeCodeCamp", "https://www.youtube.com/watch?v=xpDnVSmNFX0")],
|
| 143 |
+
"coding_questions": []
|
| 144 |
+
},
|
| 145 |
+
"JEE Main": {
|
| 146 |
+
"objective": "Crack JEE Main: focused practice on PCM + mocks & time management.",
|
| 147 |
+
"subjects": ["Mechanics, Heat, Optics, Algebra, Calculus, Coordinate geometry"],
|
| 148 |
+
"projects": ["Physics project simulations", "Math modeling tasks"],
|
| 149 |
+
"resources": [("Toppr - JEE Main", "https://www.toppr.com/jee-main/")],
|
| 150 |
+
"videos": [],
|
| 151 |
+
"coding_questions": []
|
| 152 |
+
},
|
| 153 |
+
"JEE Advanced": {
|
| 154 |
+
"objective": "Master concepts at Olympiad level — deep problem solving.",
|
| 155 |
+
"subjects": ["Advanced mechanics, E&M, Vectors, Multi-variable calculus"],
|
| 156 |
+
"projects": ["Physics simulation libraries", "Advanced math modeling"],
|
| 157 |
+
"resources": [("Physics Galaxy - Advanced", "https://www.youtube.com/c/Physicsgalaxy")],
|
| 158 |
+
"videos": [],
|
| 159 |
+
"coding_questions": []
|
| 160 |
+
},
|
| 161 |
+
"NEET": {
|
| 162 |
+
"objective": "Crack NEET: Master Biology, NCERT heavy study + mock tests.",
|
| 163 |
+
"subjects": ["Cell biology, Physiology, Genetics, Ecology, Biotech, Organic/Physical Chemistry basics"],
|
| 164 |
+
"projects": ["Genetics cross models (Punnett)", "Anatomy model studies"],
|
| 165 |
+
"resources": [("Aakash - NEET prep", "https://www.aakash.ac.in/neet")],
|
| 166 |
+
"videos": [],
|
| 167 |
+
"coding_questions": []
|
| 168 |
+
}
|
| 169 |
+
}
|
| 170 |
+
def render_roadmap(level):
|
| 171 |
+
info = ROADMAPS.get(level, None)
|
| 172 |
+
if not info:
|
| 173 |
+
return "<b>No roadmap available.</b>"
|
| 174 |
+
html = f"<div style='backdrop-filter: blur(6px); padding:16px; border-radius:12px;'>"
|
| 175 |
+
html += f"<h2 style='color:#00aaff'>{level} Roadmap</h2>"
|
| 176 |
+
html += f"<p><b>Objective:</b> {info.get('objective','-')}</p>"
|
| 177 |
+
html += "<b>Subjects:</b><ul>" + "".join(f"<li>{s}</li>" for s in info.get('subjects',[])) + "</ul>"
|
| 178 |
+
html += "<b>Projects:</b><ul>" + "".join(f"<li>{p}</li>" for p in info.get('projects',[])) + "</ul>"
|
| 179 |
+
if info.get("resources"):
|
| 180 |
+
html += "<b>Resources:</b><ul>" + "".join(f"<li><a href='{r[1]}' target='_blank'>{r[0]}</a></li>" for r in info.get('resources',[])) + "</ul>"
|
| 181 |
+
if info.get("videos"):
|
| 182 |
+
html += "<b>Videos:</b><ul>" + "".join(f"<li><a href='{v[1]}' target='_blank'>{v[0]}</a></li>" for v in info.get('videos',[])) + "</ul>"
|
| 183 |
+
if info.get("coding_questions"):
|
| 184 |
+
html += "<b>Coding Practice:</b><ul>" + "".join(f"<li><a href='{c[1]}' target='_blank'>{c[0]}</a></li>" for c in info.get('coding_questions',[])) + "</ul>"
|
| 185 |
+
html += "</div>"
|
| 186 |
+
return html
|
| 187 |
+
|
| 188 |
+
def generate_quick_plan(level, days=30):
|
| 189 |
+
|
| 190 |
+
base = ROADMAPS.get(level, None)
|
| 191 |
+
if not base:
|
| 192 |
+
return "No roadmap available."
|
| 193 |
+
|
| 194 |
+
subjects = base.get("subjects", [])
|
| 195 |
+
if not subjects:
|
| 196 |
+
return "No subjects found for this level."
|
| 197 |
+
weeks = max(1, days // 7)
|
| 198 |
+
plan = []
|
| 199 |
+
for w in range(weeks):
|
| 200 |
+
subj = subjects[w % len(subjects)]
|
| 201 |
+
plan.append(f"Week {w+1}: Focus on — {subj}. Practice exercises + 3 problems.")
|
| 202 |
+
return "<br>".join(plan)
|
| 203 |
+
|
| 204 |
+
|
| 205 |
+
def fetch_internships_remotive(query="intern"):
|
| 206 |
+
try:
|
| 207 |
+
r = requests.get(f"https://remotive.com/api/remote-jobs?search={query}&limit=20", timeout=6)
|
| 208 |
+
r.raise_for_status()
|
| 209 |
+
data = r.json().get("jobs", [])
|
| 210 |
+
# show up to 8 relevant
|
| 211 |
+
out = ""
|
| 212 |
+
for j in data[:8]:
|
| 213 |
+
title = j.get("title","")
|
| 214 |
+
company = j.get("company_name","")
|
| 215 |
+
url = j.get("url","#")
|
| 216 |
+
out += f"• {title} at {company}\n{url}\n\n"
|
| 217 |
+
return out if out else "No internships found for this query."
|
| 218 |
+
except Exception as e:
|
| 219 |
+
return f"Internship fetch error: {e}"
|
| 220 |
+
|
| 221 |
+
def fetch_hackathons_devpost(keyword=""):
|
| 222 |
+
try:
|
| 223 |
+
r = requests.get("https://devpost.com/hackathons", timeout=6)
|
| 224 |
+
r.raise_for_status()
|
| 225 |
+
soup = BeautifulSoup(r.text, "html.parser")
|
| 226 |
+
# Devpost pages change; try a few selectors
|
| 227 |
+
titles = soup.select("h3.title") or soup.select("h5.title") or soup.find_all("h3")
|
| 228 |
+
results = []
|
| 229 |
+
for t in titles[:12]:
|
| 230 |
+
text = t.get_text(strip=True)
|
| 231 |
+
if not keyword or keyword.lower() in text.lower():
|
| 232 |
+
results.append("• " + text)
|
| 233 |
+
return "\n".join(results) if results else "No hackathons found."
|
| 234 |
+
except Exception as e:
|
| 235 |
+
return f"Hackathon fetch error: {e}"
|
| 236 |
+
|
| 237 |
+
|
| 238 |
+
def generate_pitch_pro(idea, team, impact_one_line):
|
| 239 |
+
if not idea:
|
| 240 |
+
return "Please provide a one-line idea."
|
| 241 |
+
team = team or "Team Road2Success"
|
| 242 |
+
impact = impact_one_line or "Solves user pain / high impact"
|
| 243 |
+
pitch = (
|
| 244 |
+
f"🔹 {team} — 60s Pitch\n\n"
|
| 245 |
+
f"**Idea:** {idea}\n\n"
|
| 246 |
+
f"**Problem:** {impact}\n\n"
|
| 247 |
+
f"**Solution (MVP):** One-sentence summary of the product and the core demo-able feature.\n\n"
|
| 248 |
+
f"**Tech Stack:** Frontend (React/Gradio), Backend (FastAPI/Flask), ML (HuggingFace/distil), DB (Firebase/Postgres)\n\n"
|
| 249 |
+
f"**Demo Flow (30s):** 1) Landing → 2) Core feature live demo → 3) Analytics/Impact screen\n\n"
|
| 250 |
+
f"**Why it wins:** Novel application + solid demo + measurable impact + deployable within hackathon time.\n\n"
|
| 251 |
+
f"**Ask:** (Mentorship/API credits/Cloud credits)\n"
|
| 252 |
+
)
|
| 253 |
+
return pitch
|
| 254 |
+
|
| 255 |
+
def quick_checklist():
|
| 256 |
+
items = [
|
| 257 |
+
"✅ Finalize MVP scope (1 core feature)",
|
| 258 |
+
"✅ Repo + README + Start script",
|
| 259 |
+
"✅ Roles assigned",
|
| 260 |
+
"✅ Demo script + 1-minute pitch",
|
| 261 |
+
"✅ Deploy: Colab + Gradio share or Netlify/Heroku",
|
| 262 |
+
"✅ Slides (3-5) + fallback video"
|
| 263 |
+
]
|
| 264 |
+
return "\n".join(items)
|
| 265 |
+
|
| 266 |
+
def countdown_to(date_iso):
|
| 267 |
+
try:
|
| 268 |
+
t = datetime.datetime.fromisoformat(date_iso)
|
| 269 |
+
now = datetime.datetime.now()
|
| 270 |
+
diff = t - now
|
| 271 |
+
if diff.total_seconds() <= 0:
|
| 272 |
+
return "Date is in the past. Pick a future ISO date like 2025-10-01T18:00"
|
| 273 |
+
days = diff.days
|
| 274 |
+
hrs = diff.seconds // 3600
|
| 275 |
+
mins = (diff.seconds % 3600) // 60
|
| 276 |
+
return f"{days} days, {hrs} hours, {mins} minutes remaining"
|
| 277 |
+
except Exception as e:
|
| 278 |
+
return "Invalid date. Use ISO format: YYYY-MM-DDTHH:MM (e.g. 2025-10-01T18:00)"
|
| 279 |
+
|
| 280 |
+
|
| 281 |
+
SAMPLE_QUIZ = [
|
| 282 |
+
("What is the time complexity of binary search?", ["O(1)","O(n)","O(log n)","O(n log n)"], "O(log n)"),
|
| 283 |
+
("Which Python library is used for machine learning?", ["NumPy","scikit-learn","Pandas","Matplotlib"], "scikit-learn"),
|
| 284 |
+
("Which structure follows FIFO?", ["Stack","Queue","Graph","Tree"], "Queue")
|
| 285 |
+
]
|
| 286 |
+
|
| 287 |
+
def grade_and_record(name, a1, a2, a3):
|
| 288 |
+
answers = [a1, a2, a3]
|
| 289 |
+
correct = 0
|
| 290 |
+
for i, a in enumerate(answers):
|
| 291 |
+
if a == SAMPLE_QUIZ[i][2]:
|
| 292 |
+
correct += 1
|
| 293 |
+
score = int(correct)
|
| 294 |
+
# read/write leaderboard
|
| 295 |
+
try:
|
| 296 |
+
with open(LEADERBOARD_FILE, "r") as f:
|
| 297 |
+
data = json.load(f)
|
| 298 |
+
except:
|
| 299 |
+
data = {"scores": []}
|
| 300 |
+
entry = {"name": name or "Anonymous", "score": score, "time": datetime.datetime.now().isoformat()}
|
| 301 |
+
data["scores"].append(entry)
|
| 302 |
+
# keep top 20 by score then time
|
| 303 |
+
data["scores"] = sorted(data["scores"], key=lambda x: (-x["score"], x["time"]))[:40]
|
| 304 |
+
with open(LEADERBOARD_FILE, "w") as f:
|
| 305 |
+
json.dump(data, f, indent=2)
|
| 306 |
+
return f"Score: {score}/{len(SAMPLE_QUIZ)} — recorded. Good job!"
|
| 307 |
+
|
| 308 |
+
def show_leaderboard():
|
| 309 |
+
with open(LEADERBOARD_FILE, "r") as f:
|
| 310 |
+
data = json.load(f)
|
| 311 |
+
rows = data.get("scores", [])[:10]
|
| 312 |
+
if not rows:
|
| 313 |
+
return "No scores yet."
|
| 314 |
+
md = "### Leaderboard (Top 10)\n\n"
|
| 315 |
+
for i, r in enumerate(rows, start=1):
|
| 316 |
+
md += f"{i}. **{r['name']}** — {r['score']}/3 ({r['time'].split('T')[0]})\n\n"
|
| 317 |
+
return md
|
| 318 |
+
|
| 319 |
+
|
| 320 |
+
GLASS_CSS = """
|
| 321 |
+
:root{
|
| 322 |
+
--glass-bg: rgba(255,255,255,0.06);
|
| 323 |
+
--glass-border: rgba(255,255,255,0.12);
|
| 324 |
+
--accent: #00aaff;
|
| 325 |
+
}
|
| 326 |
+
body { background: linear-gradient(135deg,#071028 0%, #0b1f3a 100%); color: #e6f0ff; }
|
| 327 |
+
.gradio-container { font-family: 'Segoe UI', Roboto, Arial; }
|
| 328 |
+
.card { background: var(--glass-bg); border: 1px solid var(--glass-border); box-shadow: 0 8px 30px rgba(2,6,23,0.6); border-radius: 12px; padding: 12px; }
|
| 329 |
+
h1 { color: var(--accent); text-shadow: 0 3px 12px rgba(0,170,255,0.08); }
|
| 330 |
+
a { color: #bfefff; text-decoration: none; }
|
| 331 |
+
a:hover { text-decoration: underline; }
|
| 332 |
+
.gr-button { background: linear-gradient(90deg,#00b4ff,#00ffa3)!important; color: #022 !important; font-weight:700; }
|
| 333 |
+
"""
|
| 334 |
+
|
| 335 |
+
with gr.Blocks(css=GLASS_CSS, title="Road2Success —Dashboard") as app:
|
| 336 |
+
gr.Markdown("<h1 style='text-align:center'>🚀 Road2Success — Dashboard</h1>")
|
| 337 |
+
gr.Markdown("<p style='text-align:center;color:#1e81b0'>Professional roadmap, AI mentor, hackathon prep & leaderboard — Colab-ready</p>")
|
| 338 |
+
|
| 339 |
+
with gr.Tabs():
|
| 340 |
+
with gr.TabItem("📚 Roadmap (Class 5 → B.Tech/NEET/JEE)"):
|
| 341 |
+
with gr.Row():
|
| 342 |
+
col1, col2 = gr.Column(scale=1), gr.Column(scale=2)
|
| 343 |
+
with col1:
|
| 344 |
+
level = gr.Dropdown(choices=list(ROADMAPS.keys()), value="Class 5", label="Select level / target")
|
| 345 |
+
quick_days = gr.Radio(choices=["30","60","90"], value="30", label="Generate 30/60/90 day plan")
|
| 346 |
+
show_btn = gr.Button("Show Roadmap & Plan")
|
| 347 |
+
with col2:
|
| 348 |
+
roadmap_html = gr.HTML()
|
| 349 |
+
plan_html = gr.HTML()
|
| 350 |
+
show_btn.click(lambda l,d: (render_roadmap(l), generate_quick_plan(l, int(d))), inputs=[level, quick_days], outputs=[roadmap_html, plan_html])
|
| 351 |
+
|
| 352 |
+
with gr.TabItem("🤖 AI Mentor (concise & helpful)"):
|
| 353 |
+
prompt = gr.Textbox(label="Ask mentor (study/hackathon tips, roadmap tweaks)", lines=3, placeholder="e.g. how to plan JEE study in 6 months?")
|
| 354 |
+
short_toggle = gr.Checkbox(label="Short answer (3 sentences)", value=True)
|
| 355 |
+
eli5_toggle = gr.Checkbox(label="Explain simply (ELI5)", value=False)
|
| 356 |
+
ask_btn = gr.Button("Ask Mentor")
|
| 357 |
+
mentor_out = gr.Textbox(lines=6, label="Mentor Answer")
|
| 358 |
+
ask_btn.click(ai_mentor_query, inputs=[prompt, short_toggle, eli5_toggle], outputs=mentor_out)
|
| 359 |
+
|
| 360 |
+
with gr.TabItem("🏆 Hackathon Prep (Pitch & Checklist)"):
|
| 361 |
+
gr.Markdown("**Pitch Generator (clear, demo-first)**")
|
| 362 |
+
idea_in = gr.Textbox(label="One-line idea", placeholder="e.g. 'AI tool to summarize messy meeting notes'")
|
| 363 |
+
team_in = gr.Textbox(label="Team name (optional)")
|
| 364 |
+
impact_in = gr.Textbox(label="One-line impact/beneficiary (optional)")
|
| 365 |
+
pitch_btn = gr.Button("Generate Pro Pitch")
|
| 366 |
+
pitch_out = gr.Markdown()
|
| 367 |
+
pitch_btn.click(generate_pitch_pro, inputs=[idea_in, team_in, impact_in], outputs=pitch_out)
|
| 368 |
+
|
| 369 |
+
gr.Markdown("**Checklist & Countdown**")
|
| 370 |
+
checklist_box = gr.Textbox(value=quick_checklist(), interactive=False, lines=6)
|
| 371 |
+
iso_date = gr.Textbox(label="Submission ISO date (YYYY-MM-DDTHH:MM)", value=(datetime.datetime.now()+datetime.timedelta(days=7)).isoformat(timespec='minutes'))
|
| 372 |
+
countdown_btn = gr.Button("Get Countdown")
|
| 373 |
+
countdown_out = gr.Textbox()
|
| 374 |
+
countdown_btn.click(countdown_to, inputs=iso_date, outputs=countdown_out)
|
| 375 |
+
|
| 376 |
+
with gr.TabItem("💼 Internships & 🔍 Hackathons"):
|
| 377 |
+
with gr.Row():
|
| 378 |
+
with gr.Column():
|
| 379 |
+
intern_query = gr.Textbox(label="Internship search (role/keyword)", value="intern")
|
| 380 |
+
intern_btn = gr.Button("Fetch Internships")
|
| 381 |
+
intern_out = gr.Textbox(lines=8)
|
| 382 |
+
with gr.Column():
|
| 383 |
+
hack_kw = gr.Textbox(label="Hackathon keyword (optional)", value="")
|
| 384 |
+
hack_btn = gr.Button("Fetch Hackathons")
|
| 385 |
+
hack_out = gr.Textbox(lines=8)
|
| 386 |
+
intern_btn.click(fetch_internships_remotive, inputs=intern_query, outputs=intern_out)
|
| 387 |
+
hack_btn.click(fetch_hackathons_devpost, inputs=hack_kw, outputs=hack_out)
|
| 388 |
+
|
| 389 |
+
with gr.TabItem("🧠 Quiz Arena & Leaderboard"):
|
| 390 |
+
gr.Markdown("Quick quiz — records score to leaderboard.")
|
| 391 |
+
name_in = gr.Textbox(label="Your name for leaderboard", placeholder="e.g. Shiva Kumar")
|
| 392 |
+
q1 = gr.Radio(SAMPLE_QUIZ[0][1], label=SAMPLE_QUIZ[0][0])
|
| 393 |
+
q2 = gr.Radio(SAMPLE_QUIZ[1][1], label=SAMPLE_QUIZ[1][0])
|
| 394 |
+
q3 = gr.Radio(SAMPLE_QUIZ[2][1], label=SAMPLE_QUIZ[2][0])
|
| 395 |
+
submit_quiz = gr.Button("Submit Quiz & Save Score")
|
| 396 |
+
result_box = gr.Textbox(label="Result")
|
| 397 |
+
leaderboard_md = gr.Markdown(show_leaderboard())
|
| 398 |
+
submit_quiz.click(fn=grade_and_record, inputs=[name_in, q1, q2, q3], outputs=result_box)
|
| 399 |
+
|
| 400 |
+
submit_quiz.click(fn=lambda: gr.update(value=show_leaderboard()), outputs=leaderboard_md)
|
| 401 |
+
|
| 402 |
+
|
| 403 |
+
app.launch(share=True)
|