faelfernandes commited on
Commit
616481a
1 Parent(s): 9792fb4

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +57 -46
app.py CHANGED
@@ -1,20 +1,21 @@
1
  from huggingface_hub import InferenceClient
2
  import gradio as gr
3
 
4
- client = InferenceClient("mistralai/Mixtral-8x7B-Instruct-v0.1")
 
 
 
5
 
6
- def format_prompt(message, history, system_prompt=None):
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
- if system_prompt:
12
- prompt += f"[SYS] {system_prompt} [/SYS]"
13
- prompt += f"[INST] {message} [/INST]"
14
- return prompt
15
 
16
  def generate(
17
- prompt, history, system_prompt=None, temperature=0.2, max_new_tokens=512, top_p=0.95, repetition_penalty=1.0,
18
  ):
19
  temperature = float(temperature)
20
  if temperature < 1e-2:
@@ -30,7 +31,7 @@ def generate(
30
  seed=42,
31
  )
32
 
33
- formatted_prompt = format_prompt(prompt, history, system_prompt)
34
 
35
  stream = client.text_generation(formatted_prompt, **generate_kwargs, stream=True, details=True, return_full_text=False)
36
  output = ""
@@ -40,40 +41,50 @@ def generate(
40
  yield output
41
  return output
42
 
43
- mychatbot = gr.Chatbot(
44
- avatar_images=["./user.png", "./botm.png"], bubble_full_width=False, show_label=False, show_copy_button=True, likeable=True,)
45
 
46
- demo = gr.ChatInterface(
47
- fn=generate,
48
- chatbot=mychatbot,
49
- title="Hello! I'm Elisa by SpriFi.👋 How can I help you today?",
50
- css="body { background-color: inherit; overflow-x:hidden;}"
51
- ":root {--color-accent: transparent !important; --color-accent-soft:transparent !important; --code-background-fill:black !important; --body-text-color:white !important;}"
52
- "#component-2 {background:#ffffff1a; display:contents;}"
53
- "div#component-0 { height: auto !important;}"
54
- ".gradio-container.gradio-container-4-8-0.svelte-1kyws56.app {background: #000000;}gradio-app {background: #333 !important;}"
55
- "gradio-app {background: #000000 !important; background-attachment: fixed !important; background-position: top;}"
56
- ".panel.svelte-vt1mxs {background: transparent; padding:0;}"
57
- ".block.svelte-90oupt { background: transparent; border-color: transparent;}"
58
- ".bot.svelte-12dsd9j.svelte-12dsd9j.svelte-12dsd9j { background: #ffffff1a; border-color: transparent; color: white;}"
59
- ".user.svelte-12dsd9j.svelte-12dsd9j.svelte-12dsd9j { background: #ffffff1a; border-color: transparent; color: white; padding: 10px 18px;}"
60
- "div.svelte-iyf88w{ background: #cc0000; border-color: trasparent; border-radius: 25px;}"
61
- "textarea.scroll-hide.svelte-1f354aw {background: #555 !important;}"
62
- ".primary.svelte-cmf5ev { background: transparent; color: white;}"
63
- ".primary.svelte-cmf5ev:hover { background: transparent; color: white;}"
64
- "div#component-9 { max-width: fit-content; margin-left: auto; margin-right: auto;}"
65
- "button#component-8, button#component-10, button#component-11, button#component-12 { flex: none; background: #ffffff1a; border: none; color: white; margin-right: auto; margin-left: auto; border-radius: 9px; min-width: fit-content;}"
66
- ".share-button.svelte-12dsd9j { display: none;}"
67
- "footer.svelte-mpyp5e { display: none !important;}"
68
- ".message-buttons-bubble.svelte-12dsd9j.svelte-12dsd9j.svelte-12dsd9j { border-color: #FFFFFF; background: #FFFFFF;}"
69
- ".bubble-wrap.svelte-12dsd9j.svelte-12dsd9j.svelte-12dsd9j {padding: 0;}"
70
- ".prose h1 { color: white !important; font-size: 16px !important; font-weight: normal !important; background: #ffffff1a; padding: 20px; border-radius: 20px; width: 90%; margin-left: auto !important; margin-right: auto !important;}"
71
- ".toast-wrap.svelte-pu0yf1 { display:none !important;}"
72
- ".scroll-hide { scrollbar-width: auto !important;}"
73
- ".main svelte-1kyws56 {max-width: 800px; align-self: center;}"
74
- "div#component-4 {max-width: 650px; margin-left: auto; margin-right: auto;}"
75
- "body::-webkit-scrollbar { display: none;}"
76
- )
 
 
 
 
 
 
 
77
 
78
- demo.queue().launch(show_api=False)
79
 
 
 
 
 
 
 
 
1
  from huggingface_hub import InferenceClient
2
  import gradio as gr
3
 
4
+ client = InferenceClient(
5
+ "mistralai/Mistral-7B-Instruct-v0.3"
6
+ )
7
+
8
 
9
+ def format_prompt(message, history):
10
+ prompt = "<s>"
11
+ for user_prompt, bot_response in history:
12
+ prompt += f"[INST] {user_prompt} [/INST]"
13
+ prompt += f" {bot_response}</s> "
14
+ prompt += f"[INST] {message} [/INST]"
15
+ return prompt
 
 
16
 
17
  def generate(
18
+ prompt, history, temperature=0.9, max_new_tokens=256, top_p=0.95, repetition_penalty=1.0,
19
  ):
20
  temperature = float(temperature)
21
  if temperature < 1e-2:
 
31
  seed=42,
32
  )
33
 
34
+ formatted_prompt = format_prompt(prompt, history)
35
 
36
  stream = client.text_generation(formatted_prompt, **generate_kwargs, stream=True, details=True, return_full_text=False)
37
  output = ""
 
41
  yield output
42
  return output
43
 
 
 
44
 
45
+ additional_inputs=[
46
+ gr.Slider(
47
+ label="Temperature",
48
+ value=0.9,
49
+ minimum=0.0,
50
+ maximum=1.0,
51
+ step=0.05,
52
+ interactive=True,
53
+ info="Higher values produce more diverse outputs",
54
+ ),
55
+ gr.Slider(
56
+ label="Max new tokens",
57
+ value=256,
58
+ minimum=0,
59
+ maximum=1048,
60
+ step=64,
61
+ interactive=True,
62
+ info="The maximum numbers of new tokens",
63
+ ),
64
+ gr.Slider(
65
+ label="Top-p (nucleus sampling)",
66
+ value=0.90,
67
+ minimum=0.0,
68
+ maximum=1,
69
+ step=0.05,
70
+ interactive=True,
71
+ info="Higher values sample more low-probability tokens",
72
+ ),
73
+ gr.Slider(
74
+ label="Repetition penalty",
75
+ value=1.2,
76
+ minimum=1.0,
77
+ maximum=2.0,
78
+ step=0.05,
79
+ interactive=True,
80
+ info="Penalize repeated tokens",
81
+ )
82
+ ]
83
 
 
84
 
85
+ gr.ChatInterface(
86
+ fn=generate,
87
+ chatbot=gr.Chatbot(show_label=False, show_share_button=False, show_copy_button=True, likeable=True, layout="panel"),
88
+ additional_inputs=additional_inputs,
89
+ title="""Mistral 7B v0.3"""
90
+ ).launch(show_api=False)