Pengi5659 commited on
Commit
901ff66
Β·
verified Β·
1 Parent(s): 68b17b7

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +23 -72
app.py CHANGED
@@ -1,73 +1,24 @@
1
  import gradio as gr
2
-
3
- # Respond to user input
4
- def chatbot_response(user_input):
5
- return f"πŸ€– Thanks! That’s a strong example of an interview response."
6
-
7
- # Show/hide the tip "pop-up"
8
- def show_tip():
9
- return gr.update(visible=True)
10
-
11
- def hide_tip():
12
- return gr.update(visible=False)
13
-
14
- with gr.Blocks(css="""
15
- .popup-box {
16
- position: fixed;
17
- top: 30%;
18
- left: 50%;
19
- transform: translate(-50%, -50%);
20
- background-color: white;
21
- border: 2px solid #333;
22
- padding: 20px;
23
- z-index: 999;
24
- box-shadow: 0 0 10px rgba(0,0,0,0.3);
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()