Spaces:
Build error
Build error
Update app.py
Browse files
app.py
CHANGED
|
@@ -1,36 +1,79 @@
|
|
| 1 |
import gradio as gr
|
| 2 |
import openai
|
|
|
|
| 3 |
|
| 4 |
# Replace with your OpenAI API key
|
| 5 |
api_key = "sk-proj-c5tQOfP9FQbtQvnkg6DXT3BlbkFJXURwbOL7LUwivG7cGAtj"
|
| 6 |
openai.api_key = api_key
|
| 7 |
|
| 8 |
-
|
| 9 |
-
|
| 10 |
-
|
| 11 |
-
|
| 12 |
-
|
| 13 |
-
|
| 14 |
-
|
| 15 |
-
|
| 16 |
-
|
| 17 |
-
|
| 18 |
-
|
| 19 |
-
|
| 20 |
-
|
| 21 |
-
|
| 22 |
-
|
| 23 |
-
|
| 24 |
-
|
| 25 |
-
|
| 26 |
-
|
| 27 |
-
|
| 28 |
-
|
| 29 |
-
|
| 30 |
-
|
| 31 |
-
|
| 32 |
-
|
| 33 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 34 |
)
|
| 35 |
|
| 36 |
if __name__ == "__main__":
|
|
|
|
| 1 |
import gradio as gr
|
| 2 |
import openai
|
| 3 |
+
from huggingface_hub import InferenceClient
|
| 4 |
|
| 5 |
# Replace with your OpenAI API key
|
| 6 |
api_key = "sk-proj-c5tQOfP9FQbtQvnkg6DXT3BlbkFJXURwbOL7LUwivG7cGAtj"
|
| 7 |
openai.api_key = api_key
|
| 8 |
|
| 9 |
+
# Hugging Face model client
|
| 10 |
+
client = InferenceClient("HuggingFaceH4/zephyr-7b-beta")
|
| 11 |
+
|
| 12 |
+
# Initial welcome message and instructions
|
| 13 |
+
welcome_message = (
|
| 14 |
+
"Welcome! This GPT acts as an interviewer for candidates from various fields. "
|
| 15 |
+
"Please choose a stream/category to begin the interview."
|
| 16 |
+
)
|
| 17 |
+
|
| 18 |
+
# Track interview questions and candidate information
|
| 19 |
+
interview_history = []
|
| 20 |
+
|
| 21 |
+
def chatbot(message, system_message, max_tokens, temperature, top_p):
|
| 22 |
+
global interview_history
|
| 23 |
+
|
| 24 |
+
# Initialize messages
|
| 25 |
+
messages = [{"role": "system", "content": system_message}]
|
| 26 |
+
|
| 27 |
+
# Append user message to history
|
| 28 |
+
interview_history.append((message, ""))
|
| 29 |
+
|
| 30 |
+
# Check if candidate has selected a stream/category
|
| 31 |
+
if len(interview_history) == 1:
|
| 32 |
+
system_message = welcome_message
|
| 33 |
+
elif len(interview_history) == 2:
|
| 34 |
+
system_message = f"Great choice! Let's start asking questions related to {message}."
|
| 35 |
+
elif len(interview_history) > 10:
|
| 36 |
+
system_message = "We have asked enough questions. What are your expectations and notice period?"
|
| 37 |
+
|
| 38 |
+
# Append system message to history
|
| 39 |
+
interview_history[-1] = (message, system_message)
|
| 40 |
+
|
| 41 |
+
# Append user message to history
|
| 42 |
+
interview_history.append((message, ""))
|
| 43 |
+
|
| 44 |
+
# Check if we have asked enough questions
|
| 45 |
+
if len(interview_history) == 11:
|
| 46 |
+
system_message = "We have asked enough questions. What are your expectations and notice period?"
|
| 47 |
+
|
| 48 |
+
# Generate response from GPT model
|
| 49 |
+
response = ""
|
| 50 |
+
|
| 51 |
+
for message in client.chat_completion(
|
| 52 |
+
messages,
|
| 53 |
+
max_tokens=max_tokens,
|
| 54 |
+
stream=True,
|
| 55 |
+
temperature=temperature,
|
| 56 |
+
top_p=top_p,
|
| 57 |
+
):
|
| 58 |
+
token = message.choices[0].delta.content
|
| 59 |
+
|
| 60 |
+
response += token
|
| 61 |
+
yield response
|
| 62 |
+
|
| 63 |
+
iface = gr.ChatInterface(
|
| 64 |
+
chatbot,
|
| 65 |
+
additional_inputs=[
|
| 66 |
+
gr.Textbox(value="You are a friendly Chatbot.", label="System message"),
|
| 67 |
+
gr.Slider(minimum=1, maximum=2048, value=512, step=1, label="Max new tokens"),
|
| 68 |
+
gr.Slider(minimum=0.1, maximum=4.0, value=0.7, step=0.1, label="Temperature"),
|
| 69 |
+
gr.Slider(
|
| 70 |
+
minimum=0.1,
|
| 71 |
+
maximum=1.0,
|
| 72 |
+
value=0.95,
|
| 73 |
+
step=0.05,
|
| 74 |
+
label="Top-p (nucleus sampling)",
|
| 75 |
+
),
|
| 76 |
+
],
|
| 77 |
)
|
| 78 |
|
| 79 |
if __name__ == "__main__":
|