Spaces:
Running
Running
Update app.py
Browse files
app.py
CHANGED
@@ -1,7 +1,6 @@
|
|
1 |
import gradio as gr
|
2 |
import os
|
3 |
import spaces
|
4 |
-
from transformers import GemmaTokenizer, AutoModelForCausalLM
|
5 |
from transformers import AutoModelForCausalLM, AutoTokenizer, TextIteratorStreamer
|
6 |
from threading import Thread
|
7 |
|
@@ -12,35 +11,10 @@ HF_TOKEN = os.environ.get("HF_TOKEN", None)
|
|
12 |
DESCRIPTION = '''
|
13 |
<div>
|
14 |
<h1 style="text-align: center;">Mistral 7B Instruct v0.3</h1>
|
15 |
-
<p>This Space demonstrates the instruction-tuned model <a href="https://huggingface.co/mistralai/Mistral-7B-Instruct-v0.3"><b>mistralai/Mistral-7B-Instruct-v0.3</b></a>. The Mistral-7B-Instruct-v0.3 Large Language Model (LLM) is an instruct fine-tuned version of the Mistral-7B-v0.3, which is a Mistral-7B-v0.2 with extended vocabulary. Feel free to play with it, or duplicate to run privately!</p>
|
16 |
-
<p>🔎 For more details about the release and how to use the model with <code>transformers</code>, visit the model-card linked above.</p>
|
17 |
-
<p>🦕 The Instruct model - Has Extended vocabulary to 32768. Supports v3 Tokenizer. Supports function calling.</p>
|
18 |
</div>
|
19 |
'''
|
20 |
|
21 |
|
22 |
-
PLACEHOLDER = """
|
23 |
-
<div style="padding: 30px; text-align: center; display: flex; flex-direction: column; align-items: center;">
|
24 |
-
<img src="https://cdn-thumbnails.huggingface.co/social-thumbnails/models/mistralai/Mistral-7B-Instruct-v0.3.png" style="width: 70%; max-width: 550px; height: auto; opacity: 0.55; ">
|
25 |
-
<p style="font-size: 20px; margin-bottom: 2px; opacity: 0.65;">Ask me anything...</p>
|
26 |
-
</div>
|
27 |
-
"""
|
28 |
-
|
29 |
-
|
30 |
-
css = """
|
31 |
-
h1 {
|
32 |
-
text-align: center;
|
33 |
-
display: block;
|
34 |
-
}
|
35 |
-
|
36 |
-
#duplicate-button {
|
37 |
-
margin: auto;
|
38 |
-
color: white;
|
39 |
-
background: #1565c0;
|
40 |
-
border-radius: 100vh;
|
41 |
-
}
|
42 |
-
"""
|
43 |
-
|
44 |
# Load the tokenizer and model
|
45 |
tokenizer = AutoTokenizer.from_pretrained("mistralai/Mistral-7B-Instruct-v0.3")
|
46 |
model = AutoModelForCausalLM.from_pretrained("mistralai/Mistral-7B-Instruct-v0.3", device_map="auto")
|
@@ -92,44 +66,14 @@ def chat_mistral7b_v0dot3(message: str,
|
|
92 |
outputs = []
|
93 |
for text in streamer:
|
94 |
outputs.append(text)
|
95 |
-
#print(outputs)
|
96 |
yield "".join(outputs)
|
97 |
-
|
98 |
-
|
99 |
-
# Gradio block
|
100 |
-
chatbot=gr.Chatbot(height=450, placeholder=PLACEHOLDER, label='Gradio ChatInterface')
|
101 |
|
102 |
-
with gr.Blocks(
|
103 |
|
104 |
-
gr.
|
105 |
-
gr.DuplicateButton(value="Duplicate Space for private use", elem_id="duplicate-button")
|
106 |
-
gr.ChatInterface(
|
107 |
fn=chat_mistral7b_v0dot3,
|
108 |
-
|
109 |
-
|
110 |
-
additional_inputs_accordion=gr.Accordion(label="⚙️ Parameters", open=False, render=False),
|
111 |
-
additional_inputs=[
|
112 |
-
gr.Slider(minimum=0,
|
113 |
-
maximum=1,
|
114 |
-
step=0.1,
|
115 |
-
value=0.95,
|
116 |
-
label="Temperature",
|
117 |
-
render=False),
|
118 |
-
gr.Slider(minimum=128,
|
119 |
-
maximum=4096,
|
120 |
-
step=1,
|
121 |
-
value=512,
|
122 |
-
label="Max new tokens",
|
123 |
-
render=False ),
|
124 |
-
],
|
125 |
-
examples=[
|
126 |
-
['How to setup a human base on Mars? Give short answer.'],
|
127 |
-
['Explain theory of relativity to me like I’m 8 years old.'],
|
128 |
-
['What is 9,000 * 9,000?'],
|
129 |
-
['Write a pun-filled happy birthday message to my friend Alex.'],
|
130 |
-
['Justify why a penguin might make a good king of the jungle.']
|
131 |
-
],
|
132 |
-
cache_examples=False,
|
133 |
)
|
134 |
|
135 |
|
|
|
1 |
import gradio as gr
|
2 |
import os
|
3 |
import spaces
|
|
|
4 |
from transformers import AutoModelForCausalLM, AutoTokenizer, TextIteratorStreamer
|
5 |
from threading import Thread
|
6 |
|
|
|
11 |
DESCRIPTION = '''
|
12 |
<div>
|
13 |
<h1 style="text-align: center;">Mistral 7B Instruct v0.3</h1>
|
|
|
|
|
|
|
14 |
</div>
|
15 |
'''
|
16 |
|
17 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
18 |
# Load the tokenizer and model
|
19 |
tokenizer = AutoTokenizer.from_pretrained("mistralai/Mistral-7B-Instruct-v0.3")
|
20 |
model = AutoModelForCausalLM.from_pretrained("mistralai/Mistral-7B-Instruct-v0.3", device_map="auto")
|
|
|
66 |
outputs = []
|
67 |
for text in streamer:
|
68 |
outputs.append(text)
|
|
|
69 |
yield "".join(outputs)
|
|
|
|
|
|
|
|
|
70 |
|
71 |
+
with gr.Blocks() as demo:
|
72 |
|
73 |
+
gr.Interface(
|
|
|
|
|
74 |
fn=chat_mistral7b_v0dot3,
|
75 |
+
inputs=[gr.Textbox(), gr.Textbox(), gr.Numbers(), gr.Numbers()],
|
76 |
+
outputs=[gr.Texbox()]
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
77 |
)
|
78 |
|
79 |
|