maahikachitagi commited on
Commit
b8ba472
Β·
verified Β·
1 Parent(s): 4129a95

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +24 -17
app.py CHANGED
@@ -1,47 +1,49 @@
1
  import gradio as gr
2
  from huggingface_hub import InferenceClient
3
 
4
- # Initialize your model
5
  client = InferenceClient("HuggingFaceH4/zephyr-7b-beta")
6
 
7
- # Step 1: Set interview type
8
  def set_type(choice, user_profile):
9
  user_profile["interview_type"] = choice
10
  return "Great! What’s your background and what field/role are you aiming for?", user_profile
11
 
12
- # Step 2: Save background info
13
  def save_background(info, user_profile):
14
  user_profile["field"] = info
15
  return "Awesome! Type 'start' below to begin your interview.", user_profile
16
 
17
- # Step 3: Respond to user
18
- def respond(message, history, user_profile):
19
  if not user_profile.get("interview_type") or not user_profile.get("field"):
20
- return "Please finish steps 1 and 2 before starting the interview."
 
 
21
 
22
  messages = [
23
  {"role": "system", "content": f"You are a professional interviewer conducting a {user_profile['interview_type']} interview for a candidate in the {user_profile['field']} field."}
24
  ]
25
- if history:
26
- messages.extend(history)
 
27
  messages.append({"role": "user", "content": message})
28
 
29
  response = client.chat_completion(messages, max_tokens=150, stream=False)
30
- return response.choices[0].message.content
 
 
31
 
32
- # Build UI
33
  with gr.Blocks() as demo:
34
  user_profile = gr.State({"interview_type": "", "field": ""})
 
35
 
36
  gr.Markdown("# 🎀 Welcome to Intervu")
37
-
38
  # Step 1
39
  gr.Markdown("### Step 1: Choose Interview Type")
40
  with gr.Row():
41
- btn1 = gr.Button("Behavioral")
42
- btn2 = gr.Button("Technical")
43
- btn3 = gr.Button("College / Scholarship")
44
- type_output = gr.Textbox(label="Bot", interactive=False)
 
45
 
46
  btn1.click(set_type, inputs=[gr.Textbox(value="Behavioral", visible=False), user_profile], outputs=[type_output, user_profile])
47
  btn2.click(set_type, inputs=[gr.Textbox(value="Technical", visible=False), user_profile], outputs=[type_output, user_profile])
@@ -51,12 +53,17 @@ with gr.Blocks() as demo:
51
  gr.Markdown("### Step 2: Enter Your Background")
52
  background = gr.Textbox(label="Your background and field/goal")
53
  background_btn = gr.Button("Submit")
54
- background_output = gr.Textbox(label="Bot", interactive=False)
55
 
56
  background_btn.click(save_background, inputs=[background, user_profile], outputs=[background_output, user_profile])
57
 
58
  # Step 3
59
  gr.Markdown("### Step 3: Start Interview")
60
- chatbot = gr.ChatInterface(fn=lambda msg, hist: respond(msg, hist, user_profile.value), title="Intervu - AI Interview Practice", type="messages")
 
 
 
 
 
61
 
62
  demo.launch()
 
1
  import gradio as gr
2
  from huggingface_hub import InferenceClient
3
 
 
4
  client = InferenceClient("HuggingFaceH4/zephyr-7b-beta")
5
 
 
6
  def set_type(choice, user_profile):
7
  user_profile["interview_type"] = choice
8
  return "Great! What’s your background and what field/role are you aiming for?", user_profile
9
 
 
10
  def save_background(info, user_profile):
11
  user_profile["field"] = info
12
  return "Awesome! Type 'start' below to begin your interview.", user_profile
13
 
14
+ def respond(message, chat_history, user_profile):
 
15
  if not user_profile.get("interview_type") or not user_profile.get("field"):
16
+ bot_msg = "Please finish steps 1 and 2 before starting the interview."
17
+ chat_history.append((message, bot_msg))
18
+ return chat_history
19
 
20
  messages = [
21
  {"role": "system", "content": f"You are a professional interviewer conducting a {user_profile['interview_type']} interview for a candidate in the {user_profile['field']} field."}
22
  ]
23
+ for q, a in chat_history:
24
+ messages.append({"role": "user", "content": q})
25
+ messages.append({"role": "assistant", "content": a})
26
  messages.append({"role": "user", "content": message})
27
 
28
  response = client.chat_completion(messages, max_tokens=150, stream=False)
29
+ bot_msg = response.choices[0].message.content
30
+ chat_history.append((message, bot_msg))
31
+ return chat_history
32
 
 
33
  with gr.Blocks() as demo:
34
  user_profile = gr.State({"interview_type": "", "field": ""})
35
+ chat_history = gr.State([])
36
 
37
  gr.Markdown("# 🎀 Welcome to Intervu")
38
+
39
  # Step 1
40
  gr.Markdown("### Step 1: Choose Interview Type")
41
  with gr.Row():
42
+ with gr.Column():
43
+ btn1 = gr.Button("Behavioral")
44
+ btn2 = gr.Button("Technical")
45
+ btn3 = gr.Button("College / Scholarship")
46
+ type_output = gr.Textbox(label="Bot response", interactive=False)
47
 
48
  btn1.click(set_type, inputs=[gr.Textbox(value="Behavioral", visible=False), user_profile], outputs=[type_output, user_profile])
49
  btn2.click(set_type, inputs=[gr.Textbox(value="Technical", visible=False), user_profile], outputs=[type_output, user_profile])
 
53
  gr.Markdown("### Step 2: Enter Your Background")
54
  background = gr.Textbox(label="Your background and field/goal")
55
  background_btn = gr.Button("Submit")
56
+ background_output = gr.Textbox(label="Bot response", interactive=False)
57
 
58
  background_btn.click(save_background, inputs=[background, user_profile], outputs=[background_output, user_profile])
59
 
60
  # Step 3
61
  gr.Markdown("### Step 3: Start Interview")
62
+ chatbot = gr.Chatbot(label="Interview Bot")
63
+ msg = gr.Textbox(label="Your message")
64
+ send_btn = gr.Button("Send")
65
+
66
+ send_btn.click(respond, inputs=[msg, chat_history, user_profile], outputs=[chatbot], queue=False)
67
+ send_btn.click(lambda: "", None, msg, queue=False)
68
 
69
  demo.launch()