|
|
import os |
|
|
import gradio as gr |
|
|
import whisper |
|
|
import re |
|
|
import datetime |
|
|
import pandas as pd |
|
|
import google.generativeai as genai |
|
|
|
|
|
|
|
|
genai.configure(api_key="AIzaSyAeNCjKJVCT0gmQRAPq4NltXkc-1zELH28") |
|
|
model = genai.GenerativeModel("gemini-1.5-flash-latest") |
|
|
asr_model = whisper.load_model("base") |
|
|
|
|
|
|
|
|
session = { |
|
|
"username": "", |
|
|
"company": "", |
|
|
"role": "", |
|
|
"questions": [], |
|
|
"index": 0, |
|
|
"feedback": [], |
|
|
"interview_done": False |
|
|
} |
|
|
|
|
|
|
|
|
public_data = pd.DataFrame([ |
|
|
{"Username": "Flipkart employee", "Company": "amazon", "Role": "services", "Date": "2025-05-27", "Tone (%)": 60, "Vocabulary (%)": 50, "Grammar (%)": 40, "Technical (%)": 30}, |
|
|
{"Username": "NIELT", "Company": "Dmart", "Role": "Marketing and Sales Funnel", "Date": "2025-05-22", "Tone (%)": 74, "Vocabulary (%)": 70, "Grammar (%)": 76, "Technical (%)": 69}, |
|
|
{"Username": "AIML Saddi", "Company": "Nykaa", "Role": "Product Manager", "Date": "2025-05-27", "Tone (%)": 86, "Vocabulary (%)": 79, "Grammar (%)": 81, "Technical (%)": 88}, |
|
|
{"Username": "AIML Deepanshu", "Company": "Unilever", "Role": "Brand Manager", "Date": "2025-05-27", "Tone (%)": 80, "Vocabulary (%)": 78, "Grammar (%)": 83, "Technical (%)": 82}, |
|
|
{"Username": "Rahul Ropar", "Company": "Godrej", "Role": "B2B Sales", "Date": "2025-05-23", "Tone (%)": 72, "Vocabulary (%)": 75, "Grammar (%)": 69, "Technical (%)": 65}, |
|
|
{"Username": "Vidit789", "Company": "Amazon", "Role": "Cloud Security Analyst", "Date": "2025-05-23", "Tone (%)": 90, "Vocabulary (%)": 82, "Grammar (%)": 87, "Technical (%)": 91}, |
|
|
{"Username": "DSP Dev", "Company": "Tesla", "Role": "Autopilot QA", "Date": "2025-05-22", "Tone (%)": 84, "Vocabulary (%)": 77, "Grammar (%)": 81, "Technical (%)": 79} |
|
|
]) |
|
|
|
|
|
|
|
|
def start_interview(username, company, role): |
|
|
if not username or not company or not role: |
|
|
return "β Please fill all fields first." |
|
|
session.update({ |
|
|
"username": username, |
|
|
"company": company, |
|
|
"role": role, |
|
|
"questions": [], |
|
|
"index": 0, |
|
|
"feedback": [], |
|
|
"interview_done": False |
|
|
}) |
|
|
greeting = ( |
|
|
"Hello, I am Mrinankush Dutta.\n\n" |
|
|
"Welcome to your AI Mock interview session.\n\n" |
|
|
"This Mock interview provides tailored support for interviewees in real time.\n\n" |
|
|
"Just focus on being yourself. We will handle the rest." |
|
|
) |
|
|
return greeting |
|
|
|
|
|
|
|
|
def generate_questions(): |
|
|
if not session["company"] or not session["role"]: |
|
|
return "β Please complete setup first." |
|
|
prompt = f"Generate 13 internship interview questions (8 technical and 5 behavioral) for the role of {session['role']} at {session['company']}. Number them 1 to 13." |
|
|
response = model.generate_content(prompt) |
|
|
session["questions"] = re.findall(r"^\d+\.\s+.*", response.text.strip(), re.MULTILINE) |
|
|
return next_question() |
|
|
|
|
|
|
|
|
def next_question(): |
|
|
if session["index"] >= len(session["questions"]): |
|
|
session["interview_done"] = True |
|
|
return "Interview complete. Click 'Finish' to view feedback." |
|
|
return session["questions"][session["index"]] |
|
|
|
|
|
|
|
|
def process_answer(audio): |
|
|
if audio is None: |
|
|
return "β Please record your answer." |
|
|
result = asr_model.transcribe(audio) |
|
|
transcript = result["text"] |
|
|
q = session["questions"][session["index"]] |
|
|
session["index"] += 1 |
|
|
prompt = ( |
|
|
f"Interview Question: {q}\n" |
|
|
f"Answer: {transcript}\n\n" |
|
|
"Evaluate the following in percentage:\n" |
|
|
"Tone, Grammar, Vocabulary, and Technical correctness.\n" |
|
|
"Respond in this format:\n" |
|
|
"Tone: %\nGrammar: %\nVocabulary: %\nTechnical: %" |
|
|
) |
|
|
feedback = model.generate_content(prompt).text.strip() |
|
|
session["feedback"].append({"question": q, "answer": transcript, "feedback": feedback}) |
|
|
return "β
Answer recorded." |
|
|
|
|
|
|
|
|
def feedback_summary(): |
|
|
session["interview_done"] = True |
|
|
summary = "" |
|
|
for i, entry in enumerate(session["feedback"], 1): |
|
|
summary += f"Q{i}: {entry['question']}\nAnswer: {entry['answer']}\n{entry['feedback']}\n{'-'*40}\n" |
|
|
return summary |
|
|
|
|
|
|
|
|
def make_public(share_decision): |
|
|
if not session["interview_done"]: |
|
|
return "β Complete interview first." |
|
|
if share_decision.lower() != "yes": |
|
|
return "β
Interview ended. Your data was not shared publicly." |
|
|
last_feedback = session["feedback"][-1]["feedback"] |
|
|
tone = re.search(r"Tone:\s*(\d+)%", last_feedback) |
|
|
grammar = re.search(r"Grammar:\s*(\d+)%", last_feedback) |
|
|
vocab = re.search(r"Vocabulary:\s*(\d+)%", last_feedback) |
|
|
tech = re.search(r"Technical:\s*(\d+)%", last_feedback) |
|
|
today = datetime.date.today().strftime("%Y-%m-%d") |
|
|
new_row = { |
|
|
"Username": session["username"], |
|
|
"Company": session["company"], |
|
|
"Role": session["role"], |
|
|
"Date": today, |
|
|
"Tone (%)": int(tone.group(1)) if tone else 70, |
|
|
"Vocabulary (%)": int(vocab.group(1)) if vocab else 70, |
|
|
"Grammar (%)": int(grammar.group(1)) if grammar else 70, |
|
|
"Technical (%)": int(tech.group(1)) if tech else 70 |
|
|
} |
|
|
global public_data |
|
|
public_data.loc[len(public_data)] = new_row |
|
|
return "β
Your analysis has been shared publicly." |
|
|
|
|
|
|
|
|
def show_public(): |
|
|
if not session["interview_done"]: |
|
|
return public_data.iloc[0:0] |
|
|
return public_data |
|
|
|
|
|
|
|
|
with gr.Blocks(theme=gr.themes.Soft()) as demo: |
|
|
gr.Markdown("# π§ AI MOCK INTERVIEW BUDDY") |
|
|
|
|
|
uname = gr.Textbox(label="π€ Unique Username") |
|
|
comp = gr.Textbox(label="π’ Company") |
|
|
role = gr.Textbox(label="π― Role") |
|
|
start_btn = gr.Button("π Start Interview") |
|
|
greet = gr.Textbox(label="Greeting") |
|
|
start_btn.click(start_interview, inputs=[uname, comp, role], outputs=greet) |
|
|
|
|
|
gen_btn = gr.Button("π Generate Questions") |
|
|
qbox = gr.Textbox(label="Current Question") |
|
|
gen_btn.click(generate_questions, outputs=qbox) |
|
|
|
|
|
record = gr.Audio(sources=["microphone"], type="filepath", label="π€ Record Answer") |
|
|
submit = gr.Button("β
Submit") |
|
|
result = gr.Textbox(label="Status") |
|
|
submit.click(process_answer, inputs=record, outputs=result) |
|
|
|
|
|
next_btn = gr.Button("β‘ Next Question") |
|
|
next_btn.click(next_question, outputs=qbox) |
|
|
|
|
|
final = gr.Button("π End Interview") |
|
|
fb = gr.Textbox(label="π Final Feedback", lines=15) |
|
|
final.click(feedback_summary, outputs=fb) |
|
|
|
|
|
confirm = gr.Textbox(label="Do you want to share publicly? (Yes/No)") |
|
|
share_btn = gr.Button("β Share Final Results") |
|
|
status = gr.Textbox(label="Sharing Status") |
|
|
share_btn.click(make_public, inputs=confirm, outputs=status) |
|
|
|
|
|
view = gr.Button("π£ View Public Profiles") |
|
|
public_table = gr.Dataframe(label="π§ Public Summary Table", interactive=False) |
|
|
view.click(show_public, outputs=public_table) |
|
|
|
|
|
|
|
|
if __name__ == "__main__": |
|
|
demo.launch() |
|
|
|