Spaces:
Sleeping
Sleeping
File size: 20,413 Bytes
465ab9e 948f6d6 f7c231c abbbad3 f7c231c 67fc006 7d52299 0d7271d 7d52299 eae00f4 67fc006 7d52299 0f08973 7d52299 0f08973 eae00f4 7d52299 67fc006 7d52299 379a41b 7d52299 67fc006 7d52299 379a41b 7d52299 67fc006 7d52299 67fc006 7d52299 67fc006 7d52299 379a41b 7d52299 67fc006 7d52299 67fc006 7d52299 379a41b 7d52299 67fc006 7d52299 4d4f634 67fc006 7d52299 379a41b 67fc006 379a41b 74c1465 67fc006 7d52299 379a41b 7d52299 67fc006 7d52299 379a41b 7d52299 379a41b 67fc006 8e89e2d 67fc006 379a41b 67fc006 7d52299 379a41b 67fc006 379a41b 0f08973 379a41b 67fc006 379a41b 67fc006 379a41b 67fc006 379a41b 67fc006 379a41b 67fc006 2f9077e f3439bd 67fc006 b91a459 67fc006 |
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 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 |
import gradio as gr
from huggingface_hub import InferenceClient
from sentence_transformers import SentenceTransformer
import torch
# Theme
theme = gr.themes.Soft(
primary_hue="cyan", # ocean blue
secondary_hue="blue", # deeper ocean accent
neutral_hue="slate", # cool, balanced gray tone
)
custom_css = """
:root {
--background-fill-primary: #C9361C !important;
}
.dark {
--background-fill-primary: #C9361C !important;
}
"""
# Load research file
with open("research.txt", "r", encoding="utf-8") as file:
research_text = file.read()
# Preprocess text
def preprocess_text(text):
cleaned_text = text.strip()
chunks = cleaned_text.split("\n")
cleaned_chunks = [chunk.strip() for chunk in chunks if chunk.strip() != ""]
return cleaned_chunks
cleaned_chunks = preprocess_text(research_text)
# Create embeddings
model = SentenceTransformer('all-MiniLM-L6-v2')
def create_embeddings(text_chunks):
chunk_embeddings = model.encode(text_chunks, convert_to_tensor=True)
return chunk_embeddings
chunk_embeddings = create_embeddings(cleaned_chunks)
# Get top chunks
def get_top_chunks(query, chunk_embeddings, text_chunks):
query_embedding = model.encode(query, convert_to_tensor=True)
query_embedding_normalized = query_embedding / query_embedding.norm()
chunk_embeddings_normalized = chunk_embeddings / chunk_embeddings.norm(dim=1, keepdim=True)
similarities = torch.matmul(chunk_embeddings_normalized, query_embedding_normalized)
top_indices = torch.topk(similarities, k=3).indices
top_chunks = [text_chunks[i] for i in top_indices]
return top_chunks
# Inference client
client = InferenceClient("Qwen/Qwen2.5-72B-Instruct")
def respond(message, history):
top_results = get_top_chunks(message, chunk_embeddings, cleaned_chunks)
str_top_results = '\n'.join(top_results)
messages = [
{'role': 'system', 'content': f'You are a chatbot. Complete all your sentences, do not be blunt, and do not cut yourself off. The word limit is 100 words. Start off by giving a career in a complete, kind sentence, and then if prompted by the user provide more information like salary, college course,etc. Base your response on the provided context:\n{str_top_results}'}
]
if history:
messages.extend(history)
messages.append({'role': 'user', 'content': message})
response = client.chat_completion(
messages,
max_tokens=1000,
temperature=0.2
)
return response['choices'][0]['message']['content'].strip()
def display_image():
return "KWKbanner.png"
# Explore Page Info
def show_info(topic):
responses = {
"Highest Paying STEM Jobs": "1. AI/Machine Learning Engineer β $171,774\n2. Cloud Solutions Architect β $150,241\n3. Quantitative Analyst (Quant) β $139,949\n4. Data Scientist β $128,115\n5. Actuary β $128,147",
"Most Flexible STEM Jobs": "1. Software Developer\n2. Cloud Solutions Architect\n3. Data Scientist\n4. Cybersecurity Analyst\n5. Statistician",
"Most Creative STEM Jobs": "1. Software Developer\n2. AI/Machine Learning Engineer\n3. Biomedical Engineer\n4. Mechanical Engineer\n5. Biochemist",
"Fastest Growing STEM Jobs": "1. AI/Machine Learning Engineer\n2. Cybersecurity Analyst\n3. Data Scientist\n4. Software Developer\n5. Cloud Solutions Architect",
"Low-Stress STEM Jobs": "1. Statistician\n2. Mathematician\n3. Operations Research Analyst\n4. Environmental Scientist\n5. Biochemist"
}
return responses.get(topic, "Select a category to see the corresponding careers.")
# Resources Page Info - UPDATED
def resource_block(career):
resources = {
"AI/Machine Learning Engineer": {
"links": [
("Neural Networks β DeepLearning.AI", "https://www.deeplearning.ai"),
("Build ML Models β Fast.ai", "https://www.fast.ai"),
("Machine Learning β Stanford CS229", "https://cs229.stanford.edu/")
],
"college": {
"major": "Computer Science, Data Science",
"classes": [
"CS50: Introduction to Computer Science (Harvard)",
"Linear Algebra",
"Probability and Statistics",
"Machine Learning (Stanford CS229)",
"Algorithms"
]
}
},
"Data Scientist": {
"links": [
("Python & Pandas β Kaggle Learn", "https://www.kaggle.com/learn"),
("R Programming β Harvard Data Science", "https://online-learning.harvard.edu/series/data-science"),
("Project Practice β DataCamp", "https://www.datacamp.com")
],
"college": {
"major": "Data Science, Statistics, Computer Science",
"classes": [
"Introduction to Data Science",
"Statistics and Probability",
"Data Mining",
"Machine Learning",
"Database Systems"
]
}
},
"Cloud Solutions Architect": {
"links": [
("AWS Skills β AWS Training", "https://aws.amazon.com/training/"),
("Azure Certifications β Microsoft Learn", "https://learn.microsoft.com/en-us/certifications/"),
("Google Cloud Labs β Google Cloud Boost", "https://cloudskillsboost.google/")
],
"college": {
"major": "Computer Science, Information Technology",
"classes": [
"Cloud Computing Fundamentals",
"Computer Networks",
"Systems Design",
"Information Security",
"Operating Systems"
]
}
},
"Cybersecurity Analyst": {
"links": [
("Network Security β Cybrary", "https://www.cybrary.it"),
("Threat Intelligence β MITRE ATT&CK", "https://attack.mitre.org/"),
("Ethical Hacking β TryHackMe", "https://tryhackme.com")
],
"college": {
"major": "Cybersecurity, Computer Science, Information Security",
"classes": [
"Network Security",
"Cryptography",
"Ethical Hacking",
"Operating Systems",
"Incident Response"
]
}
},
"Statistician": {
"links": [
("Intro to Statistics β Coursera (R)", "https://www.coursera.org/specializations/statistics"),
("Probability β Khan Academy", "https://www.khanacademy.org/math/statistics-probability"),
("Statistical Tools β OpenIntro", "https://www.openintro.org/book/os/")
],
"college": {
"major": "Statistics, Mathematics",
"classes": [
"Probability Theory",
"Statistical Inference",
"Regression Analysis",
"Experimental Design",
"Data Analysis with R"
]
}
},
"Biomedical Engineer": {
"links": [
("Biomedical Research β JHU BME", "https://www.bme.jhu.edu/"),
("Medical Devices β edX Courses", "https://www.edx.org/learn/biomedical-engineering"),
("Clinical Trials β NIH", "https://www.nih.gov/")
],
"college": {
"major": "Biomedical Engineering, Bioengineering",
"classes": [
"Biomaterials",
"Human Physiology",
"Medical Instrumentation",
"Biomechanics",
"Tissue Engineering"
]
}
},
"Mechanical Engineer": {
"links": [
("CAD Design β Coursera", "https://www.coursera.org/learn/cad-design"),
("Thermodynamics β MIT OpenCourseWare", "https://ocw.mit.edu/courses/thermodynamics"),
("Materials Science Basics β edX", "https://www.edx.org/course/material-science")
],
"college": {
"major": "Mechanical Engineering",
"classes": [
"Thermodynamics",
"Fluid Mechanics",
"Materials Science",
"Computer-Aided Design (CAD)",
"Dynamics and Control"
]
}
},
"Environmental Scientist": {
"links": [
("Environmental Science β Khan Academy", "https://www.khanacademy.org/science/biology/ecology"),
("GIS Basics β Esri Training", "https://www.esri.com/training/catalog/57630435851d31e02a43f1c5/gis-basics/"),
("Data Analysis β Coursera", "https://www.coursera.org/learn/data-analysis")
],
"college": {
"major": "Environmental Science, Ecology",
"classes": [
"Ecology",
"Environmental Chemistry",
"Geographic Information Systems (GIS)",
"Data Analysis",
"Environmental Policy"
]
}
},
"Operations Research Analyst": {
"links": [
("Linear Programming β Khan Academy", "https://www.khanacademy.org/computing/computer-science/algorithms"),
("Optimization β MIT OpenCourseWare", "https://ocw.mit.edu/courses/optimization-methods"),
("Statistics β Harvard Online", "https://online-learning.harvard.edu/course/statistics-and-r")
],
"college": {
"major": "Operations Research, Applied Mathematics",
"classes": [
"Optimization Theory",
"Linear Programming",
"Probability",
"Statistics",
"Simulation Modeling"
]
}
},
"Mathematician": {
"links": [
("Abstract Algebra β MIT OpenCourseWare", "https://ocw.mit.edu/courses/abstract-algebra"),
("Calculus β Khan Academy", "https://www.khanacademy.org/math/calculus-1"),
("Proof Techniques β Coursera", "https://www.coursera.org/learn/proofs")
],
"college": {
"major": "Mathematics",
"classes": [
"Algebra",
"Calculus",
"Real Analysis",
"Abstract Algebra",
"Proof Writing"
]
}
},
"Chemical Engineer": {
"links": [
("Chemical Process Principles β MIT OCW", "https://ocw.mit.edu/courses/chemical-engineering"),
("Organic Chemistry β Khan Academy", "https://www.khanacademy.org/science/organic-chemistry"),
("Thermodynamics β Coursera", "https://www.coursera.org/learn/thermodynamics")
],
"college": {
"major": "Chemical Engineering",
"classes": [
"Organic Chemistry",
"Thermodynamics",
"Process Design",
"Fluid Mechanics",
"Chemical Reaction Engineering"
]
}
},
"Civil Engineer": {
"links": [
("Structural Analysis β Coursera", "https://www.coursera.org/learn/structural-analysis"),
("Construction Management β edX", "https://www.edx.org/course/construction-management"),
("AutoCAD β LinkedIn Learning", "https://www.linkedin.com/learning/topics/autocad")
],
"college": {
"major": "Civil Engineering",
"classes": [
"Structural Analysis",
"Construction Materials",
"Soil Mechanics",
"AutoCAD",
"Hydraulics"
]
}
},
"Electrical Engineer": {
"links": [
("Circuits and Electronics β MIT OCW", "https://ocw.mit.edu/courses/electrical-engineering-and-computer-science"),
("Signals and Systems β Coursera", "https://www.coursera.org/learn/signals-systems"),
("Electromagnetics β Khan Academy", "https://www.khanacademy.org/science/electrical-engineering")
],
"college": {
"major": "Electrical Engineering",
"classes": [
"Circuits",
"Signals and Systems",
"Electromagnetics",
"Control Systems",
"Digital Logic Design"
]
}
},
"Software Developer": {
"links": [
("CS50 β Harvard", "https://cs50.harvard.edu"),
("Learn to Code β Codecademy", "https://www.codecademy.com/catalog/subject/all"),
("Algorithms β Coursera", "https://www.coursera.org/learn/algorithms-part1")
],
"college": {
"major": "Computer Science, Software Engineering",
"classes": [
"Introduction to Computer Science (CS50)",
"Data Structures and Algorithms",
"Operating Systems",
"Software Engineering",
"Databases"
]
}
},
"Pharmacist": {
"links": [
("Pharmacology Basics β Coursera", "https://www.coursera.org/learn/pharmacology"),
("Drug Development β edX", "https://www.edx.org/course/drug-development"),
("Pharmacy Practice β FutureLearn", "https://www.futurelearn.com/courses/pharmacy-practice")
],
"college": {
"major": "Pharmacy, Pharmaceutical Sciences",
"classes": [
"Pharmacology",
"Medicinal Chemistry",
"Pharmaceutical Calculations",
"Pharmaceutics",
"Clinical Pharmacy"
]
}
},
"Physicist": {
"links": [
("Classical Mechanics β MIT OCW", "https://ocw.mit.edu/courses/physics"),
("Quantum Mechanics β edX", "https://www.edx.org/course/quantum-mechanics"),
("Thermodynamics β Khan Academy", "https://www.khanacademy.org/science/physics/thermodynamics")
],
"college": {
"major": "Physics",
"classes": [
"Classical Mechanics",
"Quantum Mechanics",
"Thermodynamics",
"Electromagnetism",
"Mathematical Methods for Physicists"
]
}
},
"Astronomer": {
"links": [
("Introduction to Astronomy β Coursera", "https://www.coursera.org/learn/astronomy"),
("Astrophysics β edX", "https://www.edx.org/course/astrophysics"),
("Cosmology β Khan Academy", "https://www.khanacademy.org/science/cosmology-and-astronomy")
],
"college": {
"major": "Astronomy, Astrophysics, Physics",
"classes": [
"Introduction to Astronomy",
"Astrophysics",
"Cosmology",
"Observational Astronomy",
"Data Analysis in Astronomy"
]
}
},
"Geologist": {
"links": [
("Physical Geology β OpenStax", "https://openstax.org/details/books/physical-geology"),
("Geochemistry β Coursera", "https://www.coursera.org/learn/geochemistry"),
("GIS Mapping β Esri Training", "https://www.esri.com/training/catalog/57630435851d31e02a43f1c5/gis-basics/")
],
"college": {
"major": "Geology, Earth Science",
"classes": [
"Physical Geology",
"Mineralogy and Petrology",
"Geochemistry",
"GIS and Remote Sensing",
"Structural Geology"
]
}
},
"Biochemist": {
"links": [
("Biochemistry β MIT OCW", "https://ocw.mit.edu/courses/biochemistry"),
("Molecular Biology β Coursera", "https://www.coursera.org/learn/molecular-biology"),
("Enzymology β Khan Academy", "https://www.khanacademy.org/science/biology")
],
"college": {
"major": "Biochemistry, Molecular Biology",
"classes": [
"General Biochemistry",
"Molecular Biology",
"Enzymology",
"Cell Biology",
"Genetics"
]
}
}
}
content = resources.get(career)
if not content:
return "Select a career to see resources.", ""
link_html = "<ul>"
for label, url in content["links"]:
link_html += f'<li><strong>{label}</strong>: <a href="{url}" target="_blank">{url}</a></li>'
link_html += "</ul>"
college_html = ""
if "college" in content:
college = content["college"]
college_html += "<p><strong>College & Classes</strong></p><ul>"
college_html += f"<li><em>Common Major(s):</em> {college['major']}</li>"
classes_list = college.get("classes", [])
if isinstance(classes_list, list):
classes_html = ", ".join(classes_list)
else:
classes_html = str(classes_list)
college_html += f"<li><em>Helpful College Classes:</em> {classes_html}</li>"
college_html += "</ul>"
# No video iframe, just empty string for second output
return link_html + college_html, ""
# UI Layout
with gr.Blocks(theme=theme, css=custom_css) as chatbot:
gr.Image(display_image)
with gr.Tab("ChatBot"):
gr.ChatInterface(
respond,
type="messages",
title="Hi, I am your basketball chatbot",
textbox=gr.Textbox(placeholder="Hi ask me any questions."),
description='This tool provides information on STEM Careers. All information is sourced from [census.gov](https://www.census.gov/).'
)
with gr.Tab("Explore Now"): # β
Changed title
gr.Markdown("### Explore STEM Career Categories")
dropdown_explore = gr.Dropdown(
choices=[
"Highest Paying STEM Jobs",
"Most Flexible STEM Jobs",
"Most Creative STEM Jobs",
"Fastest Growing STEM Jobs",
"Low-Stress STEM Jobs"
],
label="Choose a Category"
)
output_explore = gr.Markdown()
dropdown_explore.change(fn=show_info, inputs=dropdown_explore, outputs=output_explore)
with gr.Tab("Resources"):
gr.Markdown("### Career-Specific Educational Resources")
dropdown_resources = gr.Dropdown(
choices=[
"AI/Machine Learning Engineer",
"Data Scientist",
"Cloud Solutions Architect",
"Cybersecurity Analyst",
"Statistician",
"Biomedical Engineer",
"Mechanical Engineer",
"Environmental Scientist",
"Operations Research Analyst",
"Mathematician",
"Chemical Engineer",
"Civil Engineer",
"Electrical Engineer",
"Software Developer",
"Pharmacist",
"Physicist",
"Astronomer",
"Geologist",
"Biochemist"
],
label="Choose a Career"
)
output_links = gr.HTML()
output_video = gr.HTML()
dropdown_resources.change(
fn=resource_block,
inputs=dropdown_resources,
outputs=[output_links, output_video]
)
chatbot.launch()
|