Spaces:
Running
Running
File size: 17,388 Bytes
5e4f96f |
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 |
{
"cells": [
{
"cell_type": "code",
"execution_count": 2,
"id": "7749520d-87e4-4afc-99ef-81648805978f",
"metadata": {},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"/usr/local/opt/[email protected]/bin/python3.10\n"
]
}
],
"source": [
"import sys\n",
"print(sys.executable)"
]
},
{
"cell_type": "code",
"execution_count": 1,
"id": "5d134602-bc54-4e93-98c4-e5d4c3d86362",
"metadata": {},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"['/Users/macbook/Desktop/SHK/Hugging Face Space/politweets', '/usr/local/Cellar/[email protected]/3.10.15/Frameworks/Python.framework/Versions/3.10/lib/python310.zip', '/usr/local/Cellar/[email protected]/3.10.15/Frameworks/Python.framework/Versions/3.10/lib/python3.10', '/usr/local/Cellar/[email protected]/3.10.15/Frameworks/Python.framework/Versions/3.10/lib/python3.10/lib-dynload', '', '/usr/local/lib/python3.10/site-packages']\n"
]
}
],
"source": [
"import sys\n",
"print(sys.path)"
]
},
{
"cell_type": "code",
"execution_count": 4,
"id": "32eabc30-8a6b-49e3-bb08-a51cdf77d642",
"metadata": {},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"Collecting gradio\n",
" Using cached gradio-4.44.0-py3-none-any.whl (18.1 MB)\n",
"Requirement already satisfied: huggingface-hub>=0.19.3 in /Users/macbook/.pyenv/versions/3.10.8/envs/politvenv/lib/python3.10/site-packages (from gradio) (0.25.0)\n",
"Collecting aiofiles<24.0,>=22.0\n",
" Using cached aiofiles-23.2.1-py3-none-any.whl (15 kB)\n",
"Collecting pydub\n",
" Using cached pydub-0.25.1-py2.py3-none-any.whl (32 kB)\n",
"Collecting anyio<5.0,>=3.0\n",
" Using cached anyio-4.6.0-py3-none-any.whl (89 kB)\n",
"Requirement already satisfied: matplotlib~=3.0 in /Users/macbook/.pyenv/versions/3.10.8/envs/politvenv/lib/python3.10/site-packages (from gradio) (3.9.2)\n",
"Collecting importlib-resources<7.0,>=1.3\n",
" Using cached importlib_resources-6.4.5-py3-none-any.whl (36 kB)\n",
"Collecting ffmpy\n",
" Using cached ffmpy-0.4.0-py3-none-any.whl (5.8 kB)\n",
"Collecting tomlkit==0.12.0\n",
" Using cached tomlkit-0.12.0-py3-none-any.whl (37 kB)\n",
"Requirement already satisfied: markupsafe~=2.0 in /Users/macbook/.pyenv/versions/3.10.8/envs/politvenv/lib/python3.10/site-packages (from gradio) (2.1.5)\n",
"Requirement already satisfied: numpy<3.0,>=1.0 in /Users/macbook/.pyenv/versions/3.10.8/envs/politvenv/lib/python3.10/site-packages (from gradio) (1.23.5)\n",
"Requirement already satisfied: pyyaml<7.0,>=5.0 in /Users/macbook/.pyenv/versions/3.10.8/envs/politvenv/lib/python3.10/site-packages (from gradio) (6.0.2)\n",
"Requirement already satisfied: pandas<3.0,>=1.0 in /Users/macbook/.pyenv/versions/3.10.8/envs/politvenv/lib/python3.10/site-packages (from gradio) (1.5.3)\n",
"Requirement already satisfied: typing-extensions~=4.0 in /Users/macbook/.pyenv/versions/3.10.8/envs/politvenv/lib/python3.10/site-packages (from gradio) (4.12.2)\n",
"Collecting uvicorn>=0.14.0\n",
" Using cached uvicorn-0.30.6-py3-none-any.whl (62 kB)\n",
"Requirement already satisfied: urllib3~=2.0 in /Users/macbook/.pyenv/versions/3.10.8/envs/politvenv/lib/python3.10/site-packages (from gradio) (2.2.3)\n",
"Collecting gradio-client==1.3.0\n",
" Using cached gradio_client-1.3.0-py3-none-any.whl (318 kB)\n",
"Collecting orjson~=3.0\n",
" Using cached orjson-3.10.7-cp310-cp310-macosx_10_15_x86_64.macosx_11_0_arm64.macosx_10_15_universal2.whl (251 kB)\n",
"Collecting httpx>=0.24.1\n",
" Using cached httpx-0.27.2-py3-none-any.whl (76 kB)\n",
"Requirement already satisfied: jinja2<4.0 in /Users/macbook/.pyenv/versions/3.10.8/envs/politvenv/lib/python3.10/site-packages (from gradio) (3.1.4)\n",
"Collecting ruff>=0.2.2\n",
" Using cached ruff-0.6.7-py3-none-macosx_10_12_x86_64.whl (10.0 MB)\n",
"Requirement already satisfied: packaging in /Users/macbook/.pyenv/versions/3.10.8/envs/politvenv/lib/python3.10/site-packages (from gradio) (24.1)\n",
"Collecting typer<1.0,>=0.12\n",
" Using cached typer-0.12.5-py3-none-any.whl (47 kB)\n",
"Requirement already satisfied: pillow<11.0,>=8.0 in /Users/macbook/.pyenv/versions/3.10.8/envs/politvenv/lib/python3.10/site-packages (from gradio) (9.4.0)\n",
"Collecting semantic-version~=2.0\n",
" Using cached semantic_version-2.10.0-py2.py3-none-any.whl (15 kB)\n",
"Collecting fastapi<1.0\n",
" Using cached fastapi-0.115.0-py3-none-any.whl (94 kB)\n",
"Collecting python-multipart>=0.0.9\n",
" Using cached python_multipart-0.0.10-py3-none-any.whl (22 kB)\n",
"Collecting pydantic>=2.0\n",
" Using cached pydantic-2.9.2-py3-none-any.whl (434 kB)\n",
"Requirement already satisfied: fsspec in /Users/macbook/.pyenv/versions/3.10.8/envs/politvenv/lib/python3.10/site-packages (from gradio-client==1.3.0->gradio) (2024.6.1)\n",
"Collecting websockets<13.0,>=10.0\n",
" Using cached websockets-12.0-cp310-cp310-macosx_10_9_x86_64.whl (121 kB)\n",
"Requirement already satisfied: idna>=2.8 in /Users/macbook/.pyenv/versions/3.10.8/envs/politvenv/lib/python3.10/site-packages (from anyio<5.0,>=3.0->gradio) (3.10)\n",
"Collecting sniffio>=1.1\n",
" Using cached sniffio-1.3.1-py3-none-any.whl (10 kB)\n",
"Requirement already satisfied: exceptiongroup>=1.0.2 in /Users/macbook/.pyenv/versions/3.10.8/envs/politvenv/lib/python3.10/site-packages (from anyio<5.0,>=3.0->gradio) (1.2.2)\n",
"Collecting starlette<0.39.0,>=0.37.2\n",
" Using cached starlette-0.38.5-py3-none-any.whl (71 kB)\n",
"Requirement already satisfied: certifi in /Users/macbook/.pyenv/versions/3.10.8/envs/politvenv/lib/python3.10/site-packages (from httpx>=0.24.1->gradio) (2024.8.30)\n",
"Collecting httpcore==1.*\n",
" Using cached httpcore-1.0.5-py3-none-any.whl (77 kB)\n",
"Collecting h11<0.15,>=0.13\n",
" Using cached h11-0.14.0-py3-none-any.whl (58 kB)\n",
"Requirement already satisfied: requests in /Users/macbook/.pyenv/versions/3.10.8/envs/politvenv/lib/python3.10/site-packages (from huggingface-hub>=0.19.3->gradio) (2.32.3)\n",
"Requirement already satisfied: filelock in /Users/macbook/.pyenv/versions/3.10.8/envs/politvenv/lib/python3.10/site-packages (from huggingface-hub>=0.19.3->gradio) (3.16.1)\n",
"Requirement already satisfied: tqdm>=4.42.1 in /Users/macbook/.pyenv/versions/3.10.8/envs/politvenv/lib/python3.10/site-packages (from huggingface-hub>=0.19.3->gradio) (4.66.5)\n",
"Requirement already satisfied: kiwisolver>=1.3.1 in /Users/macbook/.pyenv/versions/3.10.8/envs/politvenv/lib/python3.10/site-packages (from matplotlib~=3.0->gradio) (1.4.7)\n",
"Requirement already satisfied: contourpy>=1.0.1 in /Users/macbook/.pyenv/versions/3.10.8/envs/politvenv/lib/python3.10/site-packages (from matplotlib~=3.0->gradio) (1.3.0)\n",
"Requirement already satisfied: python-dateutil>=2.7 in /Users/macbook/.pyenv/versions/3.10.8/envs/politvenv/lib/python3.10/site-packages (from matplotlib~=3.0->gradio) (2.9.0.post0)\n",
"Requirement already satisfied: cycler>=0.10 in /Users/macbook/.pyenv/versions/3.10.8/envs/politvenv/lib/python3.10/site-packages (from matplotlib~=3.0->gradio) (0.12.1)\n",
"Requirement already satisfied: pyparsing>=2.3.1 in /Users/macbook/.pyenv/versions/3.10.8/envs/politvenv/lib/python3.10/site-packages (from matplotlib~=3.0->gradio) (3.2.0b1)\n",
"Requirement already satisfied: fonttools>=4.22.0 in /Users/macbook/.pyenv/versions/3.10.8/envs/politvenv/lib/python3.10/site-packages (from matplotlib~=3.0->gradio) (4.53.1)\n",
"Requirement already satisfied: pytz>=2020.1 in /Users/macbook/.pyenv/versions/3.10.8/envs/politvenv/lib/python3.10/site-packages (from pandas<3.0,>=1.0->gradio) (2024.2)\n",
"Collecting pydantic-core==2.23.4\n",
" Using cached pydantic_core-2.23.4-cp310-cp310-macosx_10_12_x86_64.whl (1.9 MB)\n",
"Collecting annotated-types>=0.6.0\n",
" Using cached annotated_types-0.7.0-py3-none-any.whl (13 kB)\n",
"Requirement already satisfied: rich>=10.11.0 in /Users/macbook/.pyenv/versions/3.10.8/envs/politvenv/lib/python3.10/site-packages (from typer<1.0,>=0.12->gradio) (13.8.1)\n",
"Collecting shellingham>=1.3.0\n",
" Using cached shellingham-1.5.4-py2.py3-none-any.whl (9.8 kB)\n",
"Requirement already satisfied: click>=8.0.0 in /Users/macbook/.pyenv/versions/3.10.8/envs/politvenv/lib/python3.10/site-packages (from typer<1.0,>=0.12->gradio) (8.1.7)\n",
"Requirement already satisfied: six>=1.5 in /Users/macbook/.pyenv/versions/3.10.8/envs/politvenv/lib/python3.10/site-packages (from python-dateutil>=2.7->matplotlib~=3.0->gradio) (1.16.0)\n",
"Requirement already satisfied: pygments<3.0.0,>=2.13.0 in /Users/macbook/.pyenv/versions/3.10.8/envs/politvenv/lib/python3.10/site-packages (from rich>=10.11.0->typer<1.0,>=0.12->gradio) (2.18.0)\n",
"Requirement already satisfied: markdown-it-py>=2.2.0 in /Users/macbook/.pyenv/versions/3.10.8/envs/politvenv/lib/python3.10/site-packages (from rich>=10.11.0->typer<1.0,>=0.12->gradio) (3.0.0)\n",
"Requirement already satisfied: charset-normalizer<4,>=2 in /Users/macbook/.pyenv/versions/3.10.8/envs/politvenv/lib/python3.10/site-packages (from requests->huggingface-hub>=0.19.3->gradio) (3.3.2)\n",
"Requirement already satisfied: mdurl~=0.1 in /Users/macbook/.pyenv/versions/3.10.8/envs/politvenv/lib/python3.10/site-packages (from markdown-it-py>=2.2.0->rich>=10.11.0->typer<1.0,>=0.12->gradio) (0.1.2)\n",
"Installing collected packages: pydub, websockets, tomlkit, sniffio, shellingham, semantic-version, ruff, python-multipart, pydantic-core, orjson, importlib-resources, h11, ffmpy, annotated-types, aiofiles, uvicorn, pydantic, httpcore, anyio, typer, starlette, httpx, gradio-client, fastapi, gradio\n",
"Successfully installed aiofiles-23.2.1 annotated-types-0.7.0 anyio-4.6.0 fastapi-0.115.0 ffmpy-0.4.0 gradio-4.44.0 gradio-client-1.3.0 h11-0.14.0 httpcore-1.0.5 httpx-0.27.2 importlib-resources-6.4.5 orjson-3.10.7 pydantic-2.9.2 pydantic-core-2.23.4 pydub-0.25.1 python-multipart-0.0.10 ruff-0.6.7 semantic-version-2.10.0 shellingham-1.5.4 sniffio-1.3.1 starlette-0.38.5 tomlkit-0.12.0 typer-0.12.5 uvicorn-0.30.6 websockets-12.0\n",
"\n",
"\u001b[1m[\u001b[0m\u001b[34;49mnotice\u001b[0m\u001b[1;39;49m]\u001b[0m\u001b[39;49m A new release of pip available: \u001b[0m\u001b[31;49m22.2.2\u001b[0m\u001b[39;49m -> \u001b[0m\u001b[32;49m24.2\u001b[0m\n",
"\u001b[1m[\u001b[0m\u001b[34;49mnotice\u001b[0m\u001b[1;39;49m]\u001b[0m\u001b[39;49m To update, run: \u001b[0m\u001b[32;49mpython -m pip install --upgrade pip\u001b[0m\n"
]
}
],
"source": [
"!pip install gradio\n",
"#python3 -m pip install --pre autogluon.text==0.6.3b20230123"
]
},
{
"cell_type": "code",
"execution_count": 1,
"id": "c812ee32-9fe0-4087-a926-56a91a66ccb4",
"metadata": {},
"outputs": [],
"source": [
"#|default_exp app"
]
},
{
"cell_type": "code",
"execution_count": 4,
"id": "6850377a-b227-4183-90e6-a850e9a65761",
"metadata": {},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"4.44.0\n"
]
}
],
"source": [
"#|export\n",
"#from fastai.vision.all import *\n",
"import gradio as gr\n",
"\n",
"print(gr.__version__)"
]
},
{
"cell_type": "code",
"execution_count": null,
"id": "6e0bb471-02ca-484e-9a26-f5a36fe38ed4",
"metadata": {
"editable": true,
"slideshow": {
"slide_type": ""
},
"tags": []
},
"outputs": [],
"source": [
"#|export\n",
"learn = load_learner('model.pkl')"
]
},
{
"cell_type": "code",
"execution_count": 15,
"id": "42242b57-3569-46f2-9966-c737dd6e6f16",
"metadata": {},
"outputs": [],
"source": [
"import pandas as pd"
]
},
{
"cell_type": "code",
"execution_count": 5,
"id": "4e41db23-e369-413d-ab25-f85cd21af0c4",
"metadata": {},
"outputs": [],
"source": [
"import gradio as gr"
]
},
{
"cell_type": "code",
"execution_count": 1,
"id": "411ef985-d45e-4b17-b33c-24fde7c00b4f",
"metadata": {},
"outputs": [
{
"name": "stderr",
"output_type": "stream",
"text": [
"/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",
" from .autonotebook import tqdm as notebook_tqdm\n",
"Matplotlib is building the font cache; this may take a moment.\n"
]
}
],
"source": [
"#import gradio as gr\n",
"from autogluon.text import TextPredictor"
]
},
{
"cell_type": "code",
"execution_count": 9,
"id": "7de002b3-e67f-46b9-95d1-e07a1bea7f5a",
"metadata": {},
"outputs": [],
"source": [
"# Load your saved AutoGluon model\n",
"predictor = TextPredictor.load(\"trained_autogluon\")"
]
},
{
"cell_type": "code",
"execution_count": 26,
"id": "d3093469-f35f-4008-9da4-340c64a9f85a",
"metadata": {},
"outputs": [],
"source": [
"# Define a prediction function for text classification\n",
"def classify_text(text):\n",
" single_row = pd.DataFrame([text], columns=[\"text\"])\n",
" prediction = predictor.predict(single_row)\n",
" return prediction[0]\n",
" "
]
},
{
"cell_type": "code",
"execution_count": 27,
"id": "8e2ad81f-5b87-47c1-a60a-fd45616e8fb0",
"metadata": {},
"outputs": [],
"source": [
"# Create a Gradio interface\n",
"demo = gr.Interface(fn=classify_text, inputs=\"text\", outputs=\"label\", title=\"AutoGluon Text Classification Demo\")"
]
},
{
"cell_type": "code",
"execution_count": 28,
"id": "18d88162-30cc-4a6b-8581-793ed65aef0f",
"metadata": {},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"Running on local URL: http://127.0.0.1:7861\n",
"\n",
"To create a public link, set `share=True` in `launch()`.\n"
]
},
{
"data": {
"text/html": [
"<div><iframe src=\"http://127.0.0.1:7861/\" width=\"100%\" height=\"500\" allow=\"autoplay; camera; microphone; clipboard-read; clipboard-write;\" frameborder=\"0\" allowfullscreen></iframe></div>"
],
"text/plain": [
"<IPython.core.display.HTML object>"
]
},
"metadata": {},
"output_type": "display_data"
},
{
"data": {
"text/plain": []
},
"execution_count": 28,
"metadata": {},
"output_type": "execute_result"
},
{
"name": "stderr",
"output_type": "stream",
"text": [
"Global seed set to 123\n",
"/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",
" warnings.warn(\n",
"Global seed set to 123\n",
"/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",
" warnings.warn(\n",
"Global seed set to 123\n",
"/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",
" warnings.warn(\n",
"Global seed set to 123\n",
"/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",
" warnings.warn(\n",
"Global seed set to 123\n",
"/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",
" warnings.warn(\n",
"Global seed set to 123\n",
"/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",
" warnings.warn(\n"
]
}
],
"source": [
"# Launch the app\n",
"demo.launch()"
]
}
],
"metadata": {
"kernelspec": {
"display_name": "politvenvnotebook",
"language": "python",
"name": "politvenvnotebook"
},
"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.10.8"
}
},
"nbformat": 4,
"nbformat_minor": 5
}
|