maahikachitagi commited on
Commit
a1e618e
Β·
verified Β·
1 Parent(s): 649e079

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +26 -43
app.py CHANGED
@@ -1,79 +1,62 @@
1
  import gradio as gr
2
  from huggingface_hub import InferenceClient
3
 
4
- # Initialize LLM client
5
- client = InferenceClient("")
6
 
7
- # User profile state
8
- user_profile = {
9
- "interview_type": "",
10
- "field": "",
11
- "mode": "text"
12
- }
13
-
14
- # Step 1: Set interview type
15
- def set_type(choice):
16
  user_profile["interview_type"] = choice.lower()
17
- return "Great! What’s your background and what field/role are you aiming for?"
18
-
19
- def set_type_behavioral():
20
- return set_type("Behavioral")
21
-
22
- def set_type_technical():
23
- return set_type("Technical")
24
-
25
- def set_type_college():
26
- return set_type("College")
27
 
28
- # Step 2: Save background info
29
- def save_background(info):
30
  user_profile["field"] = info
31
- return "Awesome! Type 'start' below to begin your interview."
 
 
 
 
 
32
 
33
- # Step 3: Response logic for embedded Chatbot
34
- def respond(message, history):
35
  messages = [
36
- {"role": "system", "content": f"You are a professional interviewer for a {user_profile['interview_type']} interview in the {user_profile['field']} field."}
37
  ]
38
  if history:
39
  messages.extend(history)
40
  messages.append({"role": "user", "content": message})
41
 
42
  response = ""
43
- for msg in client.chat_completion(
44
- messages,
45
- max_tokens=100,
46
- stream=True
47
- ):
48
- token = msg.choices[0].delta.content
49
  response += token
50
  yield response
51
 
52
- # Build UI
53
  with gr.Blocks() as demo:
54
- gr.Markdown("# 🎀 Welcome to Intervu")
55
 
 
 
 
56
  gr.Markdown("### Step 1: Choose Interview Type")
57
  with gr.Row():
58
  btn1 = gr.Button("Behavioral")
59
  btn2 = gr.Button("Technical")
60
  btn3 = gr.Button("College / Scholarship")
61
- type_out = gr.Textbox(label="Bot", interactive=False)
62
 
63
- btn1.click(set_type_behavioral, outputs=type_out)
64
- btn2.click(set_type_technical, outputs=type_out)
65
- btn3.click(set_type_college, outputs=type_out)
66
 
 
67
  gr.Markdown("### Step 2: Enter Your Background")
68
  background = gr.Textbox(label="Your background and field/goal")
69
  background_btn = gr.Button("Submit")
70
  background_out = gr.Textbox(label="Bot", interactive=False)
71
 
72
- background_btn.click(save_background, inputs=background, outputs=background_out)
73
 
74
- gr.Markdown("### Step 3: Start Your Interview")
75
- chatbot = gr.ChatInterface(respond, title="Intervu - AI Interview Practice")
 
76
 
77
  demo.launch()
78
 
79
-
 
1
  import gradio as gr
2
  from huggingface_hub import InferenceClient
3
 
4
+ client = InferenceClient("HuggingFaceH4/zephyr-7b-beta") # Use actual model
 
5
 
6
+ def set_type(choice, user_profile):
 
 
 
 
 
 
 
 
7
  user_profile["interview_type"] = choice.lower()
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, history, user_profile):
15
+ if not user_profile["interview_type"] or not user_profile["field"]:
16
+ yield "Please finish steps 1 and 2 before starting the interview."
17
+ return
18
 
 
 
19
  messages = [
20
+ {"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."}
21
  ]
22
  if history:
23
  messages.extend(history)
24
  messages.append({"role": "user", "content": message})
25
 
26
  response = ""
27
+ for msg in client.chat_completion(messages, max_tokens=100, stream=True):
28
+ token = msg.choices[0].delta.content or ""
 
 
 
 
29
  response += token
30
  yield response
31
 
 
32
  with gr.Blocks() as demo:
33
+ user_profile = gr.State({"interview_type": "", "field": ""})
34
 
35
+ gr.Markdown("# 🎀 Welcome to Intervu")
36
+
37
+ # Step 1
38
  gr.Markdown("### Step 1: Choose Interview Type")
39
  with gr.Row():
40
  btn1 = gr.Button("Behavioral")
41
  btn2 = gr.Button("Technical")
42
  btn3 = gr.Button("College / Scholarship")
43
+ type_out = gr.Textbox(label="Bot", interactive=False)
44
 
45
+ btn1.click(set_type, inputs=[gr.Textbox(value="Behavioral", visible=False), user_profile], outputs=[type_out, user_profile])
46
+ btn2.click(set_type, inputs=[gr.Textbox(value="Technical", visible=False), user_profile], outputs=[type_out, user_profile])
47
+ btn3.click(set_type, inputs=[gr.Textbox(value="College", visible=False), user_profile], outputs=[type_out, user_profile])
48
 
49
+ # Step 2
50
  gr.Markdown("### Step 2: Enter Your Background")
51
  background = gr.Textbox(label="Your background and field/goal")
52
  background_btn = gr.Button("Submit")
53
  background_out = gr.Textbox(label="Bot", interactive=False)
54
 
55
+ background_btn.click(save_background, inputs=[background, user_profile], outputs=[background_out, user_profile])
56
 
57
+ # Step 3: Interview
58
+ gr.Markdown("### Step 3: Start Interview")
59
+ chatbot = gr.ChatInterface(lambda msg, hist: respond(msg, hist, user_profile.value), title="Intervu - AI Interview Practice")
60
 
61
  demo.launch()
62