harshlaghave commited on
Commit
e32d554
·
verified ·
1 Parent(s): 9dca0f5

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +35 -27
app.py CHANGED
@@ -1,23 +1,17 @@
1
  import os
2
- os.environ["WANDB_DISABLED"] = "true"
3
 
4
- from fastapi import FastAPI
5
- from pydantic import BaseModel
6
  from sentence_transformers import SentenceTransformer, util
7
  import pandas as pd
8
  import numpy as np
9
 
10
- # ------------------------
11
- # FastAPI app
12
- # ------------------------
13
- app = FastAPI(title="Super-Intelligent Internship Matcher")
14
-
15
  # ------------------------
16
  # Load CSV and pre-fine-tuned model
17
  # ------------------------
18
- df = pd.read_csv("converted (1).csv")
19
  MODEL_PATH = os.path.join(os.path.dirname(__file__), "fine_tuned_internship_model")
20
- model = SentenceTransformer(MODEL_PATH) # Load pre-fine-tuned model
 
21
 
22
  # ------------------------
23
  # Normalization functions
@@ -67,23 +61,13 @@ weights = np.array([0.4,0.3,0.2,0.1]) # Skills, Education, Interest, Location
67
  intercept = 0
68
 
69
  # ------------------------
70
- # FastAPI request model
71
  # ------------------------
72
- class Candidate(BaseModel):
73
- skills: str
74
- education: str
75
- interest: str
76
- location: str
77
-
78
- # ------------------------
79
- # API endpoint
80
- # ------------------------
81
- @app.post("/match")
82
- def match_internship(candidate: Candidate):
83
- candidate_skills_input = normalize_skills(candidate.skills)
84
- candidate_education_input = normalize_text(candidate.education)
85
- candidate_interest_input = normalize_text(candidate.interest)
86
- candidate_location_input = candidate.location
87
 
88
  candidate_skill_embs_input = [model.encode(s, convert_to_tensor=True) for s in candidate_skills_input]
89
  candidate_edu_emb_input = model.encode(candidate_education_input, convert_to_tensor=True)
@@ -123,4 +107,28 @@ def match_internship(candidate: Candidate):
123
  })
124
 
125
  results.sort(key=lambda x: x['Overall_Match'], reverse=True)
126
- return {"top5": results[:5]}
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
  import os
2
+ os.environ["WANDB_DISABLED"] = "true" # Disable online logging
3
 
4
+ import gradio as gr
 
5
  from sentence_transformers import SentenceTransformer, util
6
  import pandas as pd
7
  import numpy as np
8
 
 
 
 
 
 
9
  # ------------------------
10
  # Load CSV and pre-fine-tuned model
11
  # ------------------------
 
12
  MODEL_PATH = os.path.join(os.path.dirname(__file__), "fine_tuned_internship_model")
13
+ model = SentenceTransformer(MODEL_PATH)
14
+ df = pd.read_csv("converted (1).csv")
15
 
16
  # ------------------------
17
  # Normalization functions
 
61
  intercept = 0
62
 
63
  # ------------------------
64
+ # Matching function
65
  # ------------------------
66
+ def match_internship(skills, education, interest, location):
67
+ candidate_skills_input = normalize_skills(skills)
68
+ candidate_education_input = normalize_text(education)
69
+ candidate_interest_input = normalize_text(interest)
70
+ candidate_location_input = location
 
 
 
 
 
 
 
 
 
 
71
 
72
  candidate_skill_embs_input = [model.encode(s, convert_to_tensor=True) for s in candidate_skills_input]
73
  candidate_edu_emb_input = model.encode(candidate_education_input, convert_to_tensor=True)
 
107
  })
108
 
109
  results.sort(key=lambda x: x['Overall_Match'], reverse=True)
110
+ # Return top 5 as list of dicts
111
+ return results[:5]
112
+
113
+ # ------------------------
114
+ # Gradio interface
115
+ # ------------------------
116
+ inputs = [
117
+ gr.Textbox(label="Your Skills (comma-separated)"),
118
+ gr.Textbox(label="Your Education"),
119
+ gr.Textbox(label="Your Interest / Field"),
120
+ gr.Textbox(label="Your Location")
121
+ ]
122
+
123
+ outputs = gr.JSON(label="Top 5 Internship Matches")
124
+
125
+ demo = gr.Interface(
126
+ fn=match_internship,
127
+ inputs=inputs,
128
+ outputs=outputs,
129
+ title="Super-Intelligent Internship Matcher",
130
+ description="Enter your skills, education, interest, and location to get top 5 internship matches."
131
+ )
132
+
133
+ if __name__ == "__main__":
134
+ demo.launch()