maahikachitagi commited on
Commit
888c9ce
Β·
verified Β·
1 Parent(s): a9cf4c6

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +103 -51
app.py CHANGED
@@ -1,57 +1,109 @@
1
  import gradio as gr
2
- from huggingface_hub import InferenceClient
3
-
4
- client = InferenceClient("HuggingFaceH4/zephyr-7b-beta") #change LLM
5
 
 
6
  user_profile = {
7
- "interview_type": None,
8
- "field": None,
9
- "mode": "text",
10
- "stage": "select_type", # stages: select_type β†’ get_background β†’ interview β†’ done
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
11
  }
12
 
13
- def respond(message, history):
14
- global user_profile
15
-
16
- # Stage 1: Choose interview type
17
- if user_profile["stage"] == "select_type":
18
- user_profile["interview_type"] = message.lower()
19
- user_profile["stage"] = "get_background"
20
- yield f"Great! What’s your background and what field are you aiming for?"
21
- return
22
-
23
- # Stage 2: Get background info
24
- elif user_profile["stage"] == "get_background":
25
- user_profile["field"] = message
26
- user_profile["stage"] = "interview"
27
- yield f"Thanks! Let’s begin your {user_profile['interview_type']} interview. Type 'start' to begin."
28
- return
29
-
30
- # Stage 3: Start asking interview questions
31
- elif user_profile["stage"] == "interview":
32
- if message.lower() == "start":
33
- intro = f"Let’s begin! I’ll ask you questions based on a {user_profile['interview_type']} interview in {user_profile['field']}."
34
- return_stream = client.text_generation(
35
- f"Ask a good first interview question for a {user_profile['interview_type']} interview in the {user_profile['field']} field.",
36
- max_tokens=100,
37
- stream=True
38
- )
39
- for token in return_stream:
40
- yield intro + "\n\n" + token
41
- elif message.lower() == "done":
42
- user_profile["stage"] = "done"
43
- yield "Thanks for completing the interview! I’ll now evaluate your performance... (WIP)"
44
- else:
45
- messages = [{"role": "system", "content": "You are a professional interviewer. Give feedback or ask follow-up questions."}]
46
- messages.extend(history)
47
- messages.append({"role": "user", "content": message})
48
- response = ""
49
- for message in client.chat_completion(messages, max_tokens=100, stream=True):
50
- token = message.choices[0].delta.content
51
- response += token
52
- yield response
53
-
54
-
55
- chatbot = gr.ChatInterface(respond, type="messages", title="Intervu - AI Interview Practice")
56
- chatbot.launch()
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
57
 
 
 
1
  import gradio as gr
 
 
 
2
 
3
+ # In-memory user profile
4
  user_profile = {
5
+ "interview_type": "",
6
+ "field": "",
7
+ "mode": "",
8
+ "responses": []
9
+ }
10
+
11
+ # Question bank
12
+ questions = {
13
+ "technical": {
14
+ "software": [
15
+ "Can you explain a recent project where you solved a technical challenge?",
16
+ "How would you optimize a slow-running algorithm?"
17
+ ],
18
+ "general": [
19
+ "Explain Big O Notation.",
20
+ "What’s a common bug and how do you fix it?"
21
+ ]
22
+ },
23
+ "behavioral": {
24
+ "general": [
25
+ "Tell me about a time you had to overcome a challenge.",
26
+ "How do you handle feedback?"
27
+ ]
28
+ },
29
+ "college": {
30
+ "general": [
31
+ "Why do you want to attend this school?",
32
+ "What extracurricular activity means the most to you and why?"
33
+ ]
34
+ }
35
  }
36
 
37
+ # Phase 1: Choose interview type
38
+ def set_type(choice):
39
+ user_profile["interview_type"] = choice.lower()
40
+ return "Great! What’s your background and what field/role are you aiming for?"
41
+
42
+ # Phase 2: Save background
43
+ def save_background(info):
44
+ user_profile["field"] = info
45
+ return "Would you like to continue with Text, Audio, or Webcam interview?"
46
+
47
+ # Phase 3: Set mode
48
+ def set_mode(choice):
49
+ user_profile["mode"] = choice.lower()
50
+ return f"Starting {choice} interview... Type 'done' anytime to finish."
51
+
52
+ # Phase 4: Ask question
53
+ def start_interview(user_input):
54
+ if user_input.lower() == "done":
55
+ return "Interview finished! We'll provide feedback shortly."
56
+
57
+ user_profile["responses"].append(user_input)
58
+
59
+ itype = user_profile["interview_type"]
60
+ field = user_profile["field"].lower()
61
+
62
+ field_key = "software" if "software" in field else "general"
63
+ question_list = questions.get(itype, {}).get(field_key, [])
64
+
65
+ if len(user_profile["responses"]) < len(question_list):
66
+ return question_list[len(user_profile["responses"])]
67
+ else:
68
+ return "Thank you! You've completed all questions. Type 'done' to finish."
69
+
70
+ # UI construction
71
+ with gr.Blocks() as demo:
72
+ gr.Markdown("# 🎀 Welcome to Intervu")
73
+
74
+ with gr.Row():
75
+ gr.Markdown("## Step 1: Choose Interview Type")
76
+ type_out = gr.Textbox(label="Bot Response")
77
+
78
+ with gr.Row():
79
+ btn1 = gr.Button("Behavioral")
80
+ btn2 = gr.Button("Technical")
81
+ btn3 = gr.Button("College / Scholarship")
82
+
83
+ btn1.click(set_type, inputs=[], outputs=type_out, _js="() => 'Behavioral'")
84
+ btn2.click(set_type, inputs=[], outputs=type_out, _js="() => 'Technical'")
85
+ btn3.click(set_type, inputs=[], outputs=type_out, _js="() => 'College'")
86
+
87
+ gr.Markdown("## Step 2: Enter Background")
88
+ background = gr.Textbox(label="Your background + field/goal")
89
+ background_btn = gr.Button("Submit Background")
90
+ mode_out = gr.Textbox(label="Bot Response")
91
+
92
+ background_btn.click(save_background, inputs=background, outputs=mode_out)
93
+
94
+ gr.Markdown("## Step 3: Choose Mode")
95
+ btn_text = gr.Button("Text")
96
+ btn_audio = gr.Button("Audio (WIP)")
97
+ btn_webcam = gr.Button("Webcam (WIP)")
98
+ mode_feedback = gr.Textbox(label="Bot Response")
99
+
100
+ btn_text.click(set_mode, inputs=[], outputs=mode_feedback, _js="() => 'Text'")
101
+ btn_audio.click(set_mode, inputs=[], outputs=mode_feedback, _js="() => 'Audio'")
102
+ btn_webcam.click(set_mode, inputs=[], outputs=mode_feedback, _js="() => 'Webcam'")
103
+
104
+ gr.Markdown("## Step 4: Text Interview")
105
+ user_input = gr.Textbox(label="Your Response")
106
+ bot_reply = gr.Textbox(label="Bot Question")
107
+ user_input.submit(start_interview, inputs=user_input, outputs=bot_reply)
108
 
109
+ demo.launch()