File size: 6,109 Bytes
e88040b c14cd7f e88040b 5cf4465 c14cd7f 5cf4465 e88040b c14cd7f e88040b c14cd7f 5cf4465 e88040b c14cd7f e88040b c14cd7f e88040b c14cd7f e88040b c14cd7f e88040b c14cd7f e88040b c14cd7f e88040b c14cd7f e88040b c14cd7f e88040b c14cd7f e88040b c14cd7f e88040b c14cd7f e88040b 5cf4465 c14cd7f e88040b c14cd7f e88040b |
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 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 |
import gradio as gr
import os
import requests
import git
import tempfile
import shutil
from openai import OpenAI
import dotenv
def generate_prompt(repos_data, role, seniority, assignment_details, focus_areas=""):
"""Generates the AI analysis prompt with multiple repo details."""
prompt = f"""
You are an AI expert in evaluating software engineering candidates based on their GitHub repositories. Your goal is to assess the quality, organization, and best practices of the submitted code repositories. Below is the candidate's information:
### Candidate Information:
- **Role Applied For**: {role}
- **Seniority Level**: {seniority}
### Guidelines:
- Focus on the candidate's ability to write clean, efficient, and maintainable code.
- Consider the seniority level when evaluating the code.
- Consider the assignment details and how the candidate responded.
### Assignment Details:
{assignment_details}
### Repository Analysis:
Below are the repositories submitted by the candidate:
{repos_data}
### Evaluation Criteria:
1. **Code Organization & Architecture**
2. **Code Quality & Best Practices**
3. **Language Proficiency & Best Practices**
4. **Use of Frameworks & Libraries**
### Optional Key Focus Areas:
{focus_areas}
### **Final Score Calculation**
- Score each repository **out of 100** and provide an overall weighted score.
- Justify the **score** by explaining the candidateβs strengths and weaknesses.
### **Expected Output:**
- **Per Repository Analysis**: A detailed breakdown of strengths and weaknesses.
- **Overall Candidate Summary**: A final evaluation of their coding skills across all repositories.
- **Final Score (0-100)**: A numeric score with justification.
"""
return prompt
# Load environment variables
dotenv.load_dotenv()
client = OpenAI()
PASSWORD = os.getenv("PASSWORD", "defaultpass")
def authenticate(password):
"""Check if the entered password is correct."""
if password != PASSWORD:
return "β Incorrect password! Access denied.", None
return None, "β
Access granted! You may proceed."
def analyze_repos(repo_urls, role, seniority, assignment_details, focus_areas, password):
auth_error, auth_success = authenticate(password)
if auth_error:
return auth_error, gr.update(visible=False) # If incorrect password, return error
"""Clone and analyze multiple GitHub repositories."""
repo_urls = [url.strip() for url in repo_urls.split(",") if url.strip()]
if not all(url.startswith("https://github.com/") for url in repo_urls):
return "β One or more URLs are invalid!", gr.update(visible=False)
temp_dir = tempfile.mkdtemp()
repos_data = ""
total_files = 0
try:
progress = gr.update(value="π Cloning repositories...", visible=True)
for repo_url in repo_urls:
repo_name = repo_url.split("/")[-1]
repo_path = os.path.join(temp_dir, repo_name)
try:
git.Repo.clone_from(repo_url, repo_path)
except Exception as e:
repos_data += f"\nβ Failed to clone `{repo_name}`: {str(e)}\n"
continue
repo_data = f"\nπ **Repository: {repo_name}**\n"
file_count = 0
for root, _, filenames in os.walk(repo_path):
for file in filenames:
file_count += 1
file_path = os.path.join(root, file)
try:
with open(file_path, "r", encoding="utf-8") as f:
file_content = f.read()
repo_data += f"\n**File {file_count}:** {file_path.replace(repo_path, '')}\n```\n{file_content[:1000]}\n```\n"
except Exception:
repo_data += f"\n**File {file_count}:** {file_path.replace(repo_path, '')} (β οΈ Cannot read binary file)\n"
repos_data += repo_data
total_files += file_count
progress = gr.update(value="π€ Sending data to AI for evaluation...", visible=True)
# AI-based evaluation
evaluation = f"β
**Evaluation for Role: {role}**\n\n"
evaluation += f"π `{len(repo_urls)}` repositories analyzed, containing `{total_files}` files.\n"
evaluation += f"π‘ Key focus areas: {focus_areas}\n\n"
evaluation += "**π Code Quality Analysis:**\n"
completion = client.chat.completions.create(
model="o1",
messages=[
{
"role": "user",
"content": generate_prompt(repos_data, role, seniority, assignment_details, focus_areas)
}
]
)
evaluation += "\n" + completion.choices[0].message.content
progress = gr.update(value="β
Analysis complete!", visible=True)
return evaluation, progress
except Exception as e:
return f"β Error analyzing repositories: {str(e)}", gr.update(visible=False)
finally:
shutil.rmtree(temp_dir) # Cleanup
# Gradio UI
with gr.Blocks() as app:
gr.Markdown("# π οΈ AI-Powered Candidate Evaluation System")
password = gr.Textbox(label="Enter Password")
role = gr.Textbox(label="Role the Candidate is Applying For")
seniority = gr.Dropdown(
["Junior", "Mid", "Senior"],
label="Seniority Level",
value="Mid"
)
assignment_details = gr.Textbox(label="Assignment Details", lines=8)
repo_urls = gr.Textbox(label="GitHub Repository URLs (comma-separated)")
focus_areas = gr.Textbox(label="Optional Focus Areas (e.g., Clean Code, Performance)")
output = gr.Markdown()
progress = gr.Markdown(visible=False) # Loader
submit_btn = gr.Button("π Evaluate")
submit_btn.click(
fn=analyze_repos,
inputs=[repo_urls, role, seniority, assignment_details, focus_areas, password],
outputs=[output, progress]
)
app.launch() |