Spaces:
Running
Running
Andrej
commited on
Commit
·
d2ec744
1
Parent(s):
0f2526e
added description to demo
Browse files- .ipynb_checkpoints/app-checkpoint.ipynb +135 -43
- app.ipynb +135 -43
- app.py +17 -1
.ipynb_checkpoints/app-checkpoint.ipynb
CHANGED
@@ -194,7 +194,7 @@
|
|
194 |
},
|
195 |
{
|
196 |
"cell_type": "code",
|
197 |
-
"execution_count":
|
198 |
"id": "42242b57-3569-46f2-9966-c737dd6e6f16",
|
199 |
"metadata": {},
|
200 |
"outputs": [],
|
@@ -204,30 +204,29 @@
|
|
204 |
},
|
205 |
{
|
206 |
"cell_type": "code",
|
207 |
-
"execution_count":
|
208 |
"id": "4e41db23-e369-413d-ab25-f85cd21af0c4",
|
209 |
"metadata": {},
|
210 |
-
"outputs": [],
|
211 |
-
"source": [
|
212 |
-
"import gradio as gr"
|
213 |
-
]
|
214 |
-
},
|
215 |
-
{
|
216 |
-
"cell_type": "code",
|
217 |
-
"execution_count": 1,
|
218 |
-
"id": "411ef985-d45e-4b17-b33c-24fde7c00b4f",
|
219 |
-
"metadata": {},
|
220 |
"outputs": [
|
221 |
{
|
222 |
"name": "stderr",
|
223 |
"output_type": "stream",
|
224 |
"text": [
|
225 |
"/Users/macbook/.pyenv/versions/politvenv/lib/python3.10/site-packages/tqdm/auto.py:21: TqdmWarning: IProgress not found. Please update jupyter and ipywidgets. See https://ipywidgets.readthedocs.io/en/stable/user_install.html\n",
|
226 |
-
" from .autonotebook import tqdm as notebook_tqdm\n"
|
227 |
-
"Matplotlib is building the font cache; this may take a moment.\n"
|
228 |
]
|
229 |
}
|
230 |
],
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
231 |
"source": [
|
232 |
"#import gradio as gr\n",
|
233 |
"from autogluon.text import TextPredictor"
|
@@ -235,7 +234,7 @@
|
|
235 |
},
|
236 |
{
|
237 |
"cell_type": "code",
|
238 |
-
"execution_count":
|
239 |
"id": "7de002b3-e67f-46b9-95d1-e07a1bea7f5a",
|
240 |
"metadata": {},
|
241 |
"outputs": [],
|
@@ -246,7 +245,7 @@
|
|
246 |
},
|
247 |
{
|
248 |
"cell_type": "code",
|
249 |
-
"execution_count":
|
250 |
"id": "d3093469-f35f-4008-9da4-340c64a9f85a",
|
251 |
"metadata": {},
|
252 |
"outputs": [],
|
@@ -261,18 +260,42 @@
|
|
261 |
},
|
262 |
{
|
263 |
"cell_type": "code",
|
264 |
-
"execution_count":
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
265 |
"id": "8e2ad81f-5b87-47c1-a60a-fd45616e8fb0",
|
266 |
"metadata": {},
|
267 |
"outputs": [],
|
268 |
"source": [
|
269 |
"# Create a Gradio interface\n",
|
270 |
-
"demo = gr.Interface(
|
|
|
|
|
|
|
|
|
|
|
|
|
271 |
]
|
272 |
},
|
273 |
{
|
274 |
"cell_type": "code",
|
275 |
-
"execution_count":
|
276 |
"id": "18d88162-30cc-4a6b-8581-793ed65aef0f",
|
277 |
"metadata": {},
|
278 |
"outputs": [
|
@@ -280,7 +303,7 @@
|
|
280 |
"name": "stdout",
|
281 |
"output_type": "stream",
|
282 |
"text": [
|
283 |
-
"Running on local URL: http://127.0.0.1:
|
284 |
"\n",
|
285 |
"To create a public link, set `share=True` in `launch()`.\n"
|
286 |
]
|
@@ -288,7 +311,7 @@
|
|
288 |
{
|
289 |
"data": {
|
290 |
"text/html": [
|
291 |
-
"<div><iframe src=\"http://127.0.0.1:
|
292 |
],
|
293 |
"text/plain": [
|
294 |
"<IPython.core.display.HTML object>"
|
@@ -301,39 +324,108 @@
|
|
301 |
"data": {
|
302 |
"text/plain": []
|
303 |
},
|
304 |
-
"execution_count":
|
305 |
"metadata": {},
|
306 |
"output_type": "execute_result"
|
307 |
-
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
308 |
{
|
309 |
-
"name": "
|
310 |
"output_type": "stream",
|
311 |
"text": [
|
312 |
-
"
|
313 |
-
"
|
314 |
-
"
|
315 |
-
"Global seed set to 123\n",
|
316 |
-
"/Users/macbook/.pyenv/versions/politvenv/lib/python3.10/site-packages/autogluon/multimodal/utils/environment.py:50: UserWarning: Using the detected GPU number 0, smaller than the GPU number 1 in the config.\n",
|
317 |
-
" warnings.warn(\n",
|
318 |
-
"Global seed set to 123\n",
|
319 |
-
"/Users/macbook/.pyenv/versions/politvenv/lib/python3.10/site-packages/autogluon/multimodal/utils/environment.py:50: UserWarning: Using the detected GPU number 0, smaller than the GPU number 1 in the config.\n",
|
320 |
-
" warnings.warn(\n",
|
321 |
-
"Global seed set to 123\n",
|
322 |
-
"/Users/macbook/.pyenv/versions/politvenv/lib/python3.10/site-packages/autogluon/multimodal/utils/environment.py:50: UserWarning: Using the detected GPU number 0, smaller than the GPU number 1 in the config.\n",
|
323 |
-
" warnings.warn(\n",
|
324 |
-
"Global seed set to 123\n",
|
325 |
-
"/Users/macbook/.pyenv/versions/politvenv/lib/python3.10/site-packages/autogluon/multimodal/utils/environment.py:50: UserWarning: Using the detected GPU number 0, smaller than the GPU number 1 in the config.\n",
|
326 |
-
" warnings.warn(\n",
|
327 |
-
"Global seed set to 123\n",
|
328 |
-
"/Users/macbook/.pyenv/versions/politvenv/lib/python3.10/site-packages/autogluon/multimodal/utils/environment.py:50: UserWarning: Using the detected GPU number 0, smaller than the GPU number 1 in the config.\n",
|
329 |
-
" warnings.warn(\n"
|
330 |
]
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
331 |
}
|
332 |
],
|
333 |
"source": [
|
334 |
-
"# Launch the app\n",
|
335 |
"demo.launch()"
|
336 |
]
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
337 |
}
|
338 |
],
|
339 |
"metadata": {
|
|
|
194 |
},
|
195 |
{
|
196 |
"cell_type": "code",
|
197 |
+
"execution_count": 1,
|
198 |
"id": "42242b57-3569-46f2-9966-c737dd6e6f16",
|
199 |
"metadata": {},
|
200 |
"outputs": [],
|
|
|
204 |
},
|
205 |
{
|
206 |
"cell_type": "code",
|
207 |
+
"execution_count": 2,
|
208 |
"id": "4e41db23-e369-413d-ab25-f85cd21af0c4",
|
209 |
"metadata": {},
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
210 |
"outputs": [
|
211 |
{
|
212 |
"name": "stderr",
|
213 |
"output_type": "stream",
|
214 |
"text": [
|
215 |
"/Users/macbook/.pyenv/versions/politvenv/lib/python3.10/site-packages/tqdm/auto.py:21: TqdmWarning: IProgress not found. Please update jupyter and ipywidgets. See https://ipywidgets.readthedocs.io/en/stable/user_install.html\n",
|
216 |
+
" from .autonotebook import tqdm as notebook_tqdm\n"
|
|
|
217 |
]
|
218 |
}
|
219 |
],
|
220 |
+
"source": [
|
221 |
+
"import gradio as gr"
|
222 |
+
]
|
223 |
+
},
|
224 |
+
{
|
225 |
+
"cell_type": "code",
|
226 |
+
"execution_count": 3,
|
227 |
+
"id": "411ef985-d45e-4b17-b33c-24fde7c00b4f",
|
228 |
+
"metadata": {},
|
229 |
+
"outputs": [],
|
230 |
"source": [
|
231 |
"#import gradio as gr\n",
|
232 |
"from autogluon.text import TextPredictor"
|
|
|
234 |
},
|
235 |
{
|
236 |
"cell_type": "code",
|
237 |
+
"execution_count": 4,
|
238 |
"id": "7de002b3-e67f-46b9-95d1-e07a1bea7f5a",
|
239 |
"metadata": {},
|
240 |
"outputs": [],
|
|
|
245 |
},
|
246 |
{
|
247 |
"cell_type": "code",
|
248 |
+
"execution_count": 5,
|
249 |
"id": "d3093469-f35f-4008-9da4-340c64a9f85a",
|
250 |
"metadata": {},
|
251 |
"outputs": [],
|
|
|
260 |
},
|
261 |
{
|
262 |
"cell_type": "code",
|
263 |
+
"execution_count": 40,
|
264 |
+
"id": "873463fb-4911-4fe3-8f1f-36fa4c03f8a1",
|
265 |
+
"metadata": {},
|
266 |
+
"outputs": [],
|
267 |
+
"source": [
|
268 |
+
"description_text = \"\"\"\n",
|
269 |
+
"This [model](https://huggingface.co/manifesto-project/manifestoberta-xlm-roberta-56policy-topics-sentence-2023-1-1) was trained on over 8000 German tweets. The label definitions can be found in this [handbook](https://manifesto-project.wzb.eu/coding_schemes/mp_v4) from the Manifesto Project.\n",
|
270 |
+
"\n",
|
271 |
+
"With this app you can classify statements into political topics like this:\n",
|
272 |
+
"\n",
|
273 |
+
"1. Enter some text in the input box.\n",
|
274 |
+
"2. Click 'Submit' or press 'Enter' to get the classification result.\n",
|
275 |
+
"3. If you want to know the label's definition, look it up [here](https://manifesto-project.wzb.eu/coding_schemes/mp_v4).\n",
|
276 |
+
"\"\"\""
|
277 |
+
]
|
278 |
+
},
|
279 |
+
{
|
280 |
+
"cell_type": "code",
|
281 |
+
"execution_count": 41,
|
282 |
"id": "8e2ad81f-5b87-47c1-a60a-fd45616e8fb0",
|
283 |
"metadata": {},
|
284 |
"outputs": [],
|
285 |
"source": [
|
286 |
"# Create a Gradio interface\n",
|
287 |
+
"demo = gr.Interface(\n",
|
288 |
+
" fn=classify_text,\n",
|
289 |
+
" inputs=\"text\",\n",
|
290 |
+
" outputs=\"label\",\n",
|
291 |
+
" title=\"Manifestoberta fine-tuned on Politweets\",\n",
|
292 |
+
" description=description_text\n",
|
293 |
+
")"
|
294 |
]
|
295 |
},
|
296 |
{
|
297 |
"cell_type": "code",
|
298 |
+
"execution_count": 42,
|
299 |
"id": "18d88162-30cc-4a6b-8581-793ed65aef0f",
|
300 |
"metadata": {},
|
301 |
"outputs": [
|
|
|
303 |
"name": "stdout",
|
304 |
"output_type": "stream",
|
305 |
"text": [
|
306 |
+
"Running on local URL: http://127.0.0.1:7873\n",
|
307 |
"\n",
|
308 |
"To create a public link, set `share=True` in `launch()`.\n"
|
309 |
]
|
|
|
311 |
{
|
312 |
"data": {
|
313 |
"text/html": [
|
314 |
+
"<div><iframe src=\"http://127.0.0.1:7873/\" width=\"100%\" height=\"500\" allow=\"autoplay; camera; microphone; clipboard-read; clipboard-write;\" frameborder=\"0\" allowfullscreen></iframe></div>"
|
315 |
],
|
316 |
"text/plain": [
|
317 |
"<IPython.core.display.HTML object>"
|
|
|
324 |
"data": {
|
325 |
"text/plain": []
|
326 |
},
|
327 |
+
"execution_count": 42,
|
328 |
"metadata": {},
|
329 |
"output_type": "execute_result"
|
330 |
+
}
|
331 |
+
],
|
332 |
+
"source": [
|
333 |
+
"# Launch the app\n",
|
334 |
+
"demo.launch()"
|
335 |
+
]
|
336 |
+
},
|
337 |
+
{
|
338 |
+
"cell_type": "markdown",
|
339 |
+
"id": "3123914a-a490-4395-917b-1ef5c1056c57",
|
340 |
+
"metadata": {},
|
341 |
+
"source": [
|
342 |
+
"## More Customization\n",
|
343 |
+
"This is probably the way to go if I want more functionality and control.\n",
|
344 |
+
"But for now I don't really want to get into that stuff."
|
345 |
+
]
|
346 |
+
},
|
347 |
+
{
|
348 |
+
"cell_type": "code",
|
349 |
+
"execution_count": 22,
|
350 |
+
"id": "5f37d50d-281b-42a8-bcc3-26cc27b54507",
|
351 |
+
"metadata": {},
|
352 |
+
"outputs": [],
|
353 |
+
"source": [
|
354 |
+
"with gr.Blocks() as demo:\n",
|
355 |
+
" gr.Interface(\n",
|
356 |
+
" fn=classify_text,\n",
|
357 |
+
" inputs=\"text\",\n",
|
358 |
+
" outputs=\"label\"\n",
|
359 |
+
" )\n",
|
360 |
+
"\n",
|
361 |
+
" # Add explanation at the top using Markdown\n",
|
362 |
+
" gr.Markdown(\"\"\"\n",
|
363 |
+
" ### AutoGluon Text Classification Demo\n",
|
364 |
+
" \n",
|
365 |
+
" This app classifies text using a model trained with AutoGluon. \n",
|
366 |
+
" To use the app:\n",
|
367 |
+
" 1. Enter your text in the input box below.\n",
|
368 |
+
" 2. Click the 'Submit' button to get the classification result.\n",
|
369 |
+
" \n",
|
370 |
+
" For more details, visit [AutoGluon Documentation](https://auto.gluon.ai/stable/index.html).\n",
|
371 |
+
" \"\"\")\n",
|
372 |
+
" \n",
|
373 |
+
" # Add input, output, and button\n",
|
374 |
+
" text_input = gr.Textbox(label=\"Enter your text\")\n",
|
375 |
+
" output = gr.Label(label=\"Classification\")\n",
|
376 |
+
" submit_btn = gr.Button(\"Submit\")\n",
|
377 |
+
"\n",
|
378 |
+
" # Link the button to the function\n",
|
379 |
+
" submit_btn.click(classify_text, inputs=text_input, outputs=output)\n"
|
380 |
+
]
|
381 |
+
},
|
382 |
+
{
|
383 |
+
"cell_type": "code",
|
384 |
+
"execution_count": 23,
|
385 |
+
"id": "8652a1b0-8f65-4983-8bdd-a57117fee5da",
|
386 |
+
"metadata": {},
|
387 |
+
"outputs": [
|
388 |
{
|
389 |
+
"name": "stdout",
|
390 |
"output_type": "stream",
|
391 |
"text": [
|
392 |
+
"Running on local URL: http://127.0.0.1:7866\n",
|
393 |
+
"\n",
|
394 |
+
"To create a public link, set `share=True` in `launch()`.\n"
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
395 |
]
|
396 |
+
},
|
397 |
+
{
|
398 |
+
"data": {
|
399 |
+
"text/html": [
|
400 |
+
"<div><iframe src=\"http://127.0.0.1:7866/\" width=\"100%\" height=\"500\" allow=\"autoplay; camera; microphone; clipboard-read; clipboard-write;\" frameborder=\"0\" allowfullscreen></iframe></div>"
|
401 |
+
],
|
402 |
+
"text/plain": [
|
403 |
+
"<IPython.core.display.HTML object>"
|
404 |
+
]
|
405 |
+
},
|
406 |
+
"metadata": {},
|
407 |
+
"output_type": "display_data"
|
408 |
+
},
|
409 |
+
{
|
410 |
+
"data": {
|
411 |
+
"text/plain": []
|
412 |
+
},
|
413 |
+
"execution_count": 23,
|
414 |
+
"metadata": {},
|
415 |
+
"output_type": "execute_result"
|
416 |
}
|
417 |
],
|
418 |
"source": [
|
|
|
419 |
"demo.launch()"
|
420 |
]
|
421 |
+
},
|
422 |
+
{
|
423 |
+
"cell_type": "code",
|
424 |
+
"execution_count": null,
|
425 |
+
"id": "f245aa88-4746-4aed-85c1-a09bdcbb6710",
|
426 |
+
"metadata": {},
|
427 |
+
"outputs": [],
|
428 |
+
"source": []
|
429 |
}
|
430 |
],
|
431 |
"metadata": {
|
app.ipynb
CHANGED
@@ -194,7 +194,7 @@
|
|
194 |
},
|
195 |
{
|
196 |
"cell_type": "code",
|
197 |
-
"execution_count":
|
198 |
"id": "42242b57-3569-46f2-9966-c737dd6e6f16",
|
199 |
"metadata": {},
|
200 |
"outputs": [],
|
@@ -204,30 +204,29 @@
|
|
204 |
},
|
205 |
{
|
206 |
"cell_type": "code",
|
207 |
-
"execution_count":
|
208 |
"id": "4e41db23-e369-413d-ab25-f85cd21af0c4",
|
209 |
"metadata": {},
|
210 |
-
"outputs": [],
|
211 |
-
"source": [
|
212 |
-
"import gradio as gr"
|
213 |
-
]
|
214 |
-
},
|
215 |
-
{
|
216 |
-
"cell_type": "code",
|
217 |
-
"execution_count": 1,
|
218 |
-
"id": "411ef985-d45e-4b17-b33c-24fde7c00b4f",
|
219 |
-
"metadata": {},
|
220 |
"outputs": [
|
221 |
{
|
222 |
"name": "stderr",
|
223 |
"output_type": "stream",
|
224 |
"text": [
|
225 |
"/Users/macbook/.pyenv/versions/politvenv/lib/python3.10/site-packages/tqdm/auto.py:21: TqdmWarning: IProgress not found. Please update jupyter and ipywidgets. See https://ipywidgets.readthedocs.io/en/stable/user_install.html\n",
|
226 |
-
" from .autonotebook import tqdm as notebook_tqdm\n"
|
227 |
-
"Matplotlib is building the font cache; this may take a moment.\n"
|
228 |
]
|
229 |
}
|
230 |
],
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
231 |
"source": [
|
232 |
"#import gradio as gr\n",
|
233 |
"from autogluon.text import TextPredictor"
|
@@ -235,7 +234,7 @@
|
|
235 |
},
|
236 |
{
|
237 |
"cell_type": "code",
|
238 |
-
"execution_count":
|
239 |
"id": "7de002b3-e67f-46b9-95d1-e07a1bea7f5a",
|
240 |
"metadata": {},
|
241 |
"outputs": [],
|
@@ -246,7 +245,7 @@
|
|
246 |
},
|
247 |
{
|
248 |
"cell_type": "code",
|
249 |
-
"execution_count":
|
250 |
"id": "d3093469-f35f-4008-9da4-340c64a9f85a",
|
251 |
"metadata": {},
|
252 |
"outputs": [],
|
@@ -261,18 +260,42 @@
|
|
261 |
},
|
262 |
{
|
263 |
"cell_type": "code",
|
264 |
-
"execution_count":
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
265 |
"id": "8e2ad81f-5b87-47c1-a60a-fd45616e8fb0",
|
266 |
"metadata": {},
|
267 |
"outputs": [],
|
268 |
"source": [
|
269 |
"# Create a Gradio interface\n",
|
270 |
-
"demo = gr.Interface(
|
|
|
|
|
|
|
|
|
|
|
|
|
271 |
]
|
272 |
},
|
273 |
{
|
274 |
"cell_type": "code",
|
275 |
-
"execution_count":
|
276 |
"id": "18d88162-30cc-4a6b-8581-793ed65aef0f",
|
277 |
"metadata": {},
|
278 |
"outputs": [
|
@@ -280,7 +303,7 @@
|
|
280 |
"name": "stdout",
|
281 |
"output_type": "stream",
|
282 |
"text": [
|
283 |
-
"Running on local URL: http://127.0.0.1:
|
284 |
"\n",
|
285 |
"To create a public link, set `share=True` in `launch()`.\n"
|
286 |
]
|
@@ -288,7 +311,7 @@
|
|
288 |
{
|
289 |
"data": {
|
290 |
"text/html": [
|
291 |
-
"<div><iframe src=\"http://127.0.0.1:
|
292 |
],
|
293 |
"text/plain": [
|
294 |
"<IPython.core.display.HTML object>"
|
@@ -301,39 +324,108 @@
|
|
301 |
"data": {
|
302 |
"text/plain": []
|
303 |
},
|
304 |
-
"execution_count":
|
305 |
"metadata": {},
|
306 |
"output_type": "execute_result"
|
307 |
-
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
308 |
{
|
309 |
-
"name": "
|
310 |
"output_type": "stream",
|
311 |
"text": [
|
312 |
-
"
|
313 |
-
"
|
314 |
-
"
|
315 |
-
"Global seed set to 123\n",
|
316 |
-
"/Users/macbook/.pyenv/versions/politvenv/lib/python3.10/site-packages/autogluon/multimodal/utils/environment.py:50: UserWarning: Using the detected GPU number 0, smaller than the GPU number 1 in the config.\n",
|
317 |
-
" warnings.warn(\n",
|
318 |
-
"Global seed set to 123\n",
|
319 |
-
"/Users/macbook/.pyenv/versions/politvenv/lib/python3.10/site-packages/autogluon/multimodal/utils/environment.py:50: UserWarning: Using the detected GPU number 0, smaller than the GPU number 1 in the config.\n",
|
320 |
-
" warnings.warn(\n",
|
321 |
-
"Global seed set to 123\n",
|
322 |
-
"/Users/macbook/.pyenv/versions/politvenv/lib/python3.10/site-packages/autogluon/multimodal/utils/environment.py:50: UserWarning: Using the detected GPU number 0, smaller than the GPU number 1 in the config.\n",
|
323 |
-
" warnings.warn(\n",
|
324 |
-
"Global seed set to 123\n",
|
325 |
-
"/Users/macbook/.pyenv/versions/politvenv/lib/python3.10/site-packages/autogluon/multimodal/utils/environment.py:50: UserWarning: Using the detected GPU number 0, smaller than the GPU number 1 in the config.\n",
|
326 |
-
" warnings.warn(\n",
|
327 |
-
"Global seed set to 123\n",
|
328 |
-
"/Users/macbook/.pyenv/versions/politvenv/lib/python3.10/site-packages/autogluon/multimodal/utils/environment.py:50: UserWarning: Using the detected GPU number 0, smaller than the GPU number 1 in the config.\n",
|
329 |
-
" warnings.warn(\n"
|
330 |
]
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
331 |
}
|
332 |
],
|
333 |
"source": [
|
334 |
-
"# Launch the app\n",
|
335 |
"demo.launch()"
|
336 |
]
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
337 |
}
|
338 |
],
|
339 |
"metadata": {
|
|
|
194 |
},
|
195 |
{
|
196 |
"cell_type": "code",
|
197 |
+
"execution_count": 1,
|
198 |
"id": "42242b57-3569-46f2-9966-c737dd6e6f16",
|
199 |
"metadata": {},
|
200 |
"outputs": [],
|
|
|
204 |
},
|
205 |
{
|
206 |
"cell_type": "code",
|
207 |
+
"execution_count": 2,
|
208 |
"id": "4e41db23-e369-413d-ab25-f85cd21af0c4",
|
209 |
"metadata": {},
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
210 |
"outputs": [
|
211 |
{
|
212 |
"name": "stderr",
|
213 |
"output_type": "stream",
|
214 |
"text": [
|
215 |
"/Users/macbook/.pyenv/versions/politvenv/lib/python3.10/site-packages/tqdm/auto.py:21: TqdmWarning: IProgress not found. Please update jupyter and ipywidgets. See https://ipywidgets.readthedocs.io/en/stable/user_install.html\n",
|
216 |
+
" from .autonotebook import tqdm as notebook_tqdm\n"
|
|
|
217 |
]
|
218 |
}
|
219 |
],
|
220 |
+
"source": [
|
221 |
+
"import gradio as gr"
|
222 |
+
]
|
223 |
+
},
|
224 |
+
{
|
225 |
+
"cell_type": "code",
|
226 |
+
"execution_count": 3,
|
227 |
+
"id": "411ef985-d45e-4b17-b33c-24fde7c00b4f",
|
228 |
+
"metadata": {},
|
229 |
+
"outputs": [],
|
230 |
"source": [
|
231 |
"#import gradio as gr\n",
|
232 |
"from autogluon.text import TextPredictor"
|
|
|
234 |
},
|
235 |
{
|
236 |
"cell_type": "code",
|
237 |
+
"execution_count": 4,
|
238 |
"id": "7de002b3-e67f-46b9-95d1-e07a1bea7f5a",
|
239 |
"metadata": {},
|
240 |
"outputs": [],
|
|
|
245 |
},
|
246 |
{
|
247 |
"cell_type": "code",
|
248 |
+
"execution_count": 5,
|
249 |
"id": "d3093469-f35f-4008-9da4-340c64a9f85a",
|
250 |
"metadata": {},
|
251 |
"outputs": [],
|
|
|
260 |
},
|
261 |
{
|
262 |
"cell_type": "code",
|
263 |
+
"execution_count": 40,
|
264 |
+
"id": "873463fb-4911-4fe3-8f1f-36fa4c03f8a1",
|
265 |
+
"metadata": {},
|
266 |
+
"outputs": [],
|
267 |
+
"source": [
|
268 |
+
"description_text = \"\"\"\n",
|
269 |
+
"This [model](https://huggingface.co/manifesto-project/manifestoberta-xlm-roberta-56policy-topics-sentence-2023-1-1) was trained on over 8000 German tweets. The label definitions can be found in this [handbook](https://manifesto-project.wzb.eu/coding_schemes/mp_v4) from the Manifesto Project.\n",
|
270 |
+
"\n",
|
271 |
+
"With this app you can classify statements into political topics like this:\n",
|
272 |
+
"\n",
|
273 |
+
"1. Enter some text in the input box.\n",
|
274 |
+
"2. Click 'Submit' or press 'Enter' to get the classification result.\n",
|
275 |
+
"3. If you want to know the label's definition, look it up [here](https://manifesto-project.wzb.eu/coding_schemes/mp_v4).\n",
|
276 |
+
"\"\"\""
|
277 |
+
]
|
278 |
+
},
|
279 |
+
{
|
280 |
+
"cell_type": "code",
|
281 |
+
"execution_count": 41,
|
282 |
"id": "8e2ad81f-5b87-47c1-a60a-fd45616e8fb0",
|
283 |
"metadata": {},
|
284 |
"outputs": [],
|
285 |
"source": [
|
286 |
"# Create a Gradio interface\n",
|
287 |
+
"demo = gr.Interface(\n",
|
288 |
+
" fn=classify_text,\n",
|
289 |
+
" inputs=\"text\",\n",
|
290 |
+
" outputs=\"label\",\n",
|
291 |
+
" title=\"Manifestoberta fine-tuned on Politweets\",\n",
|
292 |
+
" description=description_text\n",
|
293 |
+
")"
|
294 |
]
|
295 |
},
|
296 |
{
|
297 |
"cell_type": "code",
|
298 |
+
"execution_count": 42,
|
299 |
"id": "18d88162-30cc-4a6b-8581-793ed65aef0f",
|
300 |
"metadata": {},
|
301 |
"outputs": [
|
|
|
303 |
"name": "stdout",
|
304 |
"output_type": "stream",
|
305 |
"text": [
|
306 |
+
"Running on local URL: http://127.0.0.1:7873\n",
|
307 |
"\n",
|
308 |
"To create a public link, set `share=True` in `launch()`.\n"
|
309 |
]
|
|
|
311 |
{
|
312 |
"data": {
|
313 |
"text/html": [
|
314 |
+
"<div><iframe src=\"http://127.0.0.1:7873/\" width=\"100%\" height=\"500\" allow=\"autoplay; camera; microphone; clipboard-read; clipboard-write;\" frameborder=\"0\" allowfullscreen></iframe></div>"
|
315 |
],
|
316 |
"text/plain": [
|
317 |
"<IPython.core.display.HTML object>"
|
|
|
324 |
"data": {
|
325 |
"text/plain": []
|
326 |
},
|
327 |
+
"execution_count": 42,
|
328 |
"metadata": {},
|
329 |
"output_type": "execute_result"
|
330 |
+
}
|
331 |
+
],
|
332 |
+
"source": [
|
333 |
+
"# Launch the app\n",
|
334 |
+
"demo.launch()"
|
335 |
+
]
|
336 |
+
},
|
337 |
+
{
|
338 |
+
"cell_type": "markdown",
|
339 |
+
"id": "3123914a-a490-4395-917b-1ef5c1056c57",
|
340 |
+
"metadata": {},
|
341 |
+
"source": [
|
342 |
+
"## More Customization\n",
|
343 |
+
"This is probably the way to go if I want more functionality and control.\n",
|
344 |
+
"But for now I don't really want to get into that stuff."
|
345 |
+
]
|
346 |
+
},
|
347 |
+
{
|
348 |
+
"cell_type": "code",
|
349 |
+
"execution_count": 22,
|
350 |
+
"id": "5f37d50d-281b-42a8-bcc3-26cc27b54507",
|
351 |
+
"metadata": {},
|
352 |
+
"outputs": [],
|
353 |
+
"source": [
|
354 |
+
"with gr.Blocks() as demo:\n",
|
355 |
+
" gr.Interface(\n",
|
356 |
+
" fn=classify_text,\n",
|
357 |
+
" inputs=\"text\",\n",
|
358 |
+
" outputs=\"label\"\n",
|
359 |
+
" )\n",
|
360 |
+
"\n",
|
361 |
+
" # Add explanation at the top using Markdown\n",
|
362 |
+
" gr.Markdown(\"\"\"\n",
|
363 |
+
" ### AutoGluon Text Classification Demo\n",
|
364 |
+
" \n",
|
365 |
+
" This app classifies text using a model trained with AutoGluon. \n",
|
366 |
+
" To use the app:\n",
|
367 |
+
" 1. Enter your text in the input box below.\n",
|
368 |
+
" 2. Click the 'Submit' button to get the classification result.\n",
|
369 |
+
" \n",
|
370 |
+
" For more details, visit [AutoGluon Documentation](https://auto.gluon.ai/stable/index.html).\n",
|
371 |
+
" \"\"\")\n",
|
372 |
+
" \n",
|
373 |
+
" # Add input, output, and button\n",
|
374 |
+
" text_input = gr.Textbox(label=\"Enter your text\")\n",
|
375 |
+
" output = gr.Label(label=\"Classification\")\n",
|
376 |
+
" submit_btn = gr.Button(\"Submit\")\n",
|
377 |
+
"\n",
|
378 |
+
" # Link the button to the function\n",
|
379 |
+
" submit_btn.click(classify_text, inputs=text_input, outputs=output)\n"
|
380 |
+
]
|
381 |
+
},
|
382 |
+
{
|
383 |
+
"cell_type": "code",
|
384 |
+
"execution_count": 23,
|
385 |
+
"id": "8652a1b0-8f65-4983-8bdd-a57117fee5da",
|
386 |
+
"metadata": {},
|
387 |
+
"outputs": [
|
388 |
{
|
389 |
+
"name": "stdout",
|
390 |
"output_type": "stream",
|
391 |
"text": [
|
392 |
+
"Running on local URL: http://127.0.0.1:7866\n",
|
393 |
+
"\n",
|
394 |
+
"To create a public link, set `share=True` in `launch()`.\n"
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
395 |
]
|
396 |
+
},
|
397 |
+
{
|
398 |
+
"data": {
|
399 |
+
"text/html": [
|
400 |
+
"<div><iframe src=\"http://127.0.0.1:7866/\" width=\"100%\" height=\"500\" allow=\"autoplay; camera; microphone; clipboard-read; clipboard-write;\" frameborder=\"0\" allowfullscreen></iframe></div>"
|
401 |
+
],
|
402 |
+
"text/plain": [
|
403 |
+
"<IPython.core.display.HTML object>"
|
404 |
+
]
|
405 |
+
},
|
406 |
+
"metadata": {},
|
407 |
+
"output_type": "display_data"
|
408 |
+
},
|
409 |
+
{
|
410 |
+
"data": {
|
411 |
+
"text/plain": []
|
412 |
+
},
|
413 |
+
"execution_count": 23,
|
414 |
+
"metadata": {},
|
415 |
+
"output_type": "execute_result"
|
416 |
}
|
417 |
],
|
418 |
"source": [
|
|
|
419 |
"demo.launch()"
|
420 |
]
|
421 |
+
},
|
422 |
+
{
|
423 |
+
"cell_type": "code",
|
424 |
+
"execution_count": null,
|
425 |
+
"id": "f245aa88-4746-4aed-85c1-a09bdcbb6710",
|
426 |
+
"metadata": {},
|
427 |
+
"outputs": [],
|
428 |
+
"source": []
|
429 |
}
|
430 |
],
|
431 |
"metadata": {
|
app.py
CHANGED
@@ -10,9 +10,25 @@ def classify_text(text):
|
|
10 |
single_row = pd.DataFrame([text], columns=["text"])
|
11 |
prediction = predictor.predict(single_row)
|
12 |
return prediction[0]
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
13 |
|
14 |
# Create a Gradio interface
|
15 |
-
demo = gr.Interface(
|
|
|
|
|
|
|
|
|
|
|
|
|
16 |
|
17 |
# Launch the app
|
18 |
demo.launch()
|
|
|
10 |
single_row = pd.DataFrame([text], columns=["text"])
|
11 |
prediction = predictor.predict(single_row)
|
12 |
return prediction[0]
|
13 |
+
|
14 |
+
description_text = """
|
15 |
+
This [model](https://huggingface.co/manifesto-project/manifestoberta-xlm-roberta-56policy-topics-sentence-2023-1-1) was trained on over 8000 German tweets. The label definitions can be found in this [handbook](https://manifesto-project.wzb.eu/coding_schemes/mp_v4) from the Manifesto Project.
|
16 |
+
|
17 |
+
With this app you can classify statements into political topics like this:
|
18 |
+
|
19 |
+
1. Enter some text in the input box.
|
20 |
+
2. Click 'Submit' or press 'Enter' to get the classification result.
|
21 |
+
3. If you want to know the label's definition, look it up [here](https://manifesto-project.wzb.eu/coding_schemes/mp_v4).
|
22 |
+
"""
|
23 |
|
24 |
# Create a Gradio interface
|
25 |
+
demo = gr.Interface(
|
26 |
+
fn=classify_text,
|
27 |
+
inputs="text",
|
28 |
+
outputs="label",
|
29 |
+
title="Manifestoberta fine-tuned on Politweets",
|
30 |
+
description=description_text
|
31 |
+
)
|
32 |
|
33 |
# Launch the app
|
34 |
demo.launch()
|