racheljw commited on
Commit
c95bc8a
·
verified ·
1 Parent(s): f2a41ba
Files changed (1) hide show
  1. app.py +40 -0
app.py ADDED
@@ -0,0 +1,40 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ # build on your original chatbot from the previous lesson
2
+ # a basic chatbot from the previous lesson is below -- edit it to incorporate the changes described above
3
+
4
+ import gradio as gr
5
+ from huggingface_hub import InferenceClient #imports huggingface models
6
+
7
+ client = InferenceClient("google/gemma-2-2b-it")
8
+
9
+ def respond(message, history):
10
+ messages = [{"role": "system", "content": "You are an empathetic and professional AI interview coach dedicated to helping young adults and job applicants sharpen their interview skills using the STAR method—Situation, Task, Action, and Result. Your role is to guide users in crafting clear, structured, and impactful answers to behavioral interview questions by encouraging them to fully articulate each component of the STAR framework. Maintain a supportive and respectful tone at all times, ensuring users feel comfortable and motivated to improve. After each response, provide thoughtful, constructive feedback that highlights what the user did well and gently points out areas for enhancement, explaining why these improvements matter in real interviews. Offer specific suggestions on how to make answers more concise, detailed, or engaging, and invite users to reflect on alternative examples or ways to demonstrate their impact more convincingly. Throughout the conversation, balance honest critique with positive reinforcement, helping users build confidence and refine their communication skills progressively. Always encourage practice by asking if they would like to try again with the feedback in mind, keeping the interaction collaborative and growth-focused."}]
11
+
12
+ # add all previous messages to the messages list
13
+ if history:
14
+ for user_msg, assistant_msg in history:
15
+ messages.append({"role": "user", "content": user_msg})
16
+ messages.append({"role": "assistant", "content": assistant_msg})
17
+
18
+ # add the current user's message to the messages list
19
+ messages.append({"role": "user", "content": message})
20
+
21
+ # makes the chat completion API call,
22
+ # sending the messages and other parameters to the model
23
+ # implements streaming, where one word/token appears at a time
24
+ response = ""
25
+
26
+ # iterate through each message in the method
27
+ for message in client.chat_completion(
28
+ messages,
29
+ max_tokens=500,
30
+ temperature=.1,
31
+ stream=True):
32
+
33
+ # add the tokens to the output content
34
+ token = message.choices[0].delta.content # capture the most recent toke
35
+ response += token # Add it to the response
36
+ yield response # yield the response:
37
+
38
+ chatbot = gr.ChatInterface(respond, type="messages", theme=gr.themes.Soft())
39
+
40
+ chatbot.launch()