|
import pandas as pd |
|
import gradio as gr |
|
from sentence_transformers import SentenceTransformer, util |
|
|
|
|
|
df_internships = pd.read_csv("internships.csv") |
|
|
|
|
|
model = SentenceTransformer('all-MiniLM-L6-v2') |
|
|
|
def recommend_internships(education, skills, sector, location): |
|
|
|
candidate_text = f"Education: {education}. Skills: {', '.join(skills)}. Sector: {sector}. Location: {location}" |
|
|
|
|
|
candidate_emb = model.encode(candidate_text, convert_to_tensor=True) |
|
internship_texts = df_internships['Skills'] + " " + df_internships['Sector'] + " " + df_internships['Location'] |
|
internship_embs = model.encode(list(internship_texts), convert_to_tensor=True) |
|
|
|
|
|
cosine_scores = util.cos_sim(candidate_emb, internship_embs)[0] |
|
|
|
|
|
df_internships['Match Score'] = cosine_scores.cpu().numpy() |
|
|
|
|
|
filtered = df_internships[ |
|
(df_internships['Sector'] == sector) & |
|
(df_internships['Location'] == location) |
|
] |
|
if len(filtered) < 3: |
|
filtered = df_internships |
|
|
|
|
|
top = filtered.sort_values(by='Match Score', ascending=False).head(5) |
|
|
|
|
|
recommendations = [] |
|
for _, row in top.iterrows(): |
|
card = ( |
|
f"**{row['Title']}**\n" |
|
f"Location: {row['Location']}\n" |
|
f"Sector: {row['Sector']}\n" |
|
f"Skills Required: {row['Skills']}\n" |
|
f"Match Score: {int(row['Match Score']*100)}%" |
|
) |
|
recommendations.append(card) |
|
|
|
|
|
top[['Title', 'Skills', 'Sector', 'Location', 'Match Score']].to_excel("output.xlsx", index=False) |
|
|
|
return recommendations, "output.xlsx" |
|
|
|
|
|
with gr.Blocks() as demo: |
|
gr.Markdown("## π Skill-to-Opportunity AI Navigator for PM Internship Scheme") |
|
gr.Markdown("Enter your details and get top 3β5 personalized internship recommendations.") |
|
|
|
with gr.Row(): |
|
education_input = gr.Dropdown(["High School", "Undergraduate", "Graduate", "Other"], label="Education") |
|
sector_input = gr.Dropdown(["Tech", "Governance", "NGOs"], label="Sector Interest") |
|
location_input = gr.Dropdown(["Delhi", "Bangalore", "Mumbai", "Chennai", "Hyderabad"], label="Preferred Location") |
|
|
|
skills_input = gr.CheckboxGroup( |
|
["Python","Excel","SQL","Writing","Editing","Research","Communication","Creativity","Marketing","Organizing","Planning"], |
|
label="Select Your Skills" |
|
) |
|
|
|
recommend_btn = gr.Button("Get Recommendations") |
|
|
|
recommendations_output = gr.Textbox(label="Top Internship Recommendations", lines=10) |
|
download_output = gr.File(label="Download Excel with Top Recommendations") |
|
|
|
recommend_btn.click( |
|
recommend_internships, |
|
inputs=[education_input, skills_input, sector_input, location_input], |
|
outputs=[recommendations_output, download_output] |
|
) |
|
|
|
if __name__ == "__main__": |
|
demo.launch() |
|
|