Spaces:
Sleeping
Sleeping
update
Browse files
app.py
CHANGED
|
@@ -1,175 +1,43 @@
|
|
| 1 |
import gradio as gr
|
| 2 |
from huggingface_hub import InferenceClient
|
|
|
|
|
|
|
| 3 |
from sentence_transformers import SentenceTransformer
|
| 4 |
-
import torch
|
| 5 |
|
| 6 |
-
#
|
| 7 |
-
|
| 8 |
-
primary_hue="rose",
|
| 9 |
-
secondary_hue="zinc",
|
| 10 |
-
neutral_hue="pink"
|
| 11 |
-
)
|
| 12 |
|
| 13 |
-
|
| 14 |
-
:
|
| 15 |
-
|
| 16 |
-
|
| 17 |
-
|
| 18 |
-
-
|
| 19 |
}
|
| 20 |
-
"""
|
| 21 |
-
|
| 22 |
-
# Load research file
|
| 23 |
-
with open("research.txt", "r", encoding="utf-8") as file:
|
| 24 |
-
research_text = file.read()
|
| 25 |
-
|
| 26 |
-
# Preprocess text
|
| 27 |
-
def preprocess_text(text):
|
| 28 |
-
cleaned_text = text.strip()
|
| 29 |
-
chunks = cleaned_text.split("\n")
|
| 30 |
-
cleaned_chunks = [chunk.strip() for chunk in chunks if chunk.strip() != ""]
|
| 31 |
-
return cleaned_chunks
|
| 32 |
-
|
| 33 |
-
cleaned_chunks = preprocess_text(research_text)
|
| 34 |
-
|
| 35 |
-
# Create embeddings
|
| 36 |
-
model = SentenceTransformer('all-MiniLM-L6-v2')
|
| 37 |
-
|
| 38 |
-
def create_embeddings(text_chunks):
|
| 39 |
-
chunk_embeddings = model.encode(text_chunks, convert_to_tensor=True)
|
| 40 |
-
return chunk_embeddings
|
| 41 |
-
|
| 42 |
-
chunk_embeddings = create_embeddings(cleaned_chunks)
|
| 43 |
-
|
| 44 |
-
# Get top chunks
|
| 45 |
-
def get_top_chunks(query, chunk_embeddings, text_chunks):
|
| 46 |
-
query_embedding = model.encode(query, convert_to_tensor=True)
|
| 47 |
-
query_embedding_normalized = query_embedding / query_embedding.norm()
|
| 48 |
-
chunk_embeddings_normalized = chunk_embeddings / chunk_embeddings.norm(dim=1, keepdim=True)
|
| 49 |
-
similarities = torch.matmul(chunk_embeddings_normalized, query_embedding_normalized)
|
| 50 |
-
top_indices = torch.topk(similarities, k=3).indices
|
| 51 |
-
top_chunks = [text_chunks[i] for i in top_indices]
|
| 52 |
-
return top_chunks
|
| 53 |
-
|
| 54 |
-
# Inference client
|
| 55 |
-
client = InferenceClient("Qwen/Qwen2.5-72B-Instruct")
|
| 56 |
-
|
| 57 |
-
def respond(message, history):
|
| 58 |
-
top_results = get_top_chunks(message, chunk_embeddings, cleaned_chunks)
|
| 59 |
-
str_top_results = '\n'.join(top_results)
|
| 60 |
-
messages = [
|
| 61 |
-
{'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}'}
|
| 62 |
-
]
|
| 63 |
-
if history:
|
| 64 |
-
messages.extend(history)
|
| 65 |
-
messages.append({'role': 'user', 'content': message})
|
| 66 |
|
| 67 |
-
|
| 68 |
-
messages,
|
| 69 |
-
max_tokens=1000,
|
| 70 |
-
temperature=0.2
|
| 71 |
-
)
|
| 72 |
-
return response['choices'][0]['message']['content'].strip()
|
| 73 |
|
| 74 |
-
def
|
| 75 |
-
return "
|
| 76 |
|
| 77 |
-
|
| 78 |
-
|
| 79 |
-
|
| 80 |
-
"
|
| 81 |
-
"
|
| 82 |
-
"
|
| 83 |
-
"
|
| 84 |
-
"
|
| 85 |
}
|
| 86 |
-
return
|
| 87 |
-
|
| 88 |
-
# Resources Page Info (HTML + Embedded Video)
|
| 89 |
-
def resource_block(career):
|
| 90 |
-
resources = {
|
| 91 |
-
"AI/Machine Learning Engineer": {
|
| 92 |
-
"links": [
|
| 93 |
-
("DeepLearning.AI", "https://www.deeplearning.ai"),
|
| 94 |
-
("Fast.ai", "https://www.fast.ai"),
|
| 95 |
-
("Stanford CS229", "https://cs229.stanford.edu/")
|
| 96 |
-
],
|
| 97 |
-
"video": "https://www.youtube.com/embed/5NgNicANyqM"
|
| 98 |
-
},
|
| 99 |
-
"Data Scientist": {
|
| 100 |
-
"links": [
|
| 101 |
-
("Kaggle Learn", "https://www.kaggle.com/learn"),
|
| 102 |
-
("Harvard Data Science", "https://online-learning.harvard.edu/series/data-science"),
|
| 103 |
-
("DataCamp", "https://www.datacamp.com")
|
| 104 |
-
],
|
| 105 |
-
"video": "https://www.youtube.com/embed/xC-c7E5PK0Y"
|
| 106 |
-
},
|
| 107 |
-
"Cloud Solutions Architect": {
|
| 108 |
-
"links": [
|
| 109 |
-
("AWS Training", "https://aws.amazon.com/training/"),
|
| 110 |
-
("Azure Certifications", "https://learn.microsoft.com/en-us/certifications/"),
|
| 111 |
-
("Google Cloud Boost", "https://cloudskillsboost.google/")
|
| 112 |
-
],
|
| 113 |
-
"video": "https://www.youtube.com/embed/Y1OVgGIGvfc"
|
| 114 |
-
},
|
| 115 |
-
"Cybersecurity Analyst": {
|
| 116 |
-
"links": [
|
| 117 |
-
("Cybrary", "https://www.cybrary.it"),
|
| 118 |
-
("MITRE ATT&CK", "https://attack.mitre.org/"),
|
| 119 |
-
("TryHackMe", "https://tryhackme.com")
|
| 120 |
-
],
|
| 121 |
-
"video": "https://www.youtube.com/embed/9fWjKkFvQxg"
|
| 122 |
-
},
|
| 123 |
-
"Statisticians": {
|
| 124 |
-
"links": [
|
| 125 |
-
("Statistics with R (Coursera)", "https://www.coursera.org/specializations/statistics"),
|
| 126 |
-
("Khan Academy Statistics", "https://www.khanacademy.org/math/statistics-probability")
|
| 127 |
-
],
|
| 128 |
-
"video": "https://www.youtube.com/embed/xxpc-HPKN28"
|
| 129 |
-
},
|
| 130 |
-
"Biomedical Engineer": {
|
| 131 |
-
"links": [
|
| 132 |
-
("Johns Hopkins BME", "https://www.bme.jhu.edu/"),
|
| 133 |
-
("edX Biomedical Courses", "https://www.edx.org/learn/biomedical-engineering"),
|
| 134 |
-
("NIH Biomedical Research", "https://www.nih.gov/")
|
| 135 |
-
],
|
| 136 |
-
"video": "https://www.youtube.com/embed/NM5EekDaF3g"
|
| 137 |
-
}
|
| 138 |
-
}
|
| 139 |
-
|
| 140 |
-
content = resources.get(career)
|
| 141 |
-
if not content:
|
| 142 |
-
return "Select a career to see resources.", ""
|
| 143 |
-
|
| 144 |
-
link_html = "<ul>"
|
| 145 |
-
for name, url in content["links"]:
|
| 146 |
-
link_html += f'<li><a href="{url}" target="_blank">{name}</a></li>'
|
| 147 |
-
link_html += "</ul>"
|
| 148 |
-
|
| 149 |
-
video_iframe = f"""
|
| 150 |
-
<iframe width="560" height="315" src="{content['video']}"
|
| 151 |
-
title="YouTube video player" frameborder="0" allow="accelerometer; autoplay;
|
| 152 |
-
clipboard-write; encrypted-media; gyroscope; picture-in-picture; web-share" allowfullscreen></iframe>
|
| 153 |
-
"""
|
| 154 |
-
|
| 155 |
-
return link_html, video_iframe
|
| 156 |
-
|
| 157 |
-
# UI Layout
|
| 158 |
-
with gr.Blocks(theme=theme, css=custom_css) as chatbot:
|
| 159 |
-
gr.Image(display_image)
|
| 160 |
|
|
|
|
| 161 |
with gr.Tabs():
|
| 162 |
-
with gr.Tab("
|
| 163 |
-
gr.
|
| 164 |
-
respond,
|
| 165 |
-
type="messages",
|
| 166 |
-
title="Hi, I'm Path Pilot!",
|
| 167 |
-
textbox=gr.Textbox(placeholder="Share your interests and explore more on your career of choice!"),
|
| 168 |
-
description="This tool provides information on STEM Careers."
|
| 169 |
-
)
|
| 170 |
|
| 171 |
-
with gr.Tab("Explore
|
| 172 |
-
gr.Markdown("### Explore STEM Career Categories")
|
| 173 |
dropdown_explore = gr.Dropdown(
|
| 174 |
choices=[
|
| 175 |
"Highest Paying STEM Jobs",
|
|
@@ -183,8 +51,7 @@ with gr.Blocks(theme=theme, css=custom_css) as chatbot:
|
|
| 183 |
output_explore = gr.Textbox(label="Top-Ranked Jobs", interactive=False)
|
| 184 |
dropdown_explore.change(fn=show_info, inputs=dropdown_explore, outputs=output_explore)
|
| 185 |
|
| 186 |
-
with gr.Tab("Resources Page"):
|
| 187 |
-
gr.Markdown("### Career-Specific Educational Resources")
|
| 188 |
dropdown_resources = gr.Dropdown(
|
| 189 |
choices=[
|
| 190 |
"AI/Machine Learning Engineer",
|
|
@@ -196,13 +63,9 @@ with gr.Blocks(theme=theme, css=custom_css) as chatbot:
|
|
| 196 |
],
|
| 197 |
label="Choose a Career"
|
| 198 |
)
|
| 199 |
-
|
| 200 |
-
|
| 201 |
-
|
| 202 |
-
|
| 203 |
-
inputs=dropdown_resources,
|
| 204 |
-
outputs=[output_links, output_video]
|
| 205 |
-
)
|
| 206 |
|
| 207 |
-
chatbot.launch()
|
| 208 |
|
|
|
|
| 1 |
import gradio as gr
|
| 2 |
from huggingface_hub import InferenceClient
|
| 3 |
+
|
| 4 |
+
# STEP 1 FROM SEMANTIC SEARCH
|
| 5 |
from sentence_transformers import SentenceTransformer
|
| 6 |
+
import torch
|
| 7 |
|
| 8 |
+
# YOUR ORIGINAL MODEL SETUP AND FUNCTIONS (assumed preserved)
|
| 9 |
+
model = SentenceTransformer("sentence-transformers/all-MiniLM-L6-v2")
|
|
|
|
|
|
|
|
|
|
|
|
|
| 10 |
|
| 11 |
+
careers_dict = {
|
| 12 |
+
"Highest Paying STEM Jobs": ["AI/ML Engineer", "Data Scientist", "Cloud Architect"],
|
| 13 |
+
"Most Flexible STEM Jobs": ["Web Developer", "Data Analyst", "UX Designer"],
|
| 14 |
+
"Most Creative STEM Jobs": ["UX Designer", "Game Developer", "AR/VR Developer"],
|
| 15 |
+
"Fastest Growing STEM Jobs": ["AI/ML Engineer", "Cybersecurity Analyst", "Data Scientist"],
|
| 16 |
+
"Low-Stress STEM Jobs": ["Technical Writer", "Data Analyst", "Statistician"]
|
| 17 |
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 18 |
|
| 19 |
+
# RESPONSE FUNCTION
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 20 |
|
| 21 |
+
def show_info(category):
|
| 22 |
+
return "\n".join(careers_dict.get(category, ["No data available"]))
|
| 23 |
|
| 24 |
+
def resource_links(career):
|
| 25 |
+
links = {
|
| 26 |
+
"AI/Machine Learning Engineer": "Top Skills:\n1. Deep Learning - https://www.deeplearning.ai/\n2. Python Programming - https://www.learnpython.org/\n3. ML Algorithms - https://www.youtube.com/watch?v=GwIo3gDZCVQ",
|
| 27 |
+
"Data Scientist": "Top Skills:\n1. Data Visualization - https://www.kaggle.com/learn/data-visualization\n2. Python for Data Science - https://www.youtube.com/watch?v=LHBE6Q9XlzI\n3. Statistics - https://www.khanacademy.org/math/statistics-probability",
|
| 28 |
+
"Cloud Solutions Architect": "Top Skills:\n1. AWS Fundamentals - https://www.aws.training/\n2. Cloud Networking - https://www.youtube.com/watch?v=VfGW0Qiy2I0\n3. DevOps Basics - https://www.edx.org/learn/devops",
|
| 29 |
+
"Cybersecurity Analyst": "Top Skills:\n1. Threat Analysis - https://attack.mitre.org/\n2. Network Security - https://www.youtube.com/watch?v=3t4pKl5nXlI\n3. Linux Basics - https://ubuntu.com/tutorials/command-line-for-beginners",
|
| 30 |
+
"Statisticians": "Top Skills:\n1. Probability Theory - https://www.khanacademy.org/math/statistics-probability\n2. R Programming - https://www.datacamp.com/courses/free-introduction-to-r\n3. Regression Analysis - https://www.youtube.com/watch?v=ZkjP5RJLQF4",
|
| 31 |
+
"Biomedical Engineer": "Top Skills:\n1. Medical Imaging - https://www.coursera.org/learn/introduction-medical-imaging\n2. Biomechanics - https://www.youtube.com/watch?v=EZbJwaLmQxU\n3. MATLAB - https://www.mathworks.com/learn/tutorials/matlab-onramp.html"
|
| 32 |
}
|
| 33 |
+
return links.get(career, "Select a career to see resources.")
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 34 |
|
| 35 |
+
with gr.Blocks() as demo:
|
| 36 |
with gr.Tabs():
|
| 37 |
+
with gr.Tab("Chatbot"):
|
| 38 |
+
gr.Markdown("Chatbot Tab Placeholder") # Preserve original chatbot code here
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 39 |
|
| 40 |
+
with gr.Tab("Explore now"):
|
|
|
|
| 41 |
dropdown_explore = gr.Dropdown(
|
| 42 |
choices=[
|
| 43 |
"Highest Paying STEM Jobs",
|
|
|
|
| 51 |
output_explore = gr.Textbox(label="Top-Ranked Jobs", interactive=False)
|
| 52 |
dropdown_explore.change(fn=show_info, inputs=dropdown_explore, outputs=output_explore)
|
| 53 |
|
| 54 |
+
with gr.Tab("Resources Page"):
|
|
|
|
| 55 |
dropdown_resources = gr.Dropdown(
|
| 56 |
choices=[
|
| 57 |
"AI/Machine Learning Engineer",
|
|
|
|
| 63 |
],
|
| 64 |
label="Choose a Career"
|
| 65 |
)
|
| 66 |
+
output_resources = gr.Textbox(label="Recommended Resources", interactive=False)
|
| 67 |
+
dropdown_resources.change(fn=resource_links, inputs=dropdown_resources, outputs=output_resources)
|
| 68 |
+
|
| 69 |
+
demo.launch()
|
|
|
|
|
|
|
|
|
|
| 70 |
|
|
|
|
| 71 |
|