Spaces:
Sleeping
Sleeping
Create app.py
Browse files
app.py
ADDED
@@ -0,0 +1,108 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
import gradio as gr
|
2 |
+
from openai import OpenAI
|
3 |
+
import time
|
4 |
+
|
5 |
+
def generate_questions(api_key, role, experience):
|
6 |
+
if not api_key:
|
7 |
+
return "[ERROR] Please enter your OpenRouter API key"
|
8 |
+
|
9 |
+
client = OpenAI(
|
10 |
+
base_url="https://openrouter.ai/api/v1",
|
11 |
+
api_key=api_key,
|
12 |
+
)
|
13 |
+
|
14 |
+
try:
|
15 |
+
completion = client.chat.completions.create(
|
16 |
+
extra_headers={
|
17 |
+
"HTTP-Referer": "http://localhost:7860",
|
18 |
+
"X-Title": "AI Mock Interview",
|
19 |
+
},
|
20 |
+
model="deepseek/deepseek-v3-base:free",
|
21 |
+
messages=[
|
22 |
+
{
|
23 |
+
"role": "system",
|
24 |
+
"content": "You are a professional interview coach. Generate relevant interview questions.",
|
25 |
+
},
|
26 |
+
{
|
27 |
+
"role": "user",
|
28 |
+
"content": f"Act as an interviewer for a {role} position requiring {experience} experience. Generate 5 technical questions and 3 behavioral questions. Present them in a numbered list."
|
29 |
+
}
|
30 |
+
]
|
31 |
+
)
|
32 |
+
return completion.choices[0].message.content
|
33 |
+
except Exception as e:
|
34 |
+
return f"[ERROR] API call failed: {str(e)}"
|
35 |
+
|
36 |
+
def get_feedback(api_key, questions, answer):
|
37 |
+
if not api_key:
|
38 |
+
return "[ERROR] Please enter your OpenRouter API key"
|
39 |
+
|
40 |
+
client = OpenAI(
|
41 |
+
base_url="https://openrouter.ai/api/v1",
|
42 |
+
api_key=api_key,
|
43 |
+
)
|
44 |
+
|
45 |
+
try:
|
46 |
+
completion = client.chat.completions.create(
|
47 |
+
extra_headers={
|
48 |
+
"HTTP-Referer": "http://localhost:7860",
|
49 |
+
"X-Title": "AI Mock Interview",
|
50 |
+
},
|
51 |
+
model="deepseek/deepseek-v3-base:free",
|
52 |
+
messages=[
|
53 |
+
{
|
54 |
+
"role": "system",
|
55 |
+
"content": "You are an interview coach analyzing candidate responses.",
|
56 |
+
},
|
57 |
+
{
|
58 |
+
"role": "user",
|
59 |
+
"content": f"Interview questions:\n{questions}\n\nCandidate answer:\n{answer}\n\nProvide constructive feedback focusing on: clarity, relevance, technical accuracy, and suggestions for improvement. Structure your feedback with clear sections."
|
60 |
+
}
|
61 |
+
]
|
62 |
+
)
|
63 |
+
return completion.choices[0].message.content
|
64 |
+
except Exception as e:
|
65 |
+
return f"[ERROR] API call failed: {str(e)}"
|
66 |
+
|
67 |
+
with gr.Blocks(theme=gr.themes.Soft()) as demo:
|
68 |
+
gr.Markdown("# AI Mock Interview Practice 🤖💼")
|
69 |
+
|
70 |
+
with gr.Row():
|
71 |
+
api_key = gr.Textbox(
|
72 |
+
label="OpenRouter API Key",
|
73 |
+
placeholder="Enter your API key here",
|
74 |
+
type="password"
|
75 |
+
)
|
76 |
+
|
77 |
+
with gr.Tab("Interview Setup"):
|
78 |
+
role = gr.Textbox(label="Desired Job Role")
|
79 |
+
experience = gr.Dropdown(
|
80 |
+
label="Experience Level",
|
81 |
+
choices=["Entry-level", "Mid-level", "Senior", "Executive"],
|
82 |
+
value="Mid-level"
|
83 |
+
)
|
84 |
+
generate_btn = gr.Button("Generate Interview Questions")
|
85 |
+
|
86 |
+
with gr.Tab("Practice Session"):
|
87 |
+
questions = gr.Textbox(label="Generated Questions", lines=10, interactive=False)
|
88 |
+
answer = gr.Textbox(label="Your Answer", lines=8, placeholder="Type your response here...")
|
89 |
+
feedback_btn = gr.Button("Get Feedback")
|
90 |
+
|
91 |
+
with gr.Tab("Feedback"):
|
92 |
+
feedback = gr.Textbox(label="Expert Feedback", lines=12, interactive=False)
|
93 |
+
|
94 |
+
# Event handlers
|
95 |
+
generate_btn.click(
|
96 |
+
fn=generate_questions,
|
97 |
+
inputs=[api_key, role, experience],
|
98 |
+
outputs=questions
|
99 |
+
)
|
100 |
+
|
101 |
+
feedback_btn.click(
|
102 |
+
fn=get_feedback,
|
103 |
+
inputs=[api_key, questions, answer],
|
104 |
+
outputs=feedback
|
105 |
+
)
|
106 |
+
|
107 |
+
if __name__ == "__main__":
|
108 |
+
demo.launch()
|