maahikachitagi commited on
Commit
2e48300
Β·
verified Β·
1 Parent(s): a1e618e

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +19 -9
app.py CHANGED
@@ -13,21 +13,26 @@ def save_background(info, 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": ""})
@@ -56,7 +61,12 @@ with gr.Blocks() as demo:
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
 
 
13
 
14
  def respond(message, history, user_profile):
15
  if not user_profile["interview_type"] or not user_profile["field"]:
16
+ return "Please finish steps 1 and 2 before starting the interview."
 
17
 
18
  messages = [
19
+ {
20
+ "role": "system",
21
+ "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
  ]
24
  if history:
25
  messages.extend(history)
26
  messages.append({"role": "user", "content": message})
27
 
28
+ response = client.chat_completion(
29
+ messages,
30
+ max_tokens=150,
31
+ stream=False # Make sure streaming is OFF
32
+ )
33
+
34
+ return response.choices[0].message.content
35
+
36
 
37
  with gr.Blocks() as demo:
38
  user_profile = gr.State({"interview_type": "", "field": ""})
 
61
 
62
  # Step 3: Interview
63
  gr.Markdown("### Step 3: Start Interview")
64
+ chatbot = gr.ChatInterface(
65
+ lambda msg, hist: respond(msg, hist, user_profile.value),
66
+ title="Intervu - AI Interview Practice",
67
+ type="messages" # Important to fix the warning
68
+ )
69
+
70
 
71
  demo.launch()
72