MatteoScript commited on
Commit
fe581bc
·
1 Parent(s): bd5ca88

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +10 -20
app.py CHANGED
@@ -4,12 +4,12 @@ import gradio as gr
4
  client = InferenceClient("mistralai/Mixtral-8x7B-Instruct-v0.1")
5
 
6
  def format_prompt(message, history):
7
- prompt = "<s>"
8
- for user_prompt, bot_response in history:
9
- prompt += f"[INST] {user_prompt} [/INST]"
10
- prompt += f" {bot_response}</s> "
11
- prompt += f"[INST] {message} [/INST]"
12
- return prompt
13
 
14
  def generate(
15
  prompt, history, temperature=0.2, max_new_tokens=30000, top_p=0.95, repetition_penalty=1.0,
@@ -30,22 +30,12 @@ def generate(
30
 
31
  formatted_prompt = format_prompt(prompt, history)
32
 
33
- stream = client.text_generation(formatted_prompt, **generate_kwargs, stream=True, details=True, return_full_text=False)
34
  output = ""
35
 
36
  for response in stream:
37
- output += response.token.text
38
  yield output
39
- return output
40
 
41
- mychatbot = gr.Chatbot(
42
- avatar_images=["./user.png", "./botm.png"], bubble_full_width=False, show_label=False, show_copy_button=True, likeable=True,)
43
-
44
- demo = gr.ChatInterface(fn=generate,
45
- chatbot=mychatbot,
46
- title="Matteo's Mixtral 8x7b Chat",
47
- retry_btn=None,
48
- undo_btn=None
49
- )
50
-
51
- demo.queue().launch(show_api=True)
 
4
  client = InferenceClient("mistralai/Mixtral-8x7B-Instruct-v0.1")
5
 
6
  def format_prompt(message, history):
7
+ prompt = "<s>"
8
+ for user_prompt, bot_response in history:
9
+ prompt += f"[INST] {user_prompt} [/INST]"
10
+ prompt += f" {bot_response}</s> "
11
+ prompt += f"[INST] {message} [/INST]"
12
+ return prompt
13
 
14
  def generate(
15
  prompt, history, temperature=0.2, max_new_tokens=30000, top_p=0.95, repetition_penalty=1.0,
 
30
 
31
  formatted_prompt = format_prompt(prompt, history)
32
 
33
+ stream = client.text_generation(formatted_prompt, **generate_kwargs, stream=True, details=True, return_full_text=True)
34
  output = ""
35
 
36
  for response in stream:
37
+ output += response["generated_text"]
38
  yield output
 
39
 
40
+ iface = gr.Interface(fn=generate, inputs=["text", "text", "number", "number", "number", "number"], outputs="text", title="Text Generation")
41
+ iface.launch()