Spaces:
Running
Running
app.py updated
Browse files- __pycache__/app.cpython-310.pyc +0 -0
- __pycache__/utils.cpython-310.pyc +0 -0
- app.py +126 -1
__pycache__/app.cpython-310.pyc
ADDED
|
Binary file (6.98 kB). View file
|
|
|
__pycache__/utils.cpython-310.pyc
ADDED
|
Binary file (3.17 kB). View file
|
|
|
app.py
CHANGED
|
@@ -8,6 +8,7 @@ import docx
|
|
| 8 |
import fitz
|
| 9 |
import asyncio
|
| 10 |
from google import genai
|
|
|
|
| 11 |
load_dotenv()
|
| 12 |
|
| 13 |
CX = os.getenv("SEARCH_ENGINE_ID")
|
|
@@ -16,6 +17,30 @@ PINECONE_API_KEY=os.getenv("PINECONE_API_KEY")
|
|
| 16 |
GEMINI_API_KEY=os.getenv("GEMINI_API_KEY")
|
| 17 |
app = FastAPI()
|
| 18 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 19 |
@app.get("/get/course")
|
| 20 |
def get_course(query):
|
| 21 |
# Example search query
|
|
@@ -41,6 +66,31 @@ def get_course(query):
|
|
| 41 |
|
| 42 |
|
| 43 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 44 |
|
| 45 |
|
| 46 |
@app.post("/upload")
|
|
@@ -101,4 +151,79 @@ def ask_ai_about_resume(query, user_id):
|
|
| 101 |
"""
|
| 102 |
)
|
| 103 |
|
| 104 |
-
return {"
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 8 |
import fitz
|
| 9 |
import asyncio
|
| 10 |
from google import genai
|
| 11 |
+
from pydantic import BaseModel
|
| 12 |
load_dotenv()
|
| 13 |
|
| 14 |
CX = os.getenv("SEARCH_ENGINE_ID")
|
|
|
|
| 17 |
GEMINI_API_KEY=os.getenv("GEMINI_API_KEY")
|
| 18 |
app = FastAPI()
|
| 19 |
|
| 20 |
+
import re
|
| 21 |
+
|
| 22 |
+
|
| 23 |
+
|
| 24 |
+
class CourseRecommendation(BaseModel):
|
| 25 |
+
coursename: str
|
| 26 |
+
completiontime: str
|
| 27 |
+
|
| 28 |
+
def extract_course_info(text: str) -> CourseRecommendation:
|
| 29 |
+
# Example regex patterns – adjust these as needed based on the response format.
|
| 30 |
+
course_pattern =r'"coursename":\s*"([^"]+)"'
|
| 31 |
+
time_pattern = r"(\d+\s*-\s*\d+\s*months)"
|
| 32 |
+
|
| 33 |
+
course_match = re.search(course_pattern, text)
|
| 34 |
+
time_match = re.search(time_pattern, text)
|
| 35 |
+
|
| 36 |
+
coursename = course_match.group(1).strip() if course_match else "Unknown"
|
| 37 |
+
completiontime = time_match.group(0).strip() if time_match else "Unknown"
|
| 38 |
+
|
| 39 |
+
return CourseRecommendation(coursename=coursename, completiontime=completiontime)
|
| 40 |
+
|
| 41 |
+
|
| 42 |
+
|
| 43 |
+
|
| 44 |
@app.get("/get/course")
|
| 45 |
def get_course(query):
|
| 46 |
# Example search query
|
|
|
|
| 66 |
|
| 67 |
|
| 68 |
|
| 69 |
+
def get_course_func(query):
|
| 70 |
+
# Example search query
|
| 71 |
+
results = google_search(query, API_KEY, CX)
|
| 72 |
+
content=[]
|
| 73 |
+
|
| 74 |
+
if results:
|
| 75 |
+
for item in results.get('items', []):
|
| 76 |
+
title = item.get('title')
|
| 77 |
+
link = item.get('link')
|
| 78 |
+
snippet = item.get('snippet')
|
| 79 |
+
content_structure={}
|
| 80 |
+
|
| 81 |
+
content_structure["Course_Title"]=title
|
| 82 |
+
content_structure["Course_Link"]=link
|
| 83 |
+
content_structure["Course_Snippet"]= snippet
|
| 84 |
+
|
| 85 |
+
content.append(content_structure)
|
| 86 |
+
|
| 87 |
+
|
| 88 |
+
return content
|
| 89 |
+
|
| 90 |
+
|
| 91 |
+
|
| 92 |
+
|
| 93 |
+
|
| 94 |
|
| 95 |
|
| 96 |
@app.post("/upload")
|
|
|
|
| 151 |
"""
|
| 152 |
)
|
| 153 |
|
| 154 |
+
return {"Ai_Response":response.text}
|
| 155 |
+
|
| 156 |
+
@app.get("/recommend/courses")
|
| 157 |
+
def ask_ai_about_resume(employment_status:str,interim_role:str,desired_role:str,motivation:str,learning_preference:str,hours_spent_learning:str,challenges:str,timeframe_to_achieve_dream_role:str, user_id:str):
|
| 158 |
+
"""
|
| 159 |
+
User Profile Information for Career Development
|
| 160 |
+
|
| 161 |
+
This section defines the parameters used to gather information from the user to understand their current employment situation, learning preferences, challenges, and goals related to achieving their dream role.
|
| 162 |
+
|
| 163 |
+
Parameters:
|
| 164 |
+
|
| 165 |
+
employment_status (str):
|
| 166 |
+
A description of the user's current employment situation (e.g., "unemployed", "part-time", "full-time").
|
| 167 |
+
|
| 168 |
+
interim_role (str):
|
| 169 |
+
Indicates whether the user is willing to prepare for an interim role to gain experience and income while pursuing their dream role (e.g., "yes" or "no").
|
| 170 |
+
|
| 171 |
+
desired_role (str):
|
| 172 |
+
The role the user ultimately wishes to obtain (e.g., "Full-Stack Developer", "Data Scientist").
|
| 173 |
+
|
| 174 |
+
motivation (str):
|
| 175 |
+
The user's reasons or motivations for pursuing the desired role.
|
| 176 |
+
|
| 177 |
+
learning_preference (str):
|
| 178 |
+
Describes how the user prefers to learn new skills (e.g., "online courses", "self-study", "bootcamp").
|
| 179 |
+
|
| 180 |
+
hours_spent_learning (str or int):
|
| 181 |
+
The number of hours per day the user can dedicate to learning.
|
| 182 |
+
|
| 183 |
+
challenges (str):
|
| 184 |
+
Outlines any obstacles or challenges the user faces in reaching their dream role.
|
| 185 |
+
|
| 186 |
+
timeframe_to_achieve_dream_role (str):
|
| 187 |
+
The ideal timeframe the user has in mind for achieving their dream role (e.g., "6-12 months").
|
| 188 |
+
|
| 189 |
+
user_id (str):
|
| 190 |
+
A unique identifier for the user; used to query personalized data from a vector database or other services.
|
| 191 |
+
|
| 192 |
+
"""
|
| 193 |
+
|
| 194 |
+
|
| 195 |
+
# Retrieve context from your vector database
|
| 196 |
+
|
| 197 |
+
# Ensure that an event loop is present in this thread.
|
| 198 |
+
try:
|
| 199 |
+
loop = asyncio.get_event_loop()
|
| 200 |
+
except RuntimeError:
|
| 201 |
+
loop = asyncio.new_event_loop()
|
| 202 |
+
asyncio.set_event_loop(loop)
|
| 203 |
+
|
| 204 |
+
# Create the Gemini client after the event loop is set up
|
| 205 |
+
client = genai.Client(api_key=GEMINI_API_KEY)
|
| 206 |
+
|
| 207 |
+
response = client.models.generate_content(
|
| 208 |
+
model="gemini-2.0-flash",
|
| 209 |
+
contents=f"""
|
| 210 |
+
please respond with a JSON object that contains the following keys as a response:
|
| 211 |
+
- "coursename": the name of the recommended course,
|
| 212 |
+
- "completiontime": an estimate of how long it would take to complete the course.
|
| 213 |
+
Do not include any extra text.
|
| 214 |
+
Recommend a course using this information below :
|
| 215 |
+
Which of the following best describes you?: {employment_status}
|
| 216 |
+
Would you like to prepare for an interim role to gain experience and income while pursuing your dream job?: {interim_role}
|
| 217 |
+
What is your desired role?: {desired_role}
|
| 218 |
+
Why do you want to achieve this desired role?: {motivation}
|
| 219 |
+
How do you prefer to learn new skills?: {learning_preference}
|
| 220 |
+
How many hours per day can you dedicate to learning?: {hours_spent_learning}
|
| 221 |
+
What are the biggest challenges or obstacles you face in reaching your dream role?: {challenges}
|
| 222 |
+
What is your ideal timeframe for achieving your dream role?: {timeframe_to_achieve_dream_role}
|
| 223 |
+
|
| 224 |
+
|
| 225 |
+
"""
|
| 226 |
+
)
|
| 227 |
+
course_info = extract_course_info(response.text)
|
| 228 |
+
courses = get_course_func(query=course_info.coursename)
|
| 229 |
+
return courses
|