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"colab": {
|
6 |
+
"provenance": []
|
7 |
+
},
|
8 |
+
"kernelspec": {
|
9 |
+
"name": "python3",
|
10 |
+
"display_name": "Python 3"
|
11 |
+
},
|
12 |
+
"language_info": {
|
13 |
+
"name": "python"
|
14 |
+
}
|
15 |
+
},
|
16 |
+
"cells": [
|
17 |
+
{
|
18 |
+
"cell_type": "code",
|
19 |
+
"execution_count": null,
|
20 |
+
"metadata": {
|
21 |
+
"colab": {
|
22 |
+
"base_uri": "https://localhost:8080/"
|
23 |
+
},
|
24 |
+
"id": "Sxst9V_x6WU-",
|
25 |
+
"outputId": "30153ecc-3e4f-42b8-c704-8af35a47f291"
|
26 |
+
},
|
27 |
+
"outputs": [
|
28 |
+
{
|
29 |
+
"output_type": "stream",
|
30 |
+
"name": "stdout",
|
31 |
+
"text": [
|
32 |
+
"Requirement already satisfied: gradio in /usr/local/lib/python3.10/dist-packages (4.13.0)\n",
|
33 |
+
"Requirement already satisfied: aiofiles<24.0,>=22.0 in /usr/local/lib/python3.10/dist-packages (from gradio) (23.2.1)\n",
|
34 |
+
"Requirement already satisfied: altair<6.0,>=4.2.0 in /usr/local/lib/python3.10/dist-packages (from gradio) (4.2.2)\n",
|
35 |
+
"Requirement already satisfied: fastapi in /usr/local/lib/python3.10/dist-packages (from gradio) (0.108.0)\n",
|
36 |
+
"Requirement already satisfied: ffmpy in /usr/local/lib/python3.10/dist-packages (from gradio) (0.3.1)\n",
|
37 |
+
"Requirement already satisfied: gradio-client==0.8.0 in /usr/local/lib/python3.10/dist-packages (from gradio) (0.8.0)\n",
|
38 |
+
"Requirement already satisfied: httpx in /usr/local/lib/python3.10/dist-packages (from gradio) (0.26.0)\n",
|
39 |
+
"Requirement already satisfied: huggingface-hub>=0.19.3 in /usr/local/lib/python3.10/dist-packages (from gradio) (0.20.1)\n",
|
40 |
+
"Requirement already satisfied: importlib-resources<7.0,>=1.3 in /usr/local/lib/python3.10/dist-packages (from gradio) (6.1.1)\n",
|
41 |
+
"Requirement already satisfied: jinja2<4.0 in /usr/local/lib/python3.10/dist-packages (from gradio) (3.1.2)\n",
|
42 |
+
"Requirement already satisfied: markupsafe~=2.0 in /usr/local/lib/python3.10/dist-packages (from gradio) (2.1.3)\n",
|
43 |
+
"Requirement already satisfied: matplotlib~=3.0 in /usr/local/lib/python3.10/dist-packages (from gradio) (3.7.1)\n",
|
44 |
+
"Requirement already satisfied: numpy~=1.0 in /usr/local/lib/python3.10/dist-packages (from gradio) (1.23.5)\n",
|
45 |
+
"Requirement already satisfied: orjson~=3.0 in /usr/local/lib/python3.10/dist-packages (from gradio) (3.9.10)\n",
|
46 |
+
"Requirement already satisfied: packaging in /usr/local/lib/python3.10/dist-packages (from gradio) (23.2)\n",
|
47 |
+
"Requirement already satisfied: pandas<3.0,>=1.0 in /usr/local/lib/python3.10/dist-packages (from gradio) (1.5.3)\n",
|
48 |
+
"Requirement already satisfied: pillow<11.0,>=8.0 in /usr/local/lib/python3.10/dist-packages (from gradio) (9.4.0)\n",
|
49 |
+
"Requirement already satisfied: pydantic>=2.0 in /usr/local/lib/python3.10/dist-packages (from gradio) (2.5.3)\n",
|
50 |
+
"Requirement already satisfied: pydub in /usr/local/lib/python3.10/dist-packages (from gradio) (0.25.1)\n",
|
51 |
+
"Requirement already satisfied: python-multipart in /usr/local/lib/python3.10/dist-packages (from gradio) (0.0.6)\n",
|
52 |
+
"Requirement already satisfied: pyyaml<7.0,>=5.0 in /usr/local/lib/python3.10/dist-packages (from gradio) (6.0.1)\n",
|
53 |
+
"Requirement already satisfied: semantic-version~=2.0 in /usr/local/lib/python3.10/dist-packages (from gradio) (2.10.0)\n",
|
54 |
+
"Requirement already satisfied: tomlkit==0.12.0 in /usr/local/lib/python3.10/dist-packages (from gradio) (0.12.0)\n",
|
55 |
+
"Requirement already satisfied: typer[all]<1.0,>=0.9 in /usr/local/lib/python3.10/dist-packages (from gradio) (0.9.0)\n",
|
56 |
+
"Requirement already satisfied: typing-extensions~=4.0 in /usr/local/lib/python3.10/dist-packages (from gradio) (4.9.0)\n",
|
57 |
+
"Requirement already satisfied: uvicorn>=0.14.0 in /usr/local/lib/python3.10/dist-packages (from gradio) (0.25.0)\n",
|
58 |
+
"Requirement already satisfied: fsspec in /usr/local/lib/python3.10/dist-packages (from gradio-client==0.8.0->gradio) (2023.6.0)\n",
|
59 |
+
"Requirement already satisfied: websockets<12.0,>=10.0 in /usr/local/lib/python3.10/dist-packages (from gradio-client==0.8.0->gradio) (11.0.3)\n",
|
60 |
+
"Requirement already satisfied: entrypoints in /usr/local/lib/python3.10/dist-packages (from altair<6.0,>=4.2.0->gradio) (0.4)\n",
|
61 |
+
"Requirement already satisfied: jsonschema>=3.0 in /usr/local/lib/python3.10/dist-packages (from altair<6.0,>=4.2.0->gradio) (4.19.2)\n",
|
62 |
+
"Requirement already satisfied: toolz in /usr/local/lib/python3.10/dist-packages (from altair<6.0,>=4.2.0->gradio) (0.12.0)\n",
|
63 |
+
"Requirement already satisfied: filelock in /usr/local/lib/python3.10/dist-packages (from huggingface-hub>=0.19.3->gradio) (3.13.1)\n",
|
64 |
+
"Requirement already satisfied: requests in /usr/local/lib/python3.10/dist-packages (from huggingface-hub>=0.19.3->gradio) (2.31.0)\n",
|
65 |
+
"Requirement already satisfied: tqdm>=4.42.1 in /usr/local/lib/python3.10/dist-packages (from huggingface-hub>=0.19.3->gradio) (4.66.1)\n",
|
66 |
+
"Requirement already satisfied: contourpy>=1.0.1 in /usr/local/lib/python3.10/dist-packages (from matplotlib~=3.0->gradio) (1.2.0)\n",
|
67 |
+
"Requirement already satisfied: cycler>=0.10 in /usr/local/lib/python3.10/dist-packages (from matplotlib~=3.0->gradio) (0.12.1)\n",
|
68 |
+
"Requirement already satisfied: fonttools>=4.22.0 in /usr/local/lib/python3.10/dist-packages (from matplotlib~=3.0->gradio) (4.47.0)\n",
|
69 |
+
"Requirement already satisfied: kiwisolver>=1.0.1 in /usr/local/lib/python3.10/dist-packages (from matplotlib~=3.0->gradio) (1.4.5)\n",
|
70 |
+
"Requirement already satisfied: pyparsing>=2.3.1 in /usr/local/lib/python3.10/dist-packages (from matplotlib~=3.0->gradio) (3.1.1)\n",
|
71 |
+
"Requirement already satisfied: python-dateutil>=2.7 in /usr/local/lib/python3.10/dist-packages (from matplotlib~=3.0->gradio) (2.8.2)\n",
|
72 |
+
"Requirement already satisfied: pytz>=2020.1 in /usr/local/lib/python3.10/dist-packages (from pandas<3.0,>=1.0->gradio) (2023.3.post1)\n",
|
73 |
+
"Requirement already satisfied: annotated-types>=0.4.0 in /usr/local/lib/python3.10/dist-packages (from pydantic>=2.0->gradio) (0.6.0)\n",
|
74 |
+
"Requirement already satisfied: pydantic-core==2.14.6 in /usr/local/lib/python3.10/dist-packages (from pydantic>=2.0->gradio) (2.14.6)\n",
|
75 |
+
"Requirement already satisfied: click<9.0.0,>=7.1.1 in /usr/local/lib/python3.10/dist-packages (from typer[all]<1.0,>=0.9->gradio) (8.1.7)\n",
|
76 |
+
"Requirement already satisfied: colorama<0.5.0,>=0.4.3 in /usr/local/lib/python3.10/dist-packages (from typer[all]<1.0,>=0.9->gradio) (0.4.6)\n",
|
77 |
+
"Requirement already satisfied: shellingham<2.0.0,>=1.3.0 in /usr/local/lib/python3.10/dist-packages (from typer[all]<1.0,>=0.9->gradio) (1.5.4)\n",
|
78 |
+
"Requirement already satisfied: rich<14.0.0,>=10.11.0 in /usr/local/lib/python3.10/dist-packages (from typer[all]<1.0,>=0.9->gradio) (13.7.0)\n",
|
79 |
+
"Requirement already satisfied: h11>=0.8 in /usr/local/lib/python3.10/dist-packages (from uvicorn>=0.14.0->gradio) (0.14.0)\n",
|
80 |
+
"Requirement already satisfied: starlette<0.33.0,>=0.29.0 in /usr/local/lib/python3.10/dist-packages (from fastapi->gradio) (0.32.0.post1)\n",
|
81 |
+
"Requirement already satisfied: anyio in /usr/local/lib/python3.10/dist-packages (from httpx->gradio) (3.7.1)\n",
|
82 |
+
"Requirement already satisfied: certifi in /usr/local/lib/python3.10/dist-packages (from httpx->gradio) (2023.11.17)\n",
|
83 |
+
"Requirement already satisfied: httpcore==1.* in /usr/local/lib/python3.10/dist-packages (from httpx->gradio) (1.0.2)\n",
|
84 |
+
"Requirement already satisfied: idna in /usr/local/lib/python3.10/dist-packages (from httpx->gradio) (3.6)\n",
|
85 |
+
"Requirement already satisfied: sniffio in /usr/local/lib/python3.10/dist-packages (from httpx->gradio) (1.3.0)\n",
|
86 |
+
"Requirement already satisfied: attrs>=22.2.0 in /usr/local/lib/python3.10/dist-packages (from jsonschema>=3.0->altair<6.0,>=4.2.0->gradio) (23.1.0)\n",
|
87 |
+
"Requirement already satisfied: jsonschema-specifications>=2023.03.6 in /usr/local/lib/python3.10/dist-packages (from jsonschema>=3.0->altair<6.0,>=4.2.0->gradio) (2023.11.2)\n",
|
88 |
+
"Requirement already satisfied: referencing>=0.28.4 in /usr/local/lib/python3.10/dist-packages (from jsonschema>=3.0->altair<6.0,>=4.2.0->gradio) (0.32.0)\n",
|
89 |
+
"Requirement already satisfied: rpds-py>=0.7.1 in /usr/local/lib/python3.10/dist-packages (from jsonschema>=3.0->altair<6.0,>=4.2.0->gradio) (0.15.2)\n",
|
90 |
+
"Requirement already satisfied: six>=1.5 in /usr/local/lib/python3.10/dist-packages (from python-dateutil>=2.7->matplotlib~=3.0->gradio) (1.16.0)\n",
|
91 |
+
"Requirement already satisfied: markdown-it-py>=2.2.0 in /usr/local/lib/python3.10/dist-packages (from rich<14.0.0,>=10.11.0->typer[all]<1.0,>=0.9->gradio) (3.0.0)\n",
|
92 |
+
"Requirement already satisfied: pygments<3.0.0,>=2.13.0 in /usr/local/lib/python3.10/dist-packages (from rich<14.0.0,>=10.11.0->typer[all]<1.0,>=0.9->gradio) (2.16.1)\n",
|
93 |
+
"Requirement already satisfied: exceptiongroup in /usr/local/lib/python3.10/dist-packages (from anyio->httpx->gradio) (1.2.0)\n",
|
94 |
+
"Requirement already satisfied: charset-normalizer<4,>=2 in /usr/local/lib/python3.10/dist-packages (from requests->huggingface-hub>=0.19.3->gradio) (3.3.2)\n",
|
95 |
+
"Requirement already satisfied: urllib3<3,>=1.21.1 in /usr/local/lib/python3.10/dist-packages (from requests->huggingface-hub>=0.19.3->gradio) (2.0.7)\n",
|
96 |
+
"Requirement already satisfied: mdurl~=0.1 in /usr/local/lib/python3.10/dist-packages (from markdown-it-py>=2.2.0->rich<14.0.0,>=10.11.0->typer[all]<1.0,>=0.9->gradio) (0.1.2)\n"
|
97 |
+
]
|
98 |
+
}
|
99 |
+
],
|
100 |
+
"source": [
|
101 |
+
"pip install gradio"
|
102 |
+
]
|
103 |
+
},
|
104 |
+
{
|
105 |
+
"cell_type": "code",
|
106 |
+
"source": [
|
107 |
+
"import gradio as gr\n",
|
108 |
+
"from datetime import datetime\n",
|
109 |
+
"\n",
|
110 |
+
"#Thème personnalisé\n",
|
111 |
+
"theme_chat = gr.themes.Soft(\n",
|
112 |
+
" primary_hue=\"yellow\",\n",
|
113 |
+
" secondary_hue=\"violet\",\n",
|
114 |
+
" neutral_hue=\"cyan\",\n",
|
115 |
+
")\n",
|
116 |
+
"\n",
|
117 |
+
"custom_css=\"\"\"\n",
|
118 |
+
"h1 {\n",
|
119 |
+
" font-size: 80px;\n",
|
120 |
+
" margin-left: 42%;\n",
|
121 |
+
" font-style: solid;\n",
|
122 |
+
" }\n",
|
123 |
+
"\n",
|
124 |
+
"p {\n",
|
125 |
+
" font-size: 25px;\n",
|
126 |
+
" text-decoration: underline;\n",
|
127 |
+
"}\n",
|
128 |
+
"\"\"\"\n",
|
129 |
+
"\n",
|
130 |
+
"def yes_man(message, history):\n",
|
131 |
+
" if message==\"Bonjour\":\n",
|
132 |
+
" return \"Bonjour, comment allez-vous ?\"\n",
|
133 |
+
" elif message ==\"Que signifie ton nom ?\":\n",
|
134 |
+
" return \"Mon nom, bien que je sois un robot, est basé sur un jeu de mot avec notre camarade Vithia ! Beep boop ha-ha-ha !🤖😂\"\n",
|
135 |
+
" elif message ==\"Combien de thunes à perdu Dany en pari ?\":\n",
|
136 |
+
" return \"Dany a perdu l'equivalent de : (√7 * 2 + log(10)) / (π^2 - sin(42)) euros !\"\n",
|
137 |
+
"\n",
|
138 |
+
"# Créer l'interface Gradio avec le thème personnalisé\n",
|
139 |
+
"interface = gr.ChatInterface(\n",
|
140 |
+
" yes_man,\n",
|
141 |
+
" chatbot=gr.Chatbot(height=500),\n",
|
142 |
+
" textbox=gr.Textbox(placeholder=\"Posez moi une question sur le CoronaVirus\", container=False, scale=7),\n",
|
143 |
+
" title=\"Vit'IA\",\n",
|
144 |
+
" description=\"Posez une question à Vit'IA :\",\n",
|
145 |
+
" examples=[\"Bonjour\", \"Que signifie ton nom ?\", \"Combien de thunes à perdu Dany en pari ?\"],\n",
|
146 |
+
" cache_examples=False,\n",
|
147 |
+
" retry_btn=\"Générer une nouvelle réponse\",\n",
|
148 |
+
" undo_btn=\"Supprimer la réponse précédente\",\n",
|
149 |
+
" clear_btn=\"Effacer\",\n",
|
150 |
+
" submit_btn=\"Envoyer\",\n",
|
151 |
+
" css= custom_css,\n",
|
152 |
+
" theme=theme_chat # Utiliser le thème personnalisé ici\n",
|
153 |
+
")\n",
|
154 |
+
"\n",
|
155 |
+
"# Lancer l'interface\n",
|
156 |
+
"interface.launch()"
|
157 |
+
],
|
158 |
+
"metadata": {
|
159 |
+
"colab": {
|
160 |
+
"base_uri": "https://localhost:8080/",
|
161 |
+
"height": 626
|
162 |
+
},
|
163 |
+
"id": "rJhi_3PJ70pY",
|
164 |
+
"outputId": "c494f6e4-0ea2-46bc-df53-f62f375220ac"
|
165 |
+
},
|
166 |
+
"execution_count": null,
|
167 |
+
"outputs": [
|
168 |
+
{
|
169 |
+
"output_type": "stream",
|
170 |
+
"name": "stdout",
|
171 |
+
"text": [
|
172 |
+
"Setting queue=True in a Colab notebook requires sharing enabled. Setting `share=True` (you can turn this off by setting `share=False` in `launch()` explicitly).\n",
|
173 |
+
"\n",
|
174 |
+
"Colab notebook detected. To show errors in colab notebook, set debug=True in launch()\n",
|
175 |
+
"Running on public URL: https://3bfd599cd7708bc602.gradio.live\n",
|
176 |
+
"\n",
|
177 |
+
"This share link expires in 72 hours. For free permanent hosting and GPU upgrades, run `gradio deploy` from Terminal to deploy to Spaces (https://huggingface.co/spaces)\n"
|
178 |
+
]
|
179 |
+
},
|
180 |
+
{
|
181 |
+
"output_type": "display_data",
|
182 |
+
"data": {
|
183 |
+
"text/plain": [
|
184 |
+
"<IPython.core.display.HTML object>"
|
185 |
+
],
|
186 |
+
"text/html": [
|
187 |
+
"<div><iframe src=\"https://3bfd599cd7708bc602.gradio.live\" width=\"100%\" height=\"500\" allow=\"autoplay; camera; microphone; clipboard-read; clipboard-write;\" frameborder=\"0\" allowfullscreen></iframe></div>"
|
188 |
+
]
|
189 |
+
},
|
190 |
+
"metadata": {}
|
191 |
+
},
|
192 |
+
{
|
193 |
+
"output_type": "execute_result",
|
194 |
+
"data": {
|
195 |
+
"text/plain": []
|
196 |
+
},
|
197 |
+
"metadata": {},
|
198 |
+
"execution_count": 71
|
199 |
+
}
|
200 |
+
]
|
201 |
+
},
|
202 |
+
{
|
203 |
+
"cell_type": "code",
|
204 |
+
"source": [],
|
205 |
+
"metadata": {
|
206 |
+
"id": "dBZ2ydtFRA1k"
|
207 |
+
},
|
208 |
+
"execution_count": null,
|
209 |
+
"outputs": []
|
210 |
+
},
|
211 |
+
{
|
212 |
+
"cell_type": "code",
|
213 |
+
"source": [],
|
214 |
+
"metadata": {
|
215 |
+
"id": "-J9a36V3ETBy"
|
216 |
+
},
|
217 |
+
"execution_count": null,
|
218 |
+
"outputs": []
|
219 |
+
}
|
220 |
+
]
|
221 |
+
}
|