Spaces:
Sleeping
Sleeping
MarcdeFalco
commited on
Commit
•
9ab2b8f
1
Parent(s):
61563ce
Upload folder using huggingface_hub
Browse files- .github/workflows/update_space.yml +28 -0
- README.md +3 -9
- app.py +145 -0
- app.py~ +145 -0
- exercices.md +14 -0
- exercices.md~ +3 -0
- requirements.txt +2 -0
.github/workflows/update_space.yml
ADDED
@@ -0,0 +1,28 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
name: Run Python script
|
2 |
+
|
3 |
+
on:
|
4 |
+
push:
|
5 |
+
branches:
|
6 |
+
- main
|
7 |
+
|
8 |
+
jobs:
|
9 |
+
build:
|
10 |
+
runs-on: ubuntu-latest
|
11 |
+
|
12 |
+
steps:
|
13 |
+
- name: Checkout
|
14 |
+
uses: actions/checkout@v2
|
15 |
+
|
16 |
+
- name: Set up Python
|
17 |
+
uses: actions/setup-python@v2
|
18 |
+
with:
|
19 |
+
python-version: '3.9'
|
20 |
+
|
21 |
+
- name: Install Gradio
|
22 |
+
run: python -m pip install gradio
|
23 |
+
|
24 |
+
- name: Log in to Hugging Face
|
25 |
+
run: python -c 'import huggingface_hub; huggingface_hub.login(token="${{ secrets.hf_token }}")'
|
26 |
+
|
27 |
+
- name: Deploy to Spaces
|
28 |
+
run: gradio deploy
|
README.md
CHANGED
@@ -1,12 +1,6 @@
|
|
1 |
---
|
2 |
-
title:
|
3 |
-
emoji: 🌖
|
4 |
-
colorFrom: green
|
5 |
-
colorTo: green
|
6 |
-
sdk: gradio
|
7 |
-
sdk_version: 4.39.0
|
8 |
app_file: app.py
|
9 |
-
|
|
|
10 |
---
|
11 |
-
|
12 |
-
Check out the configuration reference at https://huggingface.co/docs/hub/spaces-config-reference
|
|
|
1 |
---
|
2 |
+
title: mathstral_test
|
|
|
|
|
|
|
|
|
|
|
3 |
app_file: app.py
|
4 |
+
sdk: gradio
|
5 |
+
sdk_version: 4.38.1
|
6 |
---
|
|
|
|
app.py
ADDED
@@ -0,0 +1,145 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
from huggingface_hub import InferenceClient
|
2 |
+
import gradio as gr
|
3 |
+
import os
|
4 |
+
|
5 |
+
API_URL = {
|
6 |
+
"Mistral" : "https://api-inference.huggingface.co/models/mistralai/Mistral-7B-Instruct-v0.3",
|
7 |
+
"Mixtral" : "https://api-inference.huggingface.co/models/mistralai/Mixtral-8x7B-Instruct-v0.1",
|
8 |
+
"Mathstral" : "https://api-inference.huggingface.co/models/mistralai/mathstral-7B-v0.1",
|
9 |
+
}
|
10 |
+
|
11 |
+
HF_TOKEN = os.environ['HF_TOKEN']
|
12 |
+
|
13 |
+
mistralClient = InferenceClient(
|
14 |
+
API_URL["Mistral"],
|
15 |
+
headers = {"Authorization" : f"Bearer {HF_TOKEN}"},
|
16 |
+
)
|
17 |
+
|
18 |
+
mixtralClient = InferenceClient(
|
19 |
+
model = API_URL["Mixtral"],
|
20 |
+
headers = {"Authorization" : f"Bearer {HF_TOKEN}"},
|
21 |
+
)
|
22 |
+
|
23 |
+
mathstralClient = InferenceClient(
|
24 |
+
model = API_URL["Mathstral"],
|
25 |
+
headers = {"Authorization" : f"Bearer {HF_TOKEN}"},
|
26 |
+
)
|
27 |
+
|
28 |
+
def format_prompt(message, history):
|
29 |
+
prompt = "<s>"
|
30 |
+
|
31 |
+
for user_prompt, bot_response in history:
|
32 |
+
prompt += f"[INST] {user_prompt} [/INST]"
|
33 |
+
prompt += f" {bot_response}</s> "
|
34 |
+
prompt += f"[INST] {message} [/INST]"
|
35 |
+
return prompt
|
36 |
+
|
37 |
+
def generate(prompt, history, temperature=0.9, max_new_tokens=256, top_p=0.95,
|
38 |
+
repetition_penalty=1.0, model = "Mathstral"):
|
39 |
+
# Selecting model to be used
|
40 |
+
if(model == "Mistral"):
|
41 |
+
client = mistralClient
|
42 |
+
elif(model == "Mixstral"):
|
43 |
+
client = mixtralClient
|
44 |
+
elif(model == "Mathstral"):
|
45 |
+
client = mixtralClient
|
46 |
+
|
47 |
+
|
48 |
+
temperature = float(temperature) # Generation arguments
|
49 |
+
if temperature < 1e-2:
|
50 |
+
temperature = 1e-2
|
51 |
+
|
52 |
+
top_p = float(top_p)
|
53 |
+
|
54 |
+
generate_kwargs = dict(
|
55 |
+
temperature=temperature,
|
56 |
+
max_new_tokens=max_new_tokens,
|
57 |
+
top_p=top_p,
|
58 |
+
repetition_penalty=repetition_penalty,
|
59 |
+
do_sample=True,
|
60 |
+
seed=42,
|
61 |
+
)
|
62 |
+
|
63 |
+
formatted_prompt = format_prompt(prompt, history)
|
64 |
+
stream = client.text_generation(formatted_prompt, **generate_kwargs, stream=True, details=True, return_full_text=False)
|
65 |
+
output = ""
|
66 |
+
for response in stream:
|
67 |
+
output += response.token.text
|
68 |
+
yield output
|
69 |
+
return output
|
70 |
+
|
71 |
+
additional_inputs=[
|
72 |
+
gr.Slider(
|
73 |
+
label="Temperature",
|
74 |
+
value=0.9,
|
75 |
+
minimum=0.0,
|
76 |
+
maximum=1.0,
|
77 |
+
step=0.05,
|
78 |
+
interactive=True,
|
79 |
+
info="Higher values produce more diverse outputs",
|
80 |
+
),
|
81 |
+
gr.Slider(
|
82 |
+
label="Max new tokens",
|
83 |
+
value=2048,
|
84 |
+
minimum=0,
|
85 |
+
maximum=4096,
|
86 |
+
step=64,
|
87 |
+
interactive=True,
|
88 |
+
info="The maximum numbers of new tokens",
|
89 |
+
),
|
90 |
+
gr.Slider(
|
91 |
+
label="Top-p (nucleus sampling)",
|
92 |
+
value=0.90,
|
93 |
+
minimum=0.0,
|
94 |
+
maximum=1,
|
95 |
+
step=0.05,
|
96 |
+
interactive=True,
|
97 |
+
info="Higher values sample more low-probability tokens",
|
98 |
+
),
|
99 |
+
gr.Slider(
|
100 |
+
label="Repetition penalty",
|
101 |
+
value=1.2,
|
102 |
+
minimum=1.0,
|
103 |
+
maximum=2.0,
|
104 |
+
step=0.05,
|
105 |
+
interactive=True,
|
106 |
+
info="Penalize repeated tokens",
|
107 |
+
),
|
108 |
+
gr.Dropdown(
|
109 |
+
choices = ["Mistral","Mixtral", "Mathstral"],
|
110 |
+
value = "Mathstral",
|
111 |
+
label = "Le modèle à utiliser",
|
112 |
+
interactive=True,
|
113 |
+
info = "Mistral : pour des conversations génériques, "+
|
114 |
+
"Mixtral : conversations plus rapides et plus performantes, "+
|
115 |
+
"Mathstral : raisonnement mathématiques et scientifique"
|
116 |
+
),
|
117 |
+
]
|
118 |
+
|
119 |
+
css = """
|
120 |
+
#mkd {
|
121 |
+
height: 500px;
|
122 |
+
overflow: auto;
|
123 |
+
border: 1px solid #ccc;
|
124 |
+
}
|
125 |
+
"""
|
126 |
+
|
127 |
+
with gr.Blocks(css=css) as demo:
|
128 |
+
gr.HTML("<h1><center>Mathstral Test</center><h1>")
|
129 |
+
gr.HTML("<h3><center>Dans cette démo, vous pouvez poser des questions mathématiques et scientifiques à Mathstral. 🧮</center><h3>")
|
130 |
+
gr.ChatInterface(
|
131 |
+
generate,
|
132 |
+
additional_inputs=additional_inputs,
|
133 |
+
theme = gr.themes.Soft(),
|
134 |
+
examples=[ [l.strip()] for l in open("exercices.md").readlines()],
|
135 |
+
chatbot = gr.Chatbot(
|
136 |
+
latex_delimiters=[
|
137 |
+
{"left" : "$$", "right": "$$", "display": True },
|
138 |
+
{"left" : "\\[", "right": "\\]", "display": True },
|
139 |
+
{"left" : "\\(", "right": "\\)", "display": False },
|
140 |
+
{"left": "$", "right": "$", "display": False }
|
141 |
+
]
|
142 |
+
)
|
143 |
+
)
|
144 |
+
|
145 |
+
demo.queue(max_size=100).launch(debug=True)
|
app.py~
ADDED
@@ -0,0 +1,145 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
from huggingface_hub import InferenceClient
|
2 |
+
import gradio as gr
|
3 |
+
import os
|
4 |
+
|
5 |
+
API_URL = {
|
6 |
+
"Mistral" : "https://api-inference.huggingface.co/models/mistralai/Mistral-7B-Instruct-v0.3",
|
7 |
+
"Mixtral" : "https://api-inference.huggingface.co/models/mistralai/Mixtral-8x7B-Instruct-v0.1",
|
8 |
+
"Mathstral" : "https://api-inference.huggingface.co/models/mistralai/mathstral-7B-v0.1",
|
9 |
+
}
|
10 |
+
|
11 |
+
HF_TOKEN = os.environ['HF_TOKEN']
|
12 |
+
|
13 |
+
mistralClient = InferenceClient(
|
14 |
+
API_URL["Mistral"],
|
15 |
+
headers = {"Authorization" : f"Bearer {HF_TOKEN}"},
|
16 |
+
)
|
17 |
+
|
18 |
+
mixtralClient = InferenceClient(
|
19 |
+
model = API_URL["Mixtral"],
|
20 |
+
headers = {"Authorization" : f"Bearer {HF_TOKEN}"},
|
21 |
+
)
|
22 |
+
|
23 |
+
mathstralClient = InferenceClient(
|
24 |
+
model = API_URL["Mathstral"],
|
25 |
+
headers = {"Authorization" : f"Bearer {HF_TOKEN}"},
|
26 |
+
)
|
27 |
+
|
28 |
+
def format_prompt(message, history):
|
29 |
+
prompt = "<s>"
|
30 |
+
|
31 |
+
for user_prompt, bot_response in history:
|
32 |
+
prompt += f"[INST] {user_prompt} [/INST]"
|
33 |
+
prompt += f" {bot_response}</s> "
|
34 |
+
prompt += f"[INST] {message} [/INST]"
|
35 |
+
return prompt
|
36 |
+
|
37 |
+
def generate(prompt, history, temperature=0.9, max_new_tokens=256, top_p=0.95,
|
38 |
+
repetition_penalty=1.0, model = "Mathstral"):
|
39 |
+
# Selecting model to be used
|
40 |
+
if(model == "Mistral"):
|
41 |
+
client = mistralClient
|
42 |
+
elif(model == "Mixstral"):
|
43 |
+
client = mixtralClient
|
44 |
+
elif(model == "Mathstral"):
|
45 |
+
client = mixtralClient
|
46 |
+
|
47 |
+
|
48 |
+
temperature = float(temperature) # Generation arguments
|
49 |
+
if temperature < 1e-2:
|
50 |
+
temperature = 1e-2
|
51 |
+
|
52 |
+
top_p = float(top_p)
|
53 |
+
|
54 |
+
generate_kwargs = dict(
|
55 |
+
temperature=temperature,
|
56 |
+
max_new_tokens=max_new_tokens,
|
57 |
+
top_p=top_p,
|
58 |
+
repetition_penalty=repetition_penalty,
|
59 |
+
do_sample=True,
|
60 |
+
seed=42,
|
61 |
+
)
|
62 |
+
|
63 |
+
formatted_prompt = format_prompt(prompt, history)
|
64 |
+
stream = client.text_generation(formatted_prompt, **generate_kwargs, stream=True, details=True, return_full_text=False)
|
65 |
+
output = ""
|
66 |
+
for response in stream:
|
67 |
+
output += response.token.text
|
68 |
+
yield output
|
69 |
+
return output
|
70 |
+
|
71 |
+
additional_inputs=[
|
72 |
+
gr.Slider(
|
73 |
+
label="Temperature",
|
74 |
+
value=0.9,
|
75 |
+
minimum=0.0,
|
76 |
+
maximum=1.0,
|
77 |
+
step=0.05,
|
78 |
+
interactive=True,
|
79 |
+
info="Higher values produce more diverse outputs",
|
80 |
+
),
|
81 |
+
gr.Slider(
|
82 |
+
label="Max new tokens",
|
83 |
+
value=2048,
|
84 |
+
minimum=0,
|
85 |
+
maximum=4096,
|
86 |
+
step=64,
|
87 |
+
interactive=True,
|
88 |
+
info="The maximum numbers of new tokens",
|
89 |
+
),
|
90 |
+
gr.Slider(
|
91 |
+
label="Top-p (nucleus sampling)",
|
92 |
+
value=0.90,
|
93 |
+
minimum=0.0,
|
94 |
+
maximum=1,
|
95 |
+
step=0.05,
|
96 |
+
interactive=True,
|
97 |
+
info="Higher values sample more low-probability tokens",
|
98 |
+
),
|
99 |
+
gr.Slider(
|
100 |
+
label="Repetition penalty",
|
101 |
+
value=1.2,
|
102 |
+
minimum=1.0,
|
103 |
+
maximum=2.0,
|
104 |
+
step=0.05,
|
105 |
+
interactive=True,
|
106 |
+
info="Penalize repeated tokens",
|
107 |
+
),
|
108 |
+
gr.Dropdown(
|
109 |
+
choices = ["Mistral","Mixtral", "Mathstral"],
|
110 |
+
value = "Mathstral",
|
111 |
+
label = "Le modèle à utiliser",
|
112 |
+
interactive=True,
|
113 |
+
info = "Mistral : pour des conversations génériques, "+
|
114 |
+
"Mixtral : conversations plus rapides et plus performantes, "+
|
115 |
+
"Mathstral : raisonnement mathématiques et scientifique"
|
116 |
+
),
|
117 |
+
]
|
118 |
+
|
119 |
+
css = """
|
120 |
+
#mkd {
|
121 |
+
height: 500px;
|
122 |
+
overflow: auto;
|
123 |
+
border: 1px solid #ccc;
|
124 |
+
}
|
125 |
+
"""
|
126 |
+
|
127 |
+
with gr.Blocks(css=css) as demo:
|
128 |
+
gr.HTML("<h1><center>Mathstral Test</center><h1>")
|
129 |
+
gr.HTML("<h3><center>Dans cette démo, vous pouvez poser des questions mathématiques et scientifiques à Mathstral. 🧮</center><h3>")
|
130 |
+
gr.ChatInterface(
|
131 |
+
generate,
|
132 |
+
additional_inputs=additional_inputs,
|
133 |
+
theme = gr.themes.Soft(),
|
134 |
+
examples=[ [l.strip()] for l in open("exercices.md").readlines()],
|
135 |
+
chatbot = gr.Chatbot(
|
136 |
+
latex_delimiters=[
|
137 |
+
{"left" : "$$", "right": "$$", "display": True },
|
138 |
+
{"left" : "\\[", "right": "\\]", "display": True },
|
139 |
+
{"left" : "\\(", "right": "\\)", "display": False },
|
140 |
+
{"left": "$", "right": "$", "display": False }
|
141 |
+
]
|
142 |
+
)
|
143 |
+
)
|
144 |
+
|
145 |
+
demo.queue(max_size=100).launch(debug=True)
|
exercices.md
ADDED
@@ -0,0 +1,14 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
Déterminer les fonctions $f : \\mathbb{R} \\rightarrow \\mathbb{R}$ dérivables et telles que $$\\forall x \\in \\mathbb{R}, f'(x) + f(x) = f(0) + f(1)$$
|
2 |
+
Soit $f : \mathbb{R} \rightarrow \mathbb{R}$ une fonction borneé et dérivable, telle que $\lim_{x \rightarrow +\infty} f' = l$. Montrer que $l = 0$.
|
3 |
+
Soit $f(x) = \int_{t=0}^1\frac{1-t}{\ln t}t^x\, dt$. Étudier le domaine de définition de $f$, sa dérivabilité, puis calculer $f(x)$.
|
4 |
+
Soit $(G,\, \star \,)$ un groupe tel que $$\forall x \in G,x^2 = e$$ Montrer que $G$ est commutatif.
|
5 |
+
Soit $(E,\, \star \,)$ un monoïde avec $E$ ensemble fini. Montrer que tout élément régulier de $E$ est inversible.
|
6 |
+
Factoriser le polynôme $(X + i)^n - (X - i)^n $ pour $n \in \mathbb{N}^\star$.
|
7 |
+
Soient $a \in \left] {0,\pi } \right[$ et $n \in \mathbb{N}^\star $. Factoriser dans $\mathbb{C}\left[ X \right]$ puis dans $\mathbb{R}\left[ X \right]$ le polynôme $$X^{2n} - 2\cos (na)X^n + 1$$
|
8 |
+
Soient $F,G,F',G'$ des sous-espaces vectoriels de $E$ tels que $F \cap G = F' \cap G'$. Montrer que $$(F + (G \cap F')) \cap (F + (G \cap G')) = F$$
|
9 |
+
Trouver les coordonnées des vecteurs suivants relativement à la base $\left( (1,1,1), (1,1,0), (1,0,0) \right)$ de $\mathbb{R}^3$ : $u = (4,-3,2)$ et $v = (a,b,c)$.
|
10 |
+
|
11 |
+
|
12 |
+
|
13 |
+
|
14 |
+
|
exercices.md~
ADDED
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
1 |
+
Déterminer les fonctions $f : \\mathbb{R} \\rightarrow \\mathbb{R}$ dérivables et telles que $$\\forall x \\in \\mathbb{R}, f'(x) + f(x) = f(0) + f(1)$$
|
2 |
+
Soit $f : \mathbb{R} \rightarrow \mathbb{R}$ une fonction borneé et dérivable, telle que $\lim_{x \rightarrow +\infty} f' = l$. Montrer que $l = 0$.
|
3 |
+
Soit $f(x) = \int_{t=0}^1\frac{1-t}{\ln t}t^x\, dt$. Étudier le domaine de définition de $f$, sa dérivabilité, puis calculer $f(x)$.
|
requirements.txt
ADDED
@@ -0,0 +1,2 @@
|
|
|
|
|
|
|
1 |
+
huggingface_hub
|
2 |
+
gradio
|