mrbeliever commited on
Commit
1dddd34
·
verified ·
1 Parent(s): deb8070

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +12 -10
app.py CHANGED
@@ -1,23 +1,24 @@
1
  from huggingface_hub import InferenceClient
2
  import gradio as gr
 
3
 
4
  client = InferenceClient("mistralai/Mixtral-8x7B-Instruct-v0.1")
5
 
6
  # Your system prompt
7
- SYSTEM_PROMPT = "Your work is to rewrite and enhance the user input in sentence form without changing it's essence"
8
 
9
  def format_prompt(message, history=[]):
10
- prompt = "<s>" # Start sequence token
11
- prompt += f"[SYSTEM] {SYSTEM_PROMPT} [/SYSTEM]" # Add the system prompt here
12
-
13
  for user_prompt, bot_response in history:
14
- prompt += f"[INST] {user_prompt} [/INST] {bot_response}"
15
-
16
- prompt += f"[INST] {message} [/INST]</s>" # Close the prompt sequence
 
17
  return prompt
18
 
19
  def generate(prompt, temperature=0.9, max_new_tokens=256, top_p=0.95, repetition_penalty=1.0):
20
- temperature = max(float(temperature), 1e-2)
21
  top_p = float(top_p)
22
 
23
  generate_kwargs = dict(
@@ -29,13 +30,14 @@ def generate(prompt, temperature=0.9, max_new_tokens=256, top_p=0.95, repetition
29
  )
30
 
31
  formatted_prompt = format_prompt(prompt)
 
32
  stream = client.text_generation(formatted_prompt, **generate_kwargs, stream=True, details=True, return_full_text=False)
33
  output = ""
34
 
35
  for response in stream:
36
  output += response.token.text
37
- yield output.rstrip("</s>")
38
- return output.rstrip("</s>")
39
 
40
  with gr.Blocks() as demo:
41
  input_text = gr.Textbox(placeholder="Enter your prompt here...", lines=2, max_lines=2, label="Prompt")
 
1
  from huggingface_hub import InferenceClient
2
  import gradio as gr
3
+ import time
4
 
5
  client = InferenceClient("mistralai/Mixtral-8x7B-Instruct-v0.1")
6
 
7
  # Your system prompt
8
+ SYSTEM_PROMPT = "Rewrite and enhance this in sentence form"
9
 
10
  def format_prompt(message, history=[]):
11
+ prompt = "<s>"
12
+ prompt += f"[INST] SYSTEM: {SYSTEM_PROMPT} [/INST]" # Add the system prompt here
 
13
  for user_prompt, bot_response in history:
14
+ prompt += f"[INST] {user_prompt} [/INST]"
15
+ prompt += f" {bot_response}</s> "
16
+ # Append the user message as the last entry in the prompt history
17
+ prompt += f"[INST] {message} [/INST]</s>"
18
  return prompt
19
 
20
  def generate(prompt, temperature=0.9, max_new_tokens=256, top_p=0.95, repetition_penalty=1.0):
21
+ temperature = float(temperature)
22
  top_p = float(top_p)
23
 
24
  generate_kwargs = dict(
 
30
  )
31
 
32
  formatted_prompt = format_prompt(prompt)
33
+
34
  stream = client.text_generation(formatted_prompt, **generate_kwargs, stream=True, details=True, return_full_text=False)
35
  output = ""
36
 
37
  for response in stream:
38
  output += response.token.text
39
+ yield output.strip('</s>')
40
+ return output.strip('</s>')
41
 
42
  with gr.Blocks() as demo:
43
  input_text = gr.Textbox(placeholder="Enter your prompt here...", lines=2, max_lines=2, label="Prompt")