Spaces:
Configuration error
Configuration error
Upload 2 files
Browse files- utils/audio_processor.py +17 -0
- utils/text_analysis.py +79 -0
utils/audio_processor.py
ADDED
|
@@ -0,0 +1,17 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import speech_recognition as sr
|
| 2 |
+
|
| 3 |
+
def convert_audio_to_text() -> str:
|
| 4 |
+
"""Convert audio from microphone to text."""
|
| 5 |
+
recognizer = sr.Recognizer()
|
| 6 |
+
|
| 7 |
+
with sr.Microphone() as source:
|
| 8 |
+
print("Listening...")
|
| 9 |
+
audio = recognizer.listen(source)
|
| 10 |
+
|
| 11 |
+
try:
|
| 12 |
+
text = recognizer.recognize_google(audio)
|
| 13 |
+
return text
|
| 14 |
+
except sr.UnknownValueError:
|
| 15 |
+
return "Could not understand audio"
|
| 16 |
+
except sr.RequestError:
|
| 17 |
+
return "Could not request results"
|
utils/text_analysis.py
ADDED
|
@@ -0,0 +1,79 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import google.generativeai as genai
|
| 2 |
+
from typing import List, Dict
|
| 3 |
+
import os
|
| 4 |
+
from dotenv import load_dotenv
|
| 5 |
+
|
| 6 |
+
load_dotenv()
|
| 7 |
+
|
| 8 |
+
# Configure Gemini API
|
| 9 |
+
genai.configure(api_key=os.getenv('GOOGLE_API_KEY'))
|
| 10 |
+
model = genai.GenerativeModel('gemini-pro')
|
| 11 |
+
|
| 12 |
+
def extract_keywords(text: str) -> List[str]:
|
| 13 |
+
"""Extract important keywords from text using Gemini API."""
|
| 14 |
+
prompt = f"Extract important technical skills, technologies, and key requirements as keywords from this text. Return only the keywords separated by commas: {text}"
|
| 15 |
+
response = model.generate_content(prompt)
|
| 16 |
+
keywords = [k.strip() for k in response.text.split(',')]
|
| 17 |
+
return keywords
|
| 18 |
+
|
| 19 |
+
def generate_summary(text: str) -> str:
|
| 20 |
+
"""Generate a concise summary of the text using Gemini API."""
|
| 21 |
+
prompt = f"Provide a concise summary of the following text, focusing on the main points: {text}"
|
| 22 |
+
response = model.generate_content(prompt)
|
| 23 |
+
return response.text
|
| 24 |
+
|
| 25 |
+
def generate_mcqs(resume: str, job_description: str) -> List[Dict]:
|
| 26 |
+
"""Generate MCQs based on resume and job description."""
|
| 27 |
+
prompt = f"""Based on this resume: {resume}
|
| 28 |
+
And this job description: {job_description}
|
| 29 |
+
Generate 30 relevant multiple choice questions. For each question, provide:
|
| 30 |
+
1. The question
|
| 31 |
+
2. Four options (A, B, C, D)
|
| 32 |
+
3. The correct answer
|
| 33 |
+
Format each question as a dictionary with keys: 'question', 'options', 'correct_answer'
|
| 34 |
+
Return as a Python list of dictionaries."""
|
| 35 |
+
|
| 36 |
+
response = model.generate_content(prompt)
|
| 37 |
+
# Process and format the response into a list of dictionaries
|
| 38 |
+
# This is a simplified version - you'll need to parse the actual response
|
| 39 |
+
return eval(response.text)
|
| 40 |
+
|
| 41 |
+
def generate_coding_questions(resume: str, job_description: str) -> List[Dict]:
|
| 42 |
+
"""Generate coding questions based on resume and job description."""
|
| 43 |
+
prompt = f"""Based on this resume: {resume}
|
| 44 |
+
And this job description: {job_description}
|
| 45 |
+
Generate 2 coding questions with:
|
| 46 |
+
1. Problem statement
|
| 47 |
+
2. Input/Output examples
|
| 48 |
+
3. Constraints
|
| 49 |
+
4. Expected solution approach
|
| 50 |
+
Format as a list of dictionaries."""
|
| 51 |
+
|
| 52 |
+
response = model.generate_content(prompt)
|
| 53 |
+
return eval(response.text)
|
| 54 |
+
|
| 55 |
+
def analyze_interview_response(audio_text: str, job_description: str) -> Dict:
|
| 56 |
+
"""Analyze the interview response and provide feedback."""
|
| 57 |
+
prompt = f"""Analyze this interview response: {audio_text}
|
| 58 |
+
For this job description: {job_description}
|
| 59 |
+
Provide:
|
| 60 |
+
1. Overall performance score (0-100)
|
| 61 |
+
2. Strengths
|
| 62 |
+
3. Areas for improvement
|
| 63 |
+
4. Specific concepts to study
|
| 64 |
+
Return as a dictionary."""
|
| 65 |
+
|
| 66 |
+
response = model.generate_content(prompt)
|
| 67 |
+
return eval(response.text)
|
| 68 |
+
|
| 69 |
+
def get_learning_resources(concepts: List[str]) -> Dict[str, List[str]]:
|
| 70 |
+
"""Get learning resources for concepts that need improvement."""
|
| 71 |
+
prompt = f"""For these concepts: {concepts}
|
| 72 |
+
Provide high-quality learning resources including:
|
| 73 |
+
1. Online courses
|
| 74 |
+
2. Documentation
|
| 75 |
+
3. Practice platforms
|
| 76 |
+
Format as a dictionary with concept keys and resource list values."""
|
| 77 |
+
|
| 78 |
+
response = model.generate_content(prompt)
|
| 79 |
+
return eval(response.text)
|