Assessment / app.py
Ujeshhh's picture
Create app.py
1284607 verified
# skill_assessment_tool/app.py
import ast
from textblob import TextBlob
from transformers import pipeline
import gradio as gr
# Coding Test Analyzer
def analyze_code(code_str):
try:
tree = ast.parse(code_str)
complexity = sum(1 for node in ast.walk(tree) if isinstance(node, ast.For))
return {"syntax": "valid", "complexity": complexity, "score": min(100, 90 - complexity * 5)}
except SyntaxError:
return {"syntax": "invalid", "complexity": 0, "score": 20}
# Video Interview Analyzer (simplified, assumes text input)
def analyze_video_response(text):
blob = TextBlob(text)
sentiment = blob.sentiment.polarity # -1 to 1
comm_score = max(50, int((sentiment + 1) * 50)) # Normalize to 0-100
return {"communication": comm_score, "confidence": comm_score - 10}
# Behavioral Response Analyzer
def analyze_behavioral_response(text):
classifier = pipeline("sentiment-analysis", model="distilbert-base-uncased-finetuned-sst-2-english")
result = classifier(text)[0]
adapt_score = 80 if result["label"] == "POSITIVE" else 60
return {"adaptability": adapt_score}
# Report Generator
def generate_report(tech_score, comm_score, adapt_score):
return {
"Technical Skills": tech_score,
"Communication": comm_score,
"Adaptability": adapt_score,
"Overall": round((tech_score + comm_score + adapt_score) / 3, 2)
}
# Main function for Gradio
def assess_candidate(code, video_text, behavioral_text):
code_result = analyze_code(code)
video_result = analyze_video_response(video_text)
behavioral_result = analyze_behavioral_response(behavioral_text)
report = generate_report(
code_result["score"],
video_result["communication"],
behavioral_result["adaptability"]
)
# Return as a formatted string (Gradio outputs text or UI elements)
output = (
f"Report:\n"
f"Technical Skills: {report['Technical Skills']}/100\n"
f"Communication: {report['Communication']}/100\n"
f"Adaptability: {report['Adaptability']}/100\n"
f"Overall: {report['Overall']}/100\n\n"
f"Details:\n"
f"Code Analysis: {code_result}\n"
f"Video Analysis: {video_result}\n"
f"Behavioral Analysis: {behavioral_result}"
)
return output
# Gradio Interface
interface = gr.Interface(
fn=assess_candidate,
inputs=[
gr.Textbox(lines=5, label="Coding Test Submission", placeholder="Paste your Python code here..."),
gr.Textbox(lines=3, label="Video Interview Response", placeholder="Type your response (e.g., transcribed video)..."),
gr.Textbox(lines=3, label="Behavioral Response", placeholder="How do you handle team conflict?...")
],
outputs=gr.Textbox(label="Assessment Report"),
title="Skill Assessment Tool",
description="Enter code, video response, and behavioral text to get a skill assessment report."
)
# Launch the app
interface.launch(server_name="0.0.0.0", server_port=7860)