Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
|
@@ -6,6 +6,17 @@ For more information on `huggingface_hub` Inference API support, please check th
|
|
| 6 |
"""
|
| 7 |
client = InferenceClient("HuggingFaceH4/zephyr-7b-beta")
|
| 8 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 9 |
|
| 10 |
def respond(
|
| 11 |
message,
|
|
@@ -15,6 +26,8 @@ def respond(
|
|
| 15 |
temperature,
|
| 16 |
top_p,
|
| 17 |
):
|
|
|
|
|
|
|
| 18 |
messages = [{"role": "system", "content": system_message}]
|
| 19 |
|
| 20 |
for val in history:
|
|
@@ -23,10 +36,11 @@ def respond(
|
|
| 23 |
if val[1]:
|
| 24 |
messages.append({"role": "assistant", "content": val[1]})
|
| 25 |
|
|
|
|
| 26 |
messages.append({"role": "user", "content": message})
|
| 27 |
|
|
|
|
| 28 |
response = ""
|
| 29 |
-
|
| 30 |
for message in client.chat_completion(
|
| 31 |
messages,
|
| 32 |
max_tokens=max_tokens,
|
|
@@ -35,9 +49,21 @@ def respond(
|
|
| 35 |
top_p=top_p,
|
| 36 |
):
|
| 37 |
token = message.choices[0].delta.content
|
| 38 |
-
|
| 39 |
response += token
|
| 40 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 41 |
|
| 42 |
"""
|
| 43 |
For information on how to customize the ChatInterface, peruse the gradio docs: https://www.gradio.app/docs/chatinterface
|
|
@@ -47,7 +73,7 @@ demo = gr.ChatInterface(
|
|
| 47 |
additional_inputs=[
|
| 48 |
gr.Textbox(value="You are a manager conducting a job interview. Ask questions related to the candidate's experience, skills, and suitability for the role.", label="System message"),
|
| 49 |
gr.Slider(minimum=1, maximum=2048, value=512, step=1, label="Max new tokens"),
|
| 50 |
-
gr.Slider(minimum=0.1, maximum
|
| 51 |
gr.Slider(
|
| 52 |
minimum=0.1,
|
| 53 |
maximum=1.0,
|
|
@@ -58,6 +84,5 @@ demo = gr.ChatInterface(
|
|
| 58 |
],
|
| 59 |
)
|
| 60 |
|
| 61 |
-
|
| 62 |
if __name__ == "__main__":
|
| 63 |
demo.launch()
|
|
|
|
| 6 |
"""
|
| 7 |
client = InferenceClient("HuggingFaceH4/zephyr-7b-beta")
|
| 8 |
|
| 9 |
+
# Predefined list of interview questions
|
| 10 |
+
interview_questions = [
|
| 11 |
+
"Can you tell me about yourself?",
|
| 12 |
+
"Why are you interested in this position?",
|
| 13 |
+
"What are your strengths and weaknesses?",
|
| 14 |
+
"Can you describe a challenging work situation and how you handled it?",
|
| 15 |
+
"Where do you see yourself in five years?",
|
| 16 |
+
]
|
| 17 |
+
|
| 18 |
+
# Keep track of the current question index
|
| 19 |
+
question_index = 0
|
| 20 |
|
| 21 |
def respond(
|
| 22 |
message,
|
|
|
|
| 26 |
temperature,
|
| 27 |
top_p,
|
| 28 |
):
|
| 29 |
+
global question_index
|
| 30 |
+
|
| 31 |
messages = [{"role": "system", "content": system_message}]
|
| 32 |
|
| 33 |
for val in history:
|
|
|
|
| 36 |
if val[1]:
|
| 37 |
messages.append({"role": "assistant", "content": val[1]})
|
| 38 |
|
| 39 |
+
# Add the user's latest message
|
| 40 |
messages.append({"role": "user", "content": message})
|
| 41 |
|
| 42 |
+
# Generate the assistant's response
|
| 43 |
response = ""
|
|
|
|
| 44 |
for message in client.chat_completion(
|
| 45 |
messages,
|
| 46 |
max_tokens=max_tokens,
|
|
|
|
| 49 |
top_p=top_p,
|
| 50 |
):
|
| 51 |
token = message.choices[0].delta.content
|
|
|
|
| 52 |
response += token
|
| 53 |
+
|
| 54 |
+
# Append the response to the history
|
| 55 |
+
history.append((message, response))
|
| 56 |
+
|
| 57 |
+
# Prepare the next question if there are more questions left
|
| 58 |
+
if question_index < len(interview_questions):
|
| 59 |
+
next_question = interview_questions[question_index]
|
| 60 |
+
question_index += 1
|
| 61 |
+
else:
|
| 62 |
+
next_question = "Thank you for answering all the questions. Do you have any questions for me?"
|
| 63 |
+
|
| 64 |
+
# Yield the assistant's response followed by the next question
|
| 65 |
+
full_response = response + "\n\n" + next_question
|
| 66 |
+
yield full_response
|
| 67 |
|
| 68 |
"""
|
| 69 |
For information on how to customize the ChatInterface, peruse the gradio docs: https://www.gradio.app/docs/chatinterface
|
|
|
|
| 73 |
additional_inputs=[
|
| 74 |
gr.Textbox(value="You are a manager conducting a job interview. Ask questions related to the candidate's experience, skills, and suitability for the role.", label="System message"),
|
| 75 |
gr.Slider(minimum=1, maximum=2048, value=512, step=1, label="Max new tokens"),
|
| 76 |
+
gr.Slider(minimum=0.1, maximum 4.0, value=0.7, step=0.1, label="Temperature"),
|
| 77 |
gr.Slider(
|
| 78 |
minimum=0.1,
|
| 79 |
maximum=1.0,
|
|
|
|
| 84 |
],
|
| 85 |
)
|
| 86 |
|
|
|
|
| 87 |
if __name__ == "__main__":
|
| 88 |
demo.launch()
|