maahikachitagi commited on
Commit
a9cf4c6
Β·
verified Β·
1 Parent(s): 3320d93

Update app.py

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