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