Update app.py
Browse files
app.py
CHANGED
@@ -1,5 +1,3 @@
|
|
1 |
-
#!/usr/bin/env python
|
2 |
-
|
3 |
import os
|
4 |
from collections.abc import Iterator
|
5 |
from threading import Thread
|
@@ -22,7 +20,6 @@ CUSTOM_CSS = """
|
|
22 |
# 2) Description: Add French greeting, plus any info
|
23 |
#
|
24 |
DESCRIPTION = """# Bonjour Dans le chat du consentement
|
25 |
-
|
26 |
Mistral-7B Instruct Demo
|
27 |
"""
|
28 |
|
@@ -31,8 +28,6 @@ if not torch.cuda.is_available():
|
|
31 |
"\n<p style='color:red;'>Running on CPU - This is likely too large to run effectively.</p>"
|
32 |
)
|
33 |
|
34 |
-
MAX_MAX_NEW_TOKENS = 2048
|
35 |
-
DEFAULT_MAX_NEW_TOKENS = 1024
|
36 |
MAX_INPUT_TOKEN_LENGTH = int(os.getenv("MAX_INPUT_TOKEN_LENGTH", "4096"))
|
37 |
|
38 |
#
|
@@ -42,13 +37,15 @@ if torch.cuda.is_available():
|
|
42 |
model_id = "mistralai/Mistral-7B-Instruct-v0.3"
|
43 |
tokenizer = AutoTokenizer.from_pretrained(
|
44 |
model_id,
|
45 |
-
trust_remote_code=True # Might be needed for custom code
|
|
|
46 |
)
|
47 |
model = AutoModelForCausalLM.from_pretrained(
|
48 |
model_id,
|
49 |
torch_dtype=torch.float16,
|
50 |
device_map="auto",
|
51 |
-
trust_remote_code=True
|
|
|
52 |
)
|
53 |
|
54 |
def generate(
|
@@ -101,49 +98,12 @@ def generate(
|
|
101 |
yield "".join(outputs)
|
102 |
|
103 |
#
|
104 |
-
# 4) Build the Chat Interface
|
105 |
#
|
106 |
demo = gr.ChatInterface(
|
107 |
fn=generate,
|
108 |
description=DESCRIPTION,
|
109 |
-
css=CUSTOM_CSS,
|
110 |
-
additional_inputs=[
|
111 |
-
gr.Slider(
|
112 |
-
label="Max new tokens",
|
113 |
-
minimum=1,
|
114 |
-
maximum=MAX_MAX_NEW_TOKENS,
|
115 |
-
step=1,
|
116 |
-
value=DEFAULT_MAX_NEW_TOKENS,
|
117 |
-
),
|
118 |
-
gr.Slider(
|
119 |
-
label="Temperature",
|
120 |
-
minimum=0.1,
|
121 |
-
maximum=4.0,
|
122 |
-
step=0.1,
|
123 |
-
value=0.6,
|
124 |
-
),
|
125 |
-
gr.Slider(
|
126 |
-
label="Top-p (nucleus sampling)",
|
127 |
-
minimum=0.05,
|
128 |
-
maximum=1.0,
|
129 |
-
step=0.05,
|
130 |
-
value=0.9,
|
131 |
-
),
|
132 |
-
gr.Slider(
|
133 |
-
label="Top-k",
|
134 |
-
minimum=1,
|
135 |
-
maximum=1000,
|
136 |
-
step=1,
|
137 |
-
value=50,
|
138 |
-
),
|
139 |
-
gr.Slider(
|
140 |
-
label="Repetition penalty",
|
141 |
-
minimum=1.0,
|
142 |
-
maximum=2.0,
|
143 |
-
step=0.05,
|
144 |
-
value=1.2,
|
145 |
-
),
|
146 |
-
],
|
147 |
stop_btn=None,
|
148 |
examples=[
|
149 |
["Hello there! How are you doing?"],
|
@@ -156,4 +116,4 @@ demo = gr.ChatInterface(
|
|
156 |
)
|
157 |
|
158 |
if __name__ == "__main__":
|
159 |
-
demo.queue(max_size=20).launch()
|
|
|
|
|
|
|
1 |
import os
|
2 |
from collections.abc import Iterator
|
3 |
from threading import Thread
|
|
|
20 |
# 2) Description: Add French greeting, plus any info
|
21 |
#
|
22 |
DESCRIPTION = """# Bonjour Dans le chat du consentement
|
|
|
23 |
Mistral-7B Instruct Demo
|
24 |
"""
|
25 |
|
|
|
28 |
"\n<p style='color:red;'>Running on CPU - This is likely too large to run effectively.</p>"
|
29 |
)
|
30 |
|
|
|
|
|
31 |
MAX_INPUT_TOKEN_LENGTH = int(os.getenv("MAX_INPUT_TOKEN_LENGTH", "4096"))
|
32 |
|
33 |
#
|
|
|
37 |
model_id = "mistralai/Mistral-7B-Instruct-v0.3"
|
38 |
tokenizer = AutoTokenizer.from_pretrained(
|
39 |
model_id,
|
40 |
+
trust_remote_code=True, # Might be needed for custom code
|
41 |
+
use_auth_token=True
|
42 |
)
|
43 |
model = AutoModelForCausalLM.from_pretrained(
|
44 |
model_id,
|
45 |
torch_dtype=torch.float16,
|
46 |
device_map="auto",
|
47 |
+
trust_remote_code=True,
|
48 |
+
use_auth_token=True
|
49 |
)
|
50 |
|
51 |
def generate(
|
|
|
98 |
yield "".join(outputs)
|
99 |
|
100 |
#
|
101 |
+
# 4) Build the Chat Interface without additional inputs
|
102 |
#
|
103 |
demo = gr.ChatInterface(
|
104 |
fn=generate,
|
105 |
description=DESCRIPTION,
|
106 |
+
css=CUSTOM_CSS,
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
107 |
stop_btn=None,
|
108 |
examples=[
|
109 |
["Hello there! How are you doing?"],
|
|
|
116 |
)
|
117 |
|
118 |
if __name__ == "__main__":
|
119 |
+
demo.queue(max_size=20).launch(share=True)
|