Spaces:
Sleeping
Sleeping
File size: 46,388 Bytes
4b9fc54 506bf70 4b9fc54 506bf70 4b9fc54 506bf70 4b9fc54 506bf70 4b9fc54 506bf70 4b9fc54 |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 614 615 616 617 618 619 620 621 622 623 624 625 626 627 628 629 630 631 632 633 634 635 636 637 638 639 640 641 642 643 644 645 646 647 648 649 650 651 652 653 654 655 656 657 658 659 660 661 662 663 664 665 666 667 668 669 670 671 672 673 674 675 676 677 678 679 680 681 682 683 684 685 686 687 688 689 690 691 692 693 694 695 696 697 698 699 700 701 702 703 704 705 706 707 708 709 710 711 712 713 714 715 716 717 718 719 720 721 722 723 724 725 726 727 728 729 730 731 732 733 734 735 736 737 738 739 740 741 742 743 744 745 |
{
"cells": [
{
"cell_type": "code",
"execution_count": 2,
"id": "bf596b85",
"metadata": {},
"outputs": [],
"source": [
"!pip install -Uqq fastai"
]
},
{
"cell_type": "code",
"execution_count": 3,
"id": "f6529ac6",
"metadata": {},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"/Users/devudilip/projects/AI/fastai_pet_classifier\r\n"
]
}
],
"source": [
"!pwd"
]
},
{
"cell_type": "code",
"execution_count": 35,
"id": "0473c217",
"metadata": {},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"fastai: 2.8.0\n",
"fastcore: 1.8.0\n",
"torch: 2.4.1\n"
]
}
],
"source": [
"import fastai\n",
"import fastcore\n",
"import torch\n",
"\n",
"print(f\"fastai: {fastai.__version__}\")\n",
"print(f\"fastcore: {fastcore.__version__}\")\n",
"print(f\"torch: {torch.__version__}\")"
]
},
{
"cell_type": "code",
"execution_count": 13,
"id": "15b4cdfd",
"metadata": {},
"outputs": [],
"source": [
"from fastai.vision.all import *\n",
"import dill"
]
},
{
"cell_type": "code",
"execution_count": 5,
"id": "399533a7",
"metadata": {},
"outputs": [],
"source": [
"path = untar_data(URLs.PETS)/'images'"
]
},
{
"cell_type": "code",
"execution_count": 6,
"id": "51e0bbe2",
"metadata": {},
"outputs": [],
"source": [
"def is_cat(x): return x[0].isupper() "
]
},
{
"cell_type": "code",
"execution_count": 7,
"id": "915cbf12",
"metadata": {},
"outputs": [],
"source": [
"dls = ImageDataLoaders.from_name_func('.',\n",
" get_image_files(path), valid_pct=0.2, seed=42,\n",
" label_func=is_cat,\n",
" item_tfms=Resize(192))"
]
},
{
"cell_type": "code",
"execution_count": 8,
"id": "9bae55cc",
"metadata": {},
"outputs": [
{
"name": "stderr",
"output_type": "stream",
"text": [
"Downloading: \"https://download.pytorch.org/models/resnet18-f37072fd.pth\" to /Users/devudilip/.cache/torch/hub/checkpoints/resnet18-f37072fd.pth\n",
"100%|████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████| 44.7M/44.7M [00:09<00:00, 4.89MB/s]\n"
]
},
{
"data": {
"text/html": [
"\n",
"<style>\n",
" /* Turns off some styling */\n",
" progress {\n",
" /* gets rid of default border in Firefox and Opera. */\n",
" border: none;\n",
" /* Needs to be in here for Safari polyfill so background images work as expected. */\n",
" background-size: auto;\n",
" }\n",
" progress:not([value]), progress:not([value])::-webkit-progress-bar {\n",
" background: repeating-linear-gradient(45deg, #7e7e7e, #7e7e7e 10px, #5c5c5c 10px, #5c5c5c 20px);\n",
" }\n",
" .progress-bar-interrupted, .progress-bar-interrupted::-webkit-progress-bar {\n",
" background: #F44336;\n",
" }\n",
"</style>\n"
],
"text/plain": [
"<IPython.core.display.HTML object>"
]
},
"metadata": {},
"output_type": "display_data"
},
{
"data": {
"text/html": [
"<table border=\"1\" class=\"dataframe\">\n",
" <thead>\n",
" <tr style=\"text-align: left;\">\n",
" <th>epoch</th>\n",
" <th>train_loss</th>\n",
" <th>valid_loss</th>\n",
" <th>error_rate</th>\n",
" <th>time</th>\n",
" </tr>\n",
" </thead>\n",
" <tbody>\n",
" <tr>\n",
" <td>0</td>\n",
" <td>0.197639</td>\n",
" <td>0.045730</td>\n",
" <td>0.015562</td>\n",
" <td>01:37</td>\n",
" </tr>\n",
" </tbody>\n",
"</table>"
],
"text/plain": [
"<IPython.core.display.HTML object>"
]
},
"metadata": {},
"output_type": "display_data"
},
{
"data": {
"text/html": [
"\n",
"<style>\n",
" /* Turns off some styling */\n",
" progress {\n",
" /* gets rid of default border in Firefox and Opera. */\n",
" border: none;\n",
" /* Needs to be in here for Safari polyfill so background images work as expected. */\n",
" background-size: auto;\n",
" }\n",
" progress:not([value]), progress:not([value])::-webkit-progress-bar {\n",
" background: repeating-linear-gradient(45deg, #7e7e7e, #7e7e7e 10px, #5c5c5c 10px, #5c5c5c 20px);\n",
" }\n",
" .progress-bar-interrupted, .progress-bar-interrupted::-webkit-progress-bar {\n",
" background: #F44336;\n",
" }\n",
"</style>\n"
],
"text/plain": [
"<IPython.core.display.HTML object>"
]
},
"metadata": {},
"output_type": "display_data"
},
{
"data": {
"text/html": [
"<table border=\"1\" class=\"dataframe\">\n",
" <thead>\n",
" <tr style=\"text-align: left;\">\n",
" <th>epoch</th>\n",
" <th>train_loss</th>\n",
" <th>valid_loss</th>\n",
" <th>error_rate</th>\n",
" <th>time</th>\n",
" </tr>\n",
" </thead>\n",
" <tbody>\n",
" <tr>\n",
" <td>0</td>\n",
" <td>0.078331</td>\n",
" <td>0.054597</td>\n",
" <td>0.018268</td>\n",
" <td>02:22</td>\n",
" </tr>\n",
" <tr>\n",
" <td>1</td>\n",
" <td>0.049279</td>\n",
" <td>0.038220</td>\n",
" <td>0.010149</td>\n",
" <td>02:40</td>\n",
" </tr>\n",
" <tr>\n",
" <td>2</td>\n",
" <td>0.023927</td>\n",
" <td>0.026168</td>\n",
" <td>0.008796</td>\n",
" <td>02:56</td>\n",
" </tr>\n",
" </tbody>\n",
"</table>"
],
"text/plain": [
"<IPython.core.display.HTML object>"
]
},
"metadata": {},
"output_type": "display_data"
}
],
"source": [
"learn = vision_learner(dls, resnet18, metrics=error_rate)\n",
"learn.fine_tune(3)"
]
},
{
"cell_type": "code",
"execution_count": 37,
"id": "8034b898",
"metadata": {},
"outputs": [
{
"data": {
"text/html": [
"\n",
"<style>\n",
" /* Turns off some styling */\n",
" progress {\n",
" /* gets rid of default border in Firefox and Opera. */\n",
" border: none;\n",
" /* Needs to be in here for Safari polyfill so background images work as expected. */\n",
" background-size: auto;\n",
" }\n",
" progress:not([value]), progress:not([value])::-webkit-progress-bar {\n",
" background: repeating-linear-gradient(45deg, #7e7e7e, #7e7e7e 10px, #5c5c5c 10px, #5c5c5c 20px);\n",
" }\n",
" .progress-bar-interrupted, .progress-bar-interrupted::-webkit-progress-bar {\n",
" background: #F44336;\n",
" }\n",
"</style>\n"
],
"text/plain": [
"<IPython.core.display.HTML object>"
]
},
"metadata": {},
"output_type": "display_data"
},
{
"data": {
"text/html": [],
"text/plain": [
"<IPython.core.display.HTML object>"
]
},
"metadata": {},
"output_type": "display_data"
},
{
"data": {
"text/plain": [
"{'Dog': 1.0, 'Cat': 6.59496190991149e-09}"
]
},
"execution_count": 37,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"pred, idx, probs = learn.predict('i1.jpg')\n",
"dict(zip(categories, map(float, probs)))"
]
},
{
"cell_type": "code",
"execution_count": 38,
"id": "9119ee21",
"metadata": {},
"outputs": [
{
"ename": "AttributeError",
"evalue": "Can't get local object 'Transform.__init__.<locals>.wrapped_enc'",
"output_type": "error",
"traceback": [
"\u001b[31m---------------------------------------------------------------------------\u001b[39m",
"\u001b[31mAttributeError\u001b[39m Traceback (most recent call last)",
"\u001b[36mCell\u001b[39m\u001b[36m \u001b[39m\u001b[32mIn[38]\u001b[39m\u001b[32m, line 1\u001b[39m\n\u001b[32m----> \u001b[39m\u001b[32m1\u001b[39m \u001b[43mlearn\u001b[49m\u001b[43m.\u001b[49m\u001b[43mexport\u001b[49m\u001b[43m(\u001b[49m\u001b[33;43m'\u001b[39;49m\u001b[33;43mmodel.pkl\u001b[39;49m\u001b[33;43m'\u001b[39;49m\u001b[43m)\u001b[49m\n",
"\u001b[36mFile \u001b[39m\u001b[32m~/miniforge3/lib/python3.12/site-packages/fastai/learner.py:444\u001b[39m, in \u001b[36mexport\u001b[39m\u001b[34m(self, fname, pickle_module, pickle_protocol)\u001b[39m\n\u001b[32m 441\u001b[39m \u001b[38;5;28;01mwith\u001b[39;00m warnings.catch_warnings():\n\u001b[32m 442\u001b[39m \u001b[38;5;66;03m#To avoid the warning that come from PyTorch about model not being checked\u001b[39;00m\n\u001b[32m 443\u001b[39m warnings.simplefilter(\u001b[33m\"\u001b[39m\u001b[33mignore\u001b[39m\u001b[33m\"\u001b[39m)\n\u001b[32m--> \u001b[39m\u001b[32m444\u001b[39m \u001b[43mtorch\u001b[49m\u001b[43m.\u001b[49m\u001b[43msave\u001b[49m\u001b[43m(\u001b[49m\u001b[38;5;28;43mself\u001b[39;49m\u001b[43m,\u001b[49m\u001b[43m \u001b[49m\u001b[38;5;28;43mself\u001b[39;49m\u001b[43m.\u001b[49m\u001b[43mpath\u001b[49m\u001b[43m/\u001b[49m\u001b[43mfname\u001b[49m\u001b[43m,\u001b[49m\u001b[43m \u001b[49m\u001b[43mpickle_module\u001b[49m\u001b[43m=\u001b[49m\u001b[43mpickle_module\u001b[49m\u001b[43m,\u001b[49m\u001b[43m \u001b[49m\u001b[43mpickle_protocol\u001b[49m\u001b[43m=\u001b[49m\u001b[43mpickle_protocol\u001b[49m\u001b[43m)\u001b[49m\n\u001b[32m 445\u001b[39m \u001b[38;5;28mself\u001b[39m.create_opt()\n\u001b[32m 446\u001b[39m \u001b[38;5;28;01mif\u001b[39;00m state \u001b[38;5;129;01mis\u001b[39;00m \u001b[38;5;129;01mnot\u001b[39;00m \u001b[38;5;28;01mNone\u001b[39;00m: \u001b[38;5;28mself\u001b[39m.opt.load_state_dict(state)\n",
"\u001b[36mFile \u001b[39m\u001b[32m~/miniforge3/lib/python3.12/site-packages/torch/serialization.py:652\u001b[39m, in \u001b[36msave\u001b[39m\u001b[34m(obj, f, pickle_module, pickle_protocol, _use_new_zipfile_serialization, _disable_byteorder_record)\u001b[39m\n\u001b[32m 650\u001b[39m \u001b[38;5;28;01mif\u001b[39;00m _use_new_zipfile_serialization:\n\u001b[32m 651\u001b[39m \u001b[38;5;28;01mwith\u001b[39;00m _open_zipfile_writer(f) \u001b[38;5;28;01mas\u001b[39;00m opened_zipfile:\n\u001b[32m--> \u001b[39m\u001b[32m652\u001b[39m \u001b[43m_save\u001b[49m\u001b[43m(\u001b[49m\u001b[43mobj\u001b[49m\u001b[43m,\u001b[49m\u001b[43m \u001b[49m\u001b[43mopened_zipfile\u001b[49m\u001b[43m,\u001b[49m\u001b[43m \u001b[49m\u001b[43mpickle_module\u001b[49m\u001b[43m,\u001b[49m\u001b[43m \u001b[49m\u001b[43mpickle_protocol\u001b[49m\u001b[43m,\u001b[49m\u001b[43m \u001b[49m\u001b[43m_disable_byteorder_record\u001b[49m\u001b[43m)\u001b[49m\n\u001b[32m 653\u001b[39m \u001b[38;5;28;01mreturn\u001b[39;00m\n\u001b[32m 654\u001b[39m \u001b[38;5;28;01melse\u001b[39;00m:\n",
"\u001b[36mFile \u001b[39m\u001b[32m~/miniforge3/lib/python3.12/site-packages/torch/serialization.py:864\u001b[39m, in \u001b[36m_save\u001b[39m\u001b[34m(obj, zip_file, pickle_module, pickle_protocol, _disable_byteorder_record)\u001b[39m\n\u001b[32m 862\u001b[39m pickler = pickle_module.Pickler(data_buf, protocol=pickle_protocol)\n\u001b[32m 863\u001b[39m pickler.persistent_id = persistent_id\n\u001b[32m--> \u001b[39m\u001b[32m864\u001b[39m \u001b[43mpickler\u001b[49m\u001b[43m.\u001b[49m\u001b[43mdump\u001b[49m\u001b[43m(\u001b[49m\u001b[43mobj\u001b[49m\u001b[43m)\u001b[49m\n\u001b[32m 865\u001b[39m data_value = data_buf.getvalue()\n\u001b[32m 866\u001b[39m zip_file.write_record(\u001b[33m'\u001b[39m\u001b[33mdata.pkl\u001b[39m\u001b[33m'\u001b[39m, data_value, \u001b[38;5;28mlen\u001b[39m(data_value))\n",
"\u001b[31mAttributeError\u001b[39m: Can't get local object 'Transform.__init__.<locals>.wrapped_enc'"
]
}
],
"source": [
"learn.export('model.pkl')"
]
},
{
"cell_type": "code",
"execution_count": 26,
"id": "25a3e6c4",
"metadata": {},
"outputs": [],
"source": [
"!pip install -q gradio\n",
"import gradio as gr"
]
},
{
"cell_type": "code",
"execution_count": 27,
"id": "03631813",
"metadata": {},
"outputs": [
{
"ename": "ImportError",
"evalue": "cannot import name 'http_server' from 'gradio' (/Users/devudilip/miniforge3/lib/python3.12/site-packages/gradio/__init__.py)",
"output_type": "error",
"traceback": [
"\u001b[31m---------------------------------------------------------------------------\u001b[39m",
"\u001b[31mImportError\u001b[39m Traceback (most recent call last)",
"\u001b[36mCell\u001b[39m\u001b[36m \u001b[39m\u001b[32mIn[27]\u001b[39m\u001b[32m, line 13\u001b[39m\n\u001b[32m 10\u001b[39m examples = [\u001b[33m'\u001b[39m\u001b[33msiamese.png\u001b[39m\u001b[33m'\u001b[39m]\n\u001b[32m 12\u001b[39m intf = gr.Interface(fn=classify_image, inputs=image, outputs=label, examples=examples)\n\u001b[32m---> \u001b[39m\u001b[32m13\u001b[39m \u001b[43mintf\u001b[49m\u001b[43m.\u001b[49m\u001b[43mlaunch\u001b[49m\u001b[43m(\u001b[49m\u001b[43m)\u001b[49m\n",
"\u001b[36mFile \u001b[39m\u001b[32m~/miniforge3/lib/python3.12/site-packages/gradio/blocks.py:2597\u001b[39m, in \u001b[36mlaunch\u001b[39m\u001b[34m(self, inline, inbrowser, share, debug, max_threads, auth, auth_message, prevent_thread_lock, show_error, server_name, server_port, height, width, favicon_path, ssl_keyfile, ssl_certfile, ssl_keyfile_password, ssl_verify, quiet, show_api, allowed_paths, blocked_paths, root_path, app_kwargs, state_session_capacity, share_server_address, share_server_protocol, share_server_tls_certificate, auth_dependency, max_file_size, enable_monitoring, strict_cors, node_server_name, node_port, ssr_mode, pwa, _frontend)\u001b[39m\n\u001b[32m 0\u001b[39m <Error retrieving source code with stack_data see ipython/ipython#13598>\n",
"\u001b[31mImportError\u001b[39m: cannot import name 'http_server' from 'gradio' (/Users/devudilip/miniforge3/lib/python3.12/site-packages/gradio/__init__.py)"
]
}
],
"source": [
"categories = ('Dog', 'Cat')\n",
"\n",
"def classify_image(img):\n",
" pred, idx, probs = learn.predict(img)\n",
" return dict(zip(categories, map(float, probs)))\n",
"\n",
"image = gr.Image()\n",
"label = gr.Label()\n",
"\n",
"examples = ['siamese.png']\n",
"\n",
"intf = gr.Interface(fn=classify_image, inputs=image, outputs=label, examples=examples)\n",
"intf.launch()"
]
},
{
"cell_type": "code",
"execution_count": 30,
"id": "47d99904",
"metadata": {},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"Requirement already satisfied: gradio in /Users/devudilip/miniforge3/lib/python3.12/site-packages (3.0)\n",
"Collecting gradio\n",
" Using cached gradio-5.22.0-py3-none-any.whl.metadata (16 kB)\n",
"Requirement already satisfied: aiofiles<24.0,>=22.0 in /Users/devudilip/miniforge3/lib/python3.12/site-packages (from gradio) (23.2.1)\n",
"Requirement already satisfied: anyio<5.0,>=3.0 in /Users/devudilip/miniforge3/lib/python3.12/site-packages (from gradio) (4.9.0)\n",
"Requirement already satisfied: fastapi<1.0,>=0.115.2 in /Users/devudilip/miniforge3/lib/python3.12/site-packages (from gradio) (0.115.11)\n",
"Requirement already satisfied: ffmpy in /Users/devudilip/miniforge3/lib/python3.12/site-packages (from gradio) (0.5.0)\n",
"Collecting gradio-client==1.8.0 (from gradio)\n",
" Using cached gradio_client-1.8.0-py3-none-any.whl.metadata (7.1 kB)\n",
"Requirement already satisfied: groovy~=0.1 in /Users/devudilip/miniforge3/lib/python3.12/site-packages (from gradio) (0.1.2)\n",
"Requirement already satisfied: httpx>=0.24.1 in /Users/devudilip/miniforge3/lib/python3.12/site-packages (from gradio) (0.28.1)\n",
"Requirement already satisfied: huggingface-hub>=0.28.1 in /Users/devudilip/miniforge3/lib/python3.12/site-packages (from gradio) (0.29.3)\n",
"Requirement already satisfied: jinja2<4.0 in /Users/devudilip/miniforge3/lib/python3.12/site-packages (from gradio) (3.1.6)\n",
"Requirement already satisfied: markupsafe<4.0,>=2.0 in /Users/devudilip/miniforge3/lib/python3.12/site-packages (from gradio) (2.1.5)\n",
"Requirement already satisfied: numpy<3.0,>=1.0 in /Users/devudilip/miniforge3/lib/python3.12/site-packages (from gradio) (1.26.4)\n",
"Requirement already satisfied: orjson~=3.0 in /Users/devudilip/miniforge3/lib/python3.12/site-packages (from gradio) (3.10.15)\n",
"Requirement already satisfied: packaging in /Users/devudilip/miniforge3/lib/python3.12/site-packages (from gradio) (24.2)\n",
"Requirement already satisfied: pandas<3.0,>=1.0 in /Users/devudilip/miniforge3/lib/python3.12/site-packages (from gradio) (2.2.3)\n",
"Requirement already satisfied: pillow<12.0,>=8.0 in /Users/devudilip/miniforge3/lib/python3.12/site-packages (from gradio) (10.4.0)\n",
"Requirement already satisfied: pydantic>=2.0 in /Users/devudilip/miniforge3/lib/python3.12/site-packages (from gradio) (2.10.6)\n",
"Requirement already satisfied: pydub in /Users/devudilip/miniforge3/lib/python3.12/site-packages (from gradio) (0.25.1)\n",
"Requirement already satisfied: python-multipart>=0.0.18 in /Users/devudilip/miniforge3/lib/python3.12/site-packages (from gradio) (0.0.20)\n",
"Requirement already satisfied: pyyaml<7.0,>=5.0 in /Users/devudilip/miniforge3/lib/python3.12/site-packages (from gradio) (6.0.2)\n",
"Requirement already satisfied: ruff>=0.9.3 in /Users/devudilip/miniforge3/lib/python3.12/site-packages (from gradio) (0.11.2)\n",
"Requirement already satisfied: safehttpx<0.2.0,>=0.1.6 in /Users/devudilip/miniforge3/lib/python3.12/site-packages (from gradio) (0.1.6)\n",
"Requirement already satisfied: semantic-version~=2.0 in /Users/devudilip/miniforge3/lib/python3.12/site-packages (from gradio) (2.10.0)\n",
"Requirement already satisfied: starlette<1.0,>=0.40.0 in /Users/devudilip/miniforge3/lib/python3.12/site-packages (from gradio) (0.46.1)\n",
"Requirement already satisfied: tomlkit<0.14.0,>=0.12.0 in /Users/devudilip/miniforge3/lib/python3.12/site-packages (from gradio) (0.13.2)\n",
"Requirement already satisfied: typer<1.0,>=0.12 in /Users/devudilip/miniforge3/lib/python3.12/site-packages (from gradio) (0.15.2)\n",
"Requirement already satisfied: typing-extensions~=4.0 in /Users/devudilip/miniforge3/lib/python3.12/site-packages (from gradio) (4.12.2)\n",
"Requirement already satisfied: uvicorn>=0.14.0 in /Users/devudilip/miniforge3/lib/python3.12/site-packages (from gradio) (0.34.0)\n",
"Requirement already satisfied: fsspec in /Users/devudilip/miniforge3/lib/python3.12/site-packages (from gradio-client==1.8.0->gradio) (2024.12.0)\n",
"Requirement already satisfied: websockets<16.0,>=10.0 in /Users/devudilip/miniforge3/lib/python3.12/site-packages (from gradio-client==1.8.0->gradio) (11.0.3)\n",
"Requirement already satisfied: idna>=2.8 in /Users/devudilip/miniforge3/lib/python3.12/site-packages (from anyio<5.0,>=3.0->gradio) (3.10)\n",
"Requirement already satisfied: sniffio>=1.1 in /Users/devudilip/miniforge3/lib/python3.12/site-packages (from anyio<5.0,>=3.0->gradio) (1.3.1)\n",
"Requirement already satisfied: certifi in /Users/devudilip/miniforge3/lib/python3.12/site-packages (from httpx>=0.24.1->gradio) (2025.1.31)\n",
"Requirement already satisfied: httpcore==1.* in /Users/devudilip/miniforge3/lib/python3.12/site-packages (from httpx>=0.24.1->gradio) (1.0.7)\n",
"Requirement already satisfied: h11<0.15,>=0.13 in /Users/devudilip/miniforge3/lib/python3.12/site-packages (from httpcore==1.*->httpx>=0.24.1->gradio) (0.14.0)\n",
"Requirement already satisfied: filelock in /Users/devudilip/miniforge3/lib/python3.12/site-packages (from huggingface-hub>=0.28.1->gradio) (3.18.0)\n",
"Requirement already satisfied: requests in /Users/devudilip/miniforge3/lib/python3.12/site-packages (from huggingface-hub>=0.28.1->gradio) (2.32.3)\n",
"Requirement already satisfied: tqdm>=4.42.1 in /Users/devudilip/miniforge3/lib/python3.12/site-packages (from huggingface-hub>=0.28.1->gradio) (4.67.1)\n",
"Requirement already satisfied: python-dateutil>=2.8.2 in /Users/devudilip/miniforge3/lib/python3.12/site-packages (from pandas<3.0,>=1.0->gradio) (2.9.0.post0)\n",
"Requirement already satisfied: pytz>=2020.1 in /Users/devudilip/miniforge3/lib/python3.12/site-packages (from pandas<3.0,>=1.0->gradio) (2024.1)\n",
"Requirement already satisfied: tzdata>=2022.7 in /Users/devudilip/miniforge3/lib/python3.12/site-packages (from pandas<3.0,>=1.0->gradio) (2025.1)\n",
"Requirement already satisfied: annotated-types>=0.6.0 in /Users/devudilip/miniforge3/lib/python3.12/site-packages (from pydantic>=2.0->gradio) (0.7.0)\n",
"Requirement already satisfied: pydantic-core==2.27.2 in /Users/devudilip/miniforge3/lib/python3.12/site-packages (from pydantic>=2.0->gradio) (2.27.2)\n",
"Requirement already satisfied: click>=8.0.0 in /Users/devudilip/miniforge3/lib/python3.12/site-packages (from typer<1.0,>=0.12->gradio) (8.1.8)\n",
"Requirement already satisfied: shellingham>=1.3.0 in /Users/devudilip/miniforge3/lib/python3.12/site-packages (from typer<1.0,>=0.12->gradio) (1.5.4)\n",
"Requirement already satisfied: rich>=10.11.0 in /Users/devudilip/miniforge3/lib/python3.12/site-packages (from typer<1.0,>=0.12->gradio) (13.9.4)\n",
"Requirement already satisfied: six>=1.5 in /Users/devudilip/miniforge3/lib/python3.12/site-packages (from python-dateutil>=2.8.2->pandas<3.0,>=1.0->gradio) (1.17.0)\n",
"Requirement already satisfied: markdown-it-py>=2.2.0 in /Users/devudilip/miniforge3/lib/python3.12/site-packages (from rich>=10.11.0->typer<1.0,>=0.12->gradio) (3.0.0)\n",
"Requirement already satisfied: pygments<3.0.0,>=2.13.0 in /Users/devudilip/miniforge3/lib/python3.12/site-packages (from rich>=10.11.0->typer<1.0,>=0.12->gradio) (2.19.1)\n",
"Requirement already satisfied: charset_normalizer<4,>=2 in /Users/devudilip/miniforge3/lib/python3.12/site-packages (from requests->huggingface-hub>=0.28.1->gradio) (3.4.1)\n",
"Requirement already satisfied: urllib3<3,>=1.21.1 in /Users/devudilip/miniforge3/lib/python3.12/site-packages (from requests->huggingface-hub>=0.28.1->gradio) (2.3.0)\n",
"Requirement already satisfied: mdurl~=0.1 in /Users/devudilip/miniforge3/lib/python3.12/site-packages (from markdown-it-py>=2.2.0->rich>=10.11.0->typer<1.0,>=0.12->gradio) (0.1.2)\n",
"Using cached gradio-5.22.0-py3-none-any.whl (46.2 MB)\n",
"Using cached gradio_client-1.8.0-py3-none-any.whl (322 kB)\n",
"Installing collected packages: gradio-client, gradio\n",
" Attempting uninstall: gradio-client\n",
" Found existing installation: gradio_client 0.5.0\n",
" Uninstalling gradio_client-0.5.0:\n",
" Successfully uninstalled gradio_client-0.5.0\n",
" Attempting uninstall: gradio\n",
" Found existing installation: gradio 3.0\n",
" Uninstalling gradio-3.0:\n",
" Successfully uninstalled gradio-3.0\n",
"Successfully installed gradio-5.22.0 gradio-client-1.8.0\n"
]
}
],
"source": [
"!pip install --upgrade gradio"
]
},
{
"cell_type": "code",
"execution_count": 31,
"id": "f43155f8",
"metadata": {},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"Name: gradio\r\n",
"Version: 5.22.0\r\n",
"Summary: Python library for easily interacting with trained machine learning models\r\n",
"Home-page: https://github.com/gradio-app/gradio\r\n",
"Author: \r\n",
"Author-email: Abubakar Abid <gradio-team@huggingface.co>, Ali Abid <gradio-team@huggingface.co>, Ali Abdalla <gradio-team@huggingface.co>, Dawood Khan <gradio-team@huggingface.co>, Ahsen Khaliq <gradio-team@huggingface.co>, Pete Allen <gradio-team@huggingface.co>, Ömer Faruk Özdemir <gradio-team@huggingface.co>, Freddy A Boulton <gradio-team@huggingface.co>, Hannah Blair <gradio-team@huggingface.co>\r\n",
"License-Expression: Apache-2.0\r\n",
"Location: /Users/devudilip/miniforge3/lib/python3.12/site-packages\r\n",
"Requires: aiofiles, anyio, fastapi, ffmpy, gradio-client, groovy, httpx, huggingface-hub, jinja2, markupsafe, numpy, orjson, packaging, pandas, pillow, pydantic, pydub, python-multipart, pyyaml, ruff, safehttpx, semantic-version, starlette, tomlkit, typer, typing-extensions, uvicorn\r\n",
"Required-by: \r\n"
]
}
],
"source": [
"!pip show gradio"
]
},
{
"cell_type": "code",
"execution_count": 33,
"id": "78a256f7",
"metadata": {},
"outputs": [
{
"name": "stderr",
"output_type": "stream",
"text": [
"Exception in thread Thread-90 (run):\n",
"Traceback (most recent call last):\n",
" File \"/Users/devudilip/miniforge3/lib/python3.12/threading.py\", line 1075, in _bootstrap_inner\n",
" self.run()\n",
" File \"/Users/devudilip/miniforge3/lib/python3.12/site-packages/ipykernel/ipkernel.py\", line 766, in run_closure\n",
" _threading_Thread_run(self)\n",
" File \"/Users/devudilip/miniforge3/lib/python3.12/threading.py\", line 1012, in run\n",
" self._target(*self._args, **self._kwargs)\n",
" File \"/Users/devudilip/miniforge3/lib/python3.12/site-packages/uvicorn/server.py\", line 66, in run\n",
" return asyncio.run(self.serve(sockets=sockets))\n",
" ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^\n",
" File \"/Users/devudilip/miniforge3/lib/python3.12/asyncio/runners.py\", line 195, in run\n",
" return runner.run(main)\n",
" ^^^^^^^^^^^^^^^^\n",
" File \"/Users/devudilip/miniforge3/lib/python3.12/asyncio/runners.py\", line 118, in run\n",
" return self._loop.run_until_complete(task)\n",
" ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^\n",
" File \"/Users/devudilip/miniforge3/lib/python3.12/asyncio/base_events.py\", line 691, in run_until_complete\n",
" return future.result()\n",
" ^^^^^^^^^^^^^^^\n",
" File \"/Users/devudilip/miniforge3/lib/python3.12/site-packages/uvicorn/server.py\", line 70, in serve\n",
" await self._serve(sockets)\n",
" File \"/Users/devudilip/miniforge3/lib/python3.12/site-packages/uvicorn/server.py\", line 77, in _serve\n",
" config.load()\n",
" File \"/Users/devudilip/miniforge3/lib/python3.12/site-packages/uvicorn/config.py\", line 427, in load\n",
" ws_protocol_class = import_from_string(WS_PROTOCOLS[self.ws])\n",
" ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^\n",
" File \"/Users/devudilip/miniforge3/lib/python3.12/site-packages/uvicorn/importer.py\", line 22, in import_from_string\n",
" raise exc from None\n",
" File \"/Users/devudilip/miniforge3/lib/python3.12/site-packages/uvicorn/importer.py\", line 19, in import_from_string\n",
" module = importlib.import_module(module_str)\n",
" ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^\n",
" File \"/Users/devudilip/miniforge3/lib/python3.12/importlib/__init__.py\", line 90, in import_module\n",
" return _bootstrap._gcd_import(name[level:], package, level)\n",
" ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^\n",
" File \"<frozen importlib._bootstrap>\", line 1387, in _gcd_import\n",
" File \"<frozen importlib._bootstrap>\", line 1360, in _find_and_load\n",
" File \"<frozen importlib._bootstrap>\", line 1331, in _find_and_load_unlocked\n",
" File \"<frozen importlib._bootstrap>\", line 935, in _load_unlocked\n",
" File \"<frozen importlib._bootstrap_external>\", line 999, in exec_module\n",
" File \"<frozen importlib._bootstrap>\", line 488, in _call_with_frames_removed\n",
" File \"/Users/devudilip/miniforge3/lib/python3.12/site-packages/uvicorn/protocols/websockets/auto.py\", line 19, in <module>\n",
" from uvicorn.protocols.websockets.websockets_impl import WebSocketProtocol\n",
" File \"/Users/devudilip/miniforge3/lib/python3.12/site-packages/uvicorn/protocols/websockets/websockets_impl.py\", line 16, in <module>\n",
" from websockets.legacy.server import HTTPResponse\n",
" File \"/Users/devudilip/miniforge3/lib/python3.12/site-packages/websockets/legacy/server.py\", line 29, in <module>\n",
" from ..exceptions import (\n",
" File \"/Users/devudilip/miniforge3/lib/python3.12/site-packages/websockets/imports.py\", line 91, in __getattr__\n",
" \n",
" File \"/Users/devudilip/miniforge3/lib/python3.12/site-packages/websockets/imports.py\", line 28, in import_name\n",
" return getattr(module, name)\n",
" ^^^^^^^^^^^^^^^^^^^^\n",
"ModuleNotFoundError: No module named 'websockets.legacy.exceptions'\n",
"Exception in thread Thread-91 (run):\n",
"Traceback (most recent call last):\n",
" File \"/Users/devudilip/miniforge3/lib/python3.12/threading.py\", line 1075, in _bootstrap_inner\n",
" self.run()\n",
" File \"/Users/devudilip/miniforge3/lib/python3.12/site-packages/ipykernel/ipkernel.py\", line 766, in run_closure\n",
" _threading_Thread_run(self)\n",
" File \"/Users/devudilip/miniforge3/lib/python3.12/threading.py\", line 1012, in run\n",
" self._target(*self._args, **self._kwargs)\n",
" File \"/Users/devudilip/miniforge3/lib/python3.12/site-packages/uvicorn/server.py\", line 66, in run\n",
" return asyncio.run(self.serve(sockets=sockets))\n",
" ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^\n",
" File \"/Users/devudilip/miniforge3/lib/python3.12/asyncio/runners.py\", line 195, in run\n",
" return runner.run(main)\n",
" ^^^^^^^^^^^^^^^^\n",
" File \"/Users/devudilip/miniforge3/lib/python3.12/asyncio/runners.py\", line 118, in run\n",
" return self._loop.run_until_complete(task)\n",
" ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^\n",
" File \"/Users/devudilip/miniforge3/lib/python3.12/asyncio/base_events.py\", line 691, in run_until_complete\n",
" return future.result()\n",
" ^^^^^^^^^^^^^^^\n",
" File \"/Users/devudilip/miniforge3/lib/python3.12/site-packages/uvicorn/server.py\", line 70, in serve\n",
" await self._serve(sockets)\n",
" File \"/Users/devudilip/miniforge3/lib/python3.12/site-packages/uvicorn/server.py\", line 77, in _serve\n",
" config.load()\n",
" File \"/Users/devudilip/miniforge3/lib/python3.12/site-packages/uvicorn/config.py\", line 427, in load\n",
" ws_protocol_class = import_from_string(WS_PROTOCOLS[self.ws])\n",
" ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^\n",
" File \"/Users/devudilip/miniforge3/lib/python3.12/site-packages/uvicorn/importer.py\", line 22, in import_from_string\n",
" raise exc from None\n",
" File \"/Users/devudilip/miniforge3/lib/python3.12/site-packages/uvicorn/importer.py\", line 19, in import_from_string\n",
" module = importlib.import_module(module_str)\n",
" ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^\n",
" File \"/Users/devudilip/miniforge3/lib/python3.12/importlib/__init__.py\", line 90, in import_module\n",
" return _bootstrap._gcd_import(name[level:], package, level)\n",
" ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^\n",
" File \"<frozen importlib._bootstrap>\", line 1387, in _gcd_import\n",
" File \"<frozen importlib._bootstrap>\", line 1360, in _find_and_load\n",
" File \"<frozen importlib._bootstrap>\", line 1331, in _find_and_load_unlocked\n",
" File \"<frozen importlib._bootstrap>\", line 935, in _load_unlocked\n",
" File \"<frozen importlib._bootstrap_external>\", line 999, in exec_module\n",
" File \"<frozen importlib._bootstrap>\", line 488, in _call_with_frames_removed\n",
" File \"/Users/devudilip/miniforge3/lib/python3.12/site-packages/uvicorn/protocols/websockets/auto.py\", line 19, in <module>\n",
" from uvicorn.protocols.websockets.websockets_impl import WebSocketProtocol\n",
" File \"/Users/devudilip/miniforge3/lib/python3.12/site-packages/uvicorn/protocols/websockets/websockets_impl.py\", line 16, in <module>\n",
" from websockets.legacy.server import HTTPResponse\n",
" File \"/Users/devudilip/miniforge3/lib/python3.12/site-packages/websockets/legacy/server.py\", line 29, in <module>\n",
" from ..exceptions import (\n",
" File \"/Users/devudilip/miniforge3/lib/python3.12/site-packages/websockets/imports.py\", line 91, in __getattr__\n",
" \n",
" File \"/Users/devudilip/miniforge3/lib/python3.12/site-packages/websockets/imports.py\", line 28, in import_name\n",
" return getattr(module, name)\n",
" ^^^^^^^^^^^^^^^^^^^^\n",
"ModuleNotFoundError: No module named 'websockets.legacy.exceptions'\n",
"Exception in thread Thread-92 (run):\n",
"Traceback (most recent call last):\n",
" File \"/Users/devudilip/miniforge3/lib/python3.12/threading.py\", line 1075, in _bootstrap_inner\n",
" self.run()\n",
" File \"/Users/devudilip/miniforge3/lib/python3.12/site-packages/ipykernel/ipkernel.py\", line 766, in run_closure\n",
" _threading_Thread_run(self)\n",
" File \"/Users/devudilip/miniforge3/lib/python3.12/threading.py\", line 1012, in run\n",
" self._target(*self._args, **self._kwargs)\n",
" File \"/Users/devudilip/miniforge3/lib/python3.12/site-packages/uvicorn/server.py\", line 66, in run\n",
" return asyncio.run(self.serve(sockets=sockets))\n",
" ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^\n",
" File \"/Users/devudilip/miniforge3/lib/python3.12/asyncio/runners.py\", line 195, in run\n",
" return runner.run(main)\n",
" ^^^^^^^^^^^^^^^^\n",
" File \"/Users/devudilip/miniforge3/lib/python3.12/asyncio/runners.py\", line 118, in run\n",
" return self._loop.run_until_complete(task)\n",
" ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^\n",
" File \"/Users/devudilip/miniforge3/lib/python3.12/asyncio/base_events.py\", line 691, in run_until_complete\n",
" return future.result()\n",
" ^^^^^^^^^^^^^^^\n",
" File \"/Users/devudilip/miniforge3/lib/python3.12/site-packages/uvicorn/server.py\", line 70, in serve\n",
" await self._serve(sockets)\n",
" File \"/Users/devudilip/miniforge3/lib/python3.12/site-packages/uvicorn/server.py\", line 77, in _serve\n",
" config.load()\n",
" File \"/Users/devudilip/miniforge3/lib/python3.12/site-packages/uvicorn/config.py\", line 427, in load\n",
" ws_protocol_class = import_from_string(WS_PROTOCOLS[self.ws])\n",
" ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^\n",
" File \"/Users/devudilip/miniforge3/lib/python3.12/site-packages/uvicorn/importer.py\", line 22, in import_from_string\n",
" raise exc from None\n",
" File \"/Users/devudilip/miniforge3/lib/python3.12/site-packages/uvicorn/importer.py\", line 19, in import_from_string\n",
" module = importlib.import_module(module_str)\n",
" ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^\n",
" File \"/Users/devudilip/miniforge3/lib/python3.12/importlib/__init__.py\", line 90, in import_module\n",
" return _bootstrap._gcd_import(name[level:], package, level)\n",
" ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^\n",
" File \"<frozen importlib._bootstrap>\", line 1387, in _gcd_import\n",
" File \"<frozen importlib._bootstrap>\", line 1360, in _find_and_load\n",
" File \"<frozen importlib._bootstrap>\", line 1331, in _find_and_load_unlocked\n",
" File \"<frozen importlib._bootstrap>\", line 935, in _load_unlocked\n",
" File \"<frozen importlib._bootstrap_external>\", line 999, in exec_module\n",
" File \"<frozen importlib._bootstrap>\", line 488, in _call_with_frames_removed\n",
" File \"/Users/devudilip/miniforge3/lib/python3.12/site-packages/uvicorn/protocols/websockets/auto.py\", line 19, in <module>\n",
" from uvicorn.protocols.websockets.websockets_impl import WebSocketProtocol\n",
" File \"/Users/devudilip/miniforge3/lib/python3.12/site-packages/uvicorn/protocols/websockets/websockets_impl.py\", line 16, in <module>\n",
" from websockets.legacy.server import HTTPResponse\n",
" File \"/Users/devudilip/miniforge3/lib/python3.12/site-packages/websockets/legacy/server.py\", line 29, in <module>\n",
" from ..exceptions import (\n",
" File \"/Users/devudilip/miniforge3/lib/python3.12/site-packages/websockets/imports.py\", line 91, in __getattr__\n",
" \n",
" File \"/Users/devudilip/miniforge3/lib/python3.12/site-packages/websockets/imports.py\", line 28, in import_name\n",
" return getattr(module, name)\n",
" ^^^^^^^^^^^^^^^^^^^^\n",
"ModuleNotFoundError: No module named 'websockets.legacy.exceptions'\n"
]
},
{
"ename": "KeyboardInterrupt",
"evalue": "",
"output_type": "error",
"traceback": [
"\u001b[31m---------------------------------------------------------------------------\u001b[39m",
"\u001b[31mKeyboardInterrupt\u001b[39m Traceback (most recent call last)",
"\u001b[36mCell\u001b[39m\u001b[36m \u001b[39m\u001b[32mIn[33]\u001b[39m\u001b[32m, line 12\u001b[39m\n\u001b[32m 4\u001b[39m \u001b[38;5;28;01mreturn\u001b[39;00m \u001b[33m\"\u001b[39m\u001b[33mHello, \u001b[39m\u001b[33m\"\u001b[39m + name + \u001b[33m\"\u001b[39m\u001b[33m!\u001b[39m\u001b[33m\"\u001b[39m * \u001b[38;5;28mint\u001b[39m(intensity)\n\u001b[32m 6\u001b[39m demo = gr.Interface(\n\u001b[32m 7\u001b[39m fn=greet,\n\u001b[32m 8\u001b[39m inputs=[\u001b[33m\"\u001b[39m\u001b[33mtext\u001b[39m\u001b[33m\"\u001b[39m, \u001b[33m\"\u001b[39m\u001b[33mslider\u001b[39m\u001b[33m\"\u001b[39m],\n\u001b[32m 9\u001b[39m outputs=[\u001b[33m\"\u001b[39m\u001b[33mtext\u001b[39m\u001b[33m\"\u001b[39m],\n\u001b[32m 10\u001b[39m )\n\u001b[32m---> \u001b[39m\u001b[32m12\u001b[39m \u001b[43mdemo\u001b[49m\u001b[43m.\u001b[49m\u001b[43mlaunch\u001b[49m\u001b[43m(\u001b[49m\u001b[43m)\u001b[49m\n",
"\u001b[36mFile \u001b[39m\u001b[32m~/miniforge3/lib/python3.12/site-packages/gradio/blocks.py:2604\u001b[39m, in \u001b[36mBlocks.launch\u001b[39m\u001b[34m(self, inline, inbrowser, share, debug, max_threads, auth, auth_message, prevent_thread_lock, show_error, server_name, server_port, height, width, favicon_path, ssl_keyfile, ssl_certfile, ssl_keyfile_password, ssl_verify, quiet, show_api, allowed_paths, blocked_paths, root_path, app_kwargs, state_session_capacity, share_server_address, share_server_protocol, share_server_tls_certificate, auth_dependency, max_file_size, enable_monitoring, strict_cors, node_server_name, node_port, ssr_mode, pwa, _frontend)\u001b[39m\n\u001b[32m 2596\u001b[39m \u001b[38;5;28;01melse\u001b[39;00m:\n\u001b[32m 2597\u001b[39m \u001b[38;5;28;01mfrom\u001b[39;00m\u001b[38;5;250m \u001b[39m\u001b[34;01mgradio\u001b[39;00m\u001b[38;5;250m \u001b[39m\u001b[38;5;28;01mimport\u001b[39;00m http_server\n\u001b[32m 2599\u001b[39m (\n\u001b[32m 2600\u001b[39m server_name,\n\u001b[32m 2601\u001b[39m server_port,\n\u001b[32m 2602\u001b[39m local_url,\n\u001b[32m 2603\u001b[39m server,\n\u001b[32m-> \u001b[39m\u001b[32m2604\u001b[39m ) = \u001b[43mhttp_server\u001b[49m\u001b[43m.\u001b[49m\u001b[43mstart_server\u001b[49m\u001b[43m(\u001b[49m\n\u001b[32m 2605\u001b[39m \u001b[43m \u001b[49m\u001b[43mapp\u001b[49m\u001b[43m=\u001b[49m\u001b[38;5;28;43mself\u001b[39;49m\u001b[43m.\u001b[49m\u001b[43mapp\u001b[49m\u001b[43m,\u001b[49m\n\u001b[32m 2606\u001b[39m \u001b[43m \u001b[49m\u001b[43mserver_name\u001b[49m\u001b[43m=\u001b[49m\u001b[43mserver_name\u001b[49m\u001b[43m,\u001b[49m\n\u001b[32m 2607\u001b[39m \u001b[43m \u001b[49m\u001b[43mserver_port\u001b[49m\u001b[43m=\u001b[49m\u001b[43mserver_port\u001b[49m\u001b[43m,\u001b[49m\n\u001b[32m 2608\u001b[39m \u001b[43m \u001b[49m\u001b[43mssl_keyfile\u001b[49m\u001b[43m=\u001b[49m\u001b[43mssl_keyfile\u001b[49m\u001b[43m,\u001b[49m\n\u001b[32m 2609\u001b[39m \u001b[43m \u001b[49m\u001b[43mssl_certfile\u001b[49m\u001b[43m=\u001b[49m\u001b[43mssl_certfile\u001b[49m\u001b[43m,\u001b[49m\n\u001b[32m 2610\u001b[39m \u001b[43m \u001b[49m\u001b[43mssl_keyfile_password\u001b[49m\u001b[43m=\u001b[49m\u001b[43mssl_keyfile_password\u001b[49m\u001b[43m,\u001b[49m\n\u001b[32m 2611\u001b[39m \u001b[43m \u001b[49m\u001b[43m)\u001b[49m\n\u001b[32m 2612\u001b[39m \u001b[38;5;28mself\u001b[39m.server_name = server_name\n\u001b[32m 2613\u001b[39m \u001b[38;5;28mself\u001b[39m.local_url = local_url\n",
"\u001b[36mFile \u001b[39m\u001b[32m~/miniforge3/lib/python3.12/site-packages/gradio/http_server.py:151\u001b[39m, in \u001b[36mstart_server\u001b[39m\u001b[34m(app, server_name, server_port, ssl_keyfile, ssl_certfile, ssl_keyfile_password)\u001b[39m\n\u001b[32m 141\u001b[39m reloader = SourceFileReloader(\n\u001b[32m 142\u001b[39m app=app,\n\u001b[32m 143\u001b[39m watch_dirs=GRADIO_WATCH_DIRS,\n\u001b[32m (...)\u001b[39m\u001b[32m 148\u001b[39m watch_module=sys.modules[\u001b[33m\"\u001b[39m\u001b[33m__main__\u001b[39m\u001b[33m\"\u001b[39m],\n\u001b[32m 149\u001b[39m )\n\u001b[32m 150\u001b[39m server = Server(config=config, reloader=reloader)\n\u001b[32m--> \u001b[39m\u001b[32m151\u001b[39m \u001b[43mserver\u001b[49m\u001b[43m.\u001b[49m\u001b[43mrun_in_thread\u001b[49m\u001b[43m(\u001b[49m\u001b[43m)\u001b[49m\n\u001b[32m 152\u001b[39m \u001b[38;5;28;01mbreak\u001b[39;00m\n\u001b[32m 153\u001b[39m \u001b[38;5;28;01mexcept\u001b[39;00m (\u001b[38;5;167;01mOSError\u001b[39;00m, ServerFailedToStartError):\n",
"\u001b[36mFile \u001b[39m\u001b[32m~/miniforge3/lib/python3.12/site-packages/gradio/http_server.py:58\u001b[39m, in \u001b[36mServer.run_in_thread\u001b[39m\u001b[34m(self)\u001b[39m\n\u001b[32m 56\u001b[39m start = time.time()\n\u001b[32m 57\u001b[39m \u001b[38;5;28;01mwhile\u001b[39;00m \u001b[38;5;129;01mnot\u001b[39;00m \u001b[38;5;28mself\u001b[39m.started:\n\u001b[32m---> \u001b[39m\u001b[32m58\u001b[39m \u001b[43mtime\u001b[49m\u001b[43m.\u001b[49m\u001b[43msleep\u001b[49m\u001b[43m(\u001b[49m\u001b[32;43m1e-3\u001b[39;49m\u001b[43m)\u001b[49m\n\u001b[32m 59\u001b[39m \u001b[38;5;28;01mif\u001b[39;00m time.time() - start > \u001b[32m5\u001b[39m:\n\u001b[32m 60\u001b[39m \u001b[38;5;28;01mraise\u001b[39;00m ServerFailedToStartError(\n\u001b[32m 61\u001b[39m \u001b[33m\"\u001b[39m\u001b[33mServer failed to start. Please check that the port is available.\u001b[39m\u001b[33m\"\u001b[39m\n\u001b[32m 62\u001b[39m )\n",
"\u001b[31mKeyboardInterrupt\u001b[39m: "
]
}
],
"source": [
"import gradio as gr\n",
"\n",
"def greet(name, intensity):\n",
" return \"Hello, \" + name + \"!\" * int(intensity)\n",
"\n",
"demo = gr.Interface(\n",
" fn=greet,\n",
" inputs=[\"text\", \"slider\"],\n",
" outputs=[\"text\"],\n",
")\n",
"\n",
"demo.launch()"
]
},
{
"cell_type": "code",
"execution_count": null,
"id": "74837fee",
"metadata": {},
"outputs": [],
"source": []
},
{
"cell_type": "code",
"execution_count": null,
"id": "f61cb7c0",
"metadata": {},
"outputs": [],
"source": []
}
],
"metadata": {
"kernelspec": {
"display_name": "Python 3 (ipykernel)",
"language": "python",
"name": "python3"
},
"language_info": {
"codemirror_mode": {
"name": "ipython",
"version": 3
},
"file_extension": ".py",
"mimetype": "text/x-python",
"name": "python",
"nbconvert_exporter": "python",
"pygments_lexer": "ipython3",
"version": "3.12.9"
},
"toc": {
"base_numbering": 1,
"nav_menu": {},
"number_sections": true,
"sideBar": true,
"skip_h1_title": false,
"title_cell": "Table of Contents",
"title_sidebar": "Contents",
"toc_cell": false,
"toc_position": {},
"toc_section_display": true,
"toc_window_display": false
}
},
"nbformat": 4,
"nbformat_minor": 5
}
|