Spaces:
Runtime error
Runtime error
Update app.py
Browse files
app.py
CHANGED
|
@@ -30,27 +30,24 @@ def save_background(info):
|
|
| 30 |
user_profile["field"] = info
|
| 31 |
return "Awesome! Type 'start' below to begin your interview."
|
| 32 |
|
| 33 |
-
# Step 3:
|
| 34 |
-
def
|
| 35 |
-
|
| 36 |
-
|
| 37 |
-
|
| 38 |
-
|
| 39 |
-
|
| 40 |
-
|
| 41 |
-
|
| 42 |
-
|
| 43 |
-
|
| 44 |
-
|
| 45 |
-
|
| 46 |
-
|
| 47 |
-
|
| 48 |
-
|
| 49 |
-
|
| 50 |
-
|
| 51 |
-
yield response
|
| 52 |
-
|
| 53 |
-
gr.ChatInterface(respond, title="Intervu - AI Interview Practice").launch()
|
| 54 |
|
| 55 |
# Build UI
|
| 56 |
with gr.Blocks() as demo:
|
|
@@ -75,8 +72,8 @@ with gr.Blocks() as demo:
|
|
| 75 |
background_btn.click(save_background, inputs=background, outputs=background_out)
|
| 76 |
|
| 77 |
gr.Markdown("### Step 3: Start Your Interview")
|
| 78 |
-
|
| 79 |
-
start_btn.click(fn=chat_bot, inputs=[], outputs=[])
|
| 80 |
|
| 81 |
demo.launch()
|
| 82 |
|
|
|
|
|
|
| 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:
|
|
|
|
| 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 |
+
|