SuriRaja commited on
Commit
f51df04
·
verified ·
1 Parent(s): 74b6ac3

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +69 -26
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
- def chatbot(input_text):
9
- prompt = "The following interview dialogue is a mock-up scenario:\n" \
10
- "Interviewer: Tell me about yourself.\n" \
11
- f"Candidate: {input_text}\n" \
12
- "Interviewer: Why do you want this job?\n" \
13
- "Candidate: (Your response)\n" \
14
- "Interviewer: (Follow-up question)\n" \
15
- "Candidate: (Your response)\n" \
16
- "Interviewer: (Closing remarks)\n" \
17
- "Candidate: (Your response)\n"
18
-
19
- response = openai.Completion.create(
20
- engine="text-davinci-002",
21
- prompt=prompt,
22
- max_tokens=150
23
- )
24
-
25
- return response.choices[0].text.strip()
26
-
27
- iface = gr.Interface(
28
- fn=chatbot,
29
- inputs=gr.Textbox(lines=5, label="Candidate's Response"),
30
- outputs=gr.Textbox(label="Interviewer's Question"),
31
- title="Mock Interview Chatbot",
32
- description="This chatbot simulates a mock interview scenario. Enter your response as a candidate and see the interviewer's question.",
33
- theme="compact"
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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__":