Akash473 commited on
Commit
518fe2b
·
verified ·
1 Parent(s): 1b4db11

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +41 -16
app.py CHANGED
@@ -3,8 +3,38 @@ import gradio as gr
3
 
4
  client = InferenceClient("mistralai/Mistral-7B-Instruct-v0.1")
5
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
6
 
7
  def format_prompt(message, history):
 
 
 
 
8
  prompt = "<s>"
9
  for user_prompt, bot_response in history:
10
  prompt += f"[INST] {user_prompt} [/INST]"
@@ -12,14 +42,8 @@ def format_prompt(message, history):
12
  prompt += f"[INST] {message} [/INST]"
13
  return prompt
14
 
15
-
16
  def generate(
17
- initial_prompt,
18
- temperature=0.9,
19
- max_new_tokens=256,
20
- top_p=0.95,
21
- repetition_penalty=1.0,
22
- chat_history=[],
23
  ):
24
  temperature = float(temperature)
25
  if temperature < 1e-2:
@@ -35,7 +59,7 @@ def generate(
35
  seed=42,
36
  )
37
 
38
- formatted_prompt = format_prompt(initial_prompt, chat_history)
39
 
40
  stream = client.text_generation(
41
  formatted_prompt,
@@ -51,13 +75,7 @@ def generate(
51
  yield output
52
  return output
53
 
54
-
55
  additional_inputs = [
56
- gr.Textbox(
57
- label="Initial Prompt",
58
- type="text",
59
- default="Simulate a GenAI-based interview scenario for the position of Solution Architect with a candidate named 'John Doe.' Follow these steps:\n\n1. Start with a friendly greeting and welcome message. Ask John to introduce himself briefly.\n\n2. After John introduces himself, ask if he has any initial thoughts or questions about the position.\n\n3. If John shares any initial thoughts or questions, acknowledge them and express appreciation. If not, proceed with the formal interview questions:\n\n a. Tools and Technologies: Could you please list and briefly describe the primary tools and technologies you have experience with? Additionally, could you elaborate on how you have applied them in your previous roles?\n\n4. After John provides the response to the first question, acknowledge the answer and proceed to the second question:\n\n b. Years of Experience: Can you tell us about the number of years of experience you have in the field of solution architecture? Specifically, do you have any notable projects or achievements during your career that demonstrate your expertise?\n\n5. After receiving the response to the second question, acknowledge the answer and proceed to the third question:\n\n c. Team Leadership: Have you ever led a team in your role as a Solution Architect? How many years have you spent in such a capacity, and what were the most significant learnings or challenges you encountered while doing so?\n\n6. After John responds to the third question, acknowledge the answer and conclude the interview:\n\n Provide a summary of the key points, including tools used, years of experience, and years leading a team. Express gratitude for John's time and participation.\n\nRemember to maintain a natural and polite conversational tone throughout the interview. Address any final thoughts or questions from John in the closing statement.",
60
- ),
61
  gr.Slider(
62
  label="Temperature",
63
  value=0.9,
@@ -97,7 +115,14 @@ additional_inputs = [
97
  ]
98
 
99
  gr.ChatInterface(
100
- generate,
 
 
 
 
 
 
 
101
  additional_inputs=additional_inputs,
102
- title="Mistral 7B Interview Simulation",
103
  ).launch(show_api=False)
 
3
 
4
  client = InferenceClient("mistralai/Mistral-7B-Instruct-v0.1")
5
 
6
+ # Define the initial prompt
7
+ initial_prompt = """
8
+ Simulate a GenAI-based interview scenario for the position of Solution Architect with a candidate named "John Doe." Follow these steps:
9
+
10
+ 1. Start with a friendly greeting and welcome message. Ask John to introduce himself briefly.
11
+
12
+ 2. After John introduces himself, ask if he has any initial thoughts or questions about the position.
13
+
14
+ 3. If John shares any initial thoughts or questions, acknowledge them and express appreciation. If not, proceed with the formal interview questions:
15
+
16
+ a. Tools and Technologies: Could you please list and briefly describe the primary tools and technologies you have experience with? Additionally, could you elaborate on how you have applied them in your previous roles?
17
+
18
+ 4. After John provides the response to the first question, acknowledge the answer and proceed to the second question:
19
+
20
+ b. Years of Experience: Can you tell us about the number of years of experience you have in the field of solution architecture? Specifically, do you have any notable projects or achievements during your career that demonstrate your expertise?
21
+
22
+ 5. After receiving the response to the second question, acknowledge the answer and proceed to the third question:
23
+
24
+ c. Team Leadership: Have you ever led a team in your role as a Solution Architect? How many years have you spent in such a capacity, and what were the most significant learnings or challenges you encountered while doing so?
25
+
26
+ 6. After John responds to the third question, acknowledge the answer and conclude the interview:
27
+
28
+ Provide a summary of the key points, including tools used, years of experience, and years leading a team. Express gratitude for John's time and participation.
29
+
30
+ Remember to maintain a natural and polite conversational tone throughout the interview. Address any final thoughts or questions from John in the closing statement.
31
+ """
32
 
33
  def format_prompt(message, history):
34
+ # Start with the initial prompt for the first interaction
35
+ if not history:
36
+ return message
37
+
38
  prompt = "<s>"
39
  for user_prompt, bot_response in history:
40
  prompt += f"[INST] {user_prompt} [/INST]"
 
42
  prompt += f"[INST] {message} [/INST]"
43
  return prompt
44
 
 
45
  def generate(
46
+ prompt, history, temperature=0.9, max_new_tokens=256, top_p=0.95, repetition_penalty=1.0,
 
 
 
 
 
47
  ):
48
  temperature = float(temperature)
49
  if temperature < 1e-2:
 
59
  seed=42,
60
  )
61
 
62
+ formatted_prompt = format_prompt(prompt, history)
63
 
64
  stream = client.text_generation(
65
  formatted_prompt,
 
75
  yield output
76
  return output
77
 
 
78
  additional_inputs = [
 
 
 
 
 
79
  gr.Slider(
80
  label="Temperature",
81
  value=0.9,
 
115
  ]
116
 
117
  gr.ChatInterface(
118
+ fn=generate,
119
+ chatbot=gr.Chatbot(
120
+ show_label=False,
121
+ show_share_button=False,
122
+ show_copy_button=True,
123
+ likeable=True,
124
+ layout="panel",
125
+ ),
126
  additional_inputs=additional_inputs,
127
+ title="""Mistral 7B""",
128
  ).launch(show_api=False)