Spaces:
Runtime error
Runtime error
Update app.py
Browse files
app.py
CHANGED
|
@@ -1,73 +1,24 @@
|
|
| 1 |
import gradio as gr
|
| 2 |
-
|
| 3 |
-
|
| 4 |
-
|
| 5 |
-
|
| 6 |
-
|
| 7 |
-
|
| 8 |
-
|
| 9 |
-
|
| 10 |
-
|
| 11 |
-
|
| 12 |
-
|
| 13 |
-
|
| 14 |
-
|
| 15 |
-
|
| 16 |
-
|
| 17 |
-
|
| 18 |
-
|
| 19 |
-
|
| 20 |
-
|
| 21 |
-
|
| 22 |
-
|
| 23 |
-
|
| 24 |
-
|
| 25 |
-
border-radius: 12px;
|
| 26 |
-
}
|
| 27 |
-
.overlay {
|
| 28 |
-
position: fixed;
|
| 29 |
-
top: 0;
|
| 30 |
-
left: 0;
|
| 31 |
-
width: 100%;
|
| 32 |
-
height: 100%;
|
| 33 |
-
background: rgba(0,0,0,0.4);
|
| 34 |
-
z-index: 998;
|
| 35 |
-
}
|
| 36 |
-
""") as demo:
|
| 37 |
-
|
| 38 |
-
gr.Markdown("## π€ Interview Chatbot")
|
| 39 |
-
gr.Markdown("Write your answer below or click an example:")
|
| 40 |
-
|
| 41 |
-
# User input and bot output
|
| 42 |
-
user_input = gr.Textbox(label="Your Answer", placeholder="Type your interview response here...")
|
| 43 |
-
submit_btn = gr.Button("Submit")
|
| 44 |
-
bot_output = gr.Textbox(label="Bot Reply")
|
| 45 |
-
|
| 46 |
-
# Example answers for interview questions
|
| 47 |
-
gr.Examples(
|
| 48 |
-
examples=[
|
| 49 |
-
["I led a cross-functional team to deliver a project ahead of schedule."],
|
| 50 |
-
["I handled a client complaint by staying calm and offering a solution."],
|
| 51 |
-
["I used data to reduce delivery time by 15% on a logistics project."]
|
| 52 |
-
],
|
| 53 |
-
inputs=user_input
|
| 54 |
-
)
|
| 55 |
-
|
| 56 |
-
# Submit logic
|
| 57 |
-
submit_btn.click(fn=chatbot_response, inputs=user_input, outputs=bot_output)
|
| 58 |
-
|
| 59 |
-
# Button to show interview tip
|
| 60 |
-
tip_button = gr.Button("π‘ Show Interview Tip")
|
| 61 |
-
|
| 62 |
-
# Tip pop-up with overlay
|
| 63 |
-
with gr.Group(visible=False) as popup:
|
| 64 |
-
gr.HTML('<div class="overlay"></div>')
|
| 65 |
-
with gr.Column(elem_classes="popup-box"):
|
| 66 |
-
gr.Markdown("π§ **Tip:** Use the **STAR method** β Situation, Task, Action, Result β to structure your answers.")
|
| 67 |
-
close_btn = gr.Button("β Close Tip")
|
| 68 |
-
|
| 69 |
-
# Show/hide logic
|
| 70 |
-
tip_button.click(fn=show_tip, outputs=popup)
|
| 71 |
-
close_btn.click(fn=hide_tip, outputs=popup)
|
| 72 |
-
|
| 73 |
-
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 |
+
def respond(message, history):
|
| 7 |
+
messages = [{"role": "system", "content": "You are a helpful chatbot."}]
|
| 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()
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|