File size: 3,264 Bytes
a7e25b8 3726f03 376f67b a7e25b8 93f2465 a7e25b8 70e124b 93f2465 3726f03 a7e25b8 3726f03 70e124b 93f2465 a7e25b8 93f2465 a7e25b8 93f2465 a7e25b8 93f2465 a7e25b8 93f2465 a7e25b8 93f2465 a7e25b8 93f2465 a7e25b8 93f2465 a7e25b8 93f2465 3726f03 93f2465 a7e25b8 93f2465 a7e25b8 3726f03 93f2465 3726f03 a7e25b8 93f2465 a7e25b8 |
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 |
import pandas as pd
import gradio as gr
from sentence_transformers import SentenceTransformer, util
# Load dataset
df_internships = pd.read_csv("internships.csv")
# Load lightweight embedding model
model = SentenceTransformer('all-MiniLM-L6-v2')
def recommend_internships(education, skills, sector, location):
# 1. Candidate profile as a single string
candidate_text = f"Education: {education}. Skills: {', '.join(skills)}. Sector: {sector}. Location: {location}"
# 2. Compute embeddings
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)
# 3. Compute cosine similarity
cosine_scores = util.cos_sim(candidate_emb, internship_embs)[0]
# 4. Add score to dataframe
df_internships['Match Score'] = cosine_scores.cpu().numpy()
# 5. Filter by sector/location preference (optional fallback)
filtered = df_internships[
(df_internships['Sector'] == sector) &
(df_internships['Location'] == location)
]
if len(filtered) < 3:
filtered = df_internships # fallback to all internships
# 6. Sort by match score and pick top 5
top = filtered.sort_values(by='Match Score', ascending=False).head(5)
# 7. Prepare card-like recommendations
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)
# 8. Save Excel for download
top[['Title', 'Skills', 'Sector', 'Location', 'Match Score']].to_excel("output.xlsx", index=False)
return recommendations, "output.xlsx"
# Gradio UI
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()
|