├── .dockerignore ├── requirements.txt ├── README.md ├── Dockerfile ├── src └── main.py └── .gitignore /.dockerignore: -------------------------------------------------------------------------------- 1 | venv/ -------------------------------------------------------------------------------- /requirements.txt: -------------------------------------------------------------------------------- 1 | gradio 2 | altair 3 | pillow 4 | torch 5 | torchvision 6 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # AI Gradio Template 2 | 3 | ## Build and Run 4 | 5 | ```bash 6 | docker build -t ai_gradio_template -f Dockerfile . 7 | ``` 8 | 9 | ```bash 10 | docker run -d -p 7860:7860 ai_gradio_template 11 | ``` 12 | -------------------------------------------------------------------------------- /Dockerfile: -------------------------------------------------------------------------------- 1 | FROM pytorch/pytorch:1.12.0-cuda11.3-cudnn8-runtime 2 | 3 | RUN apt-get update && \ 4 | apt-get install ffmpeg libsm6 libxext6 -y && \ 5 | rm -rf /var/lib/apt/lists/* 6 | 7 | COPY requirements.txt ./requirements.txt 8 | 9 | RUN python -m pip install -U pip && \ 10 | python -m pip install -r requirements.txt && \ 11 | python -m pip cache purge 12 | 13 | COPY ./ /app/ 14 | 15 | WORKDIR /app/ 16 | 17 | CMD python src/main.py 18 | -------------------------------------------------------------------------------- /src/main.py: -------------------------------------------------------------------------------- 1 | import gradio as gr 2 | import torch 3 | 4 | 5 | print("Model initialization starts") 6 | model = torch.hub.load( 7 | "AK391/animegan2-pytorch:main", 8 | "generator", 9 | pretrained="face_paint_512_v2", 10 | ) 11 | face2paint = torch.hub.load( 12 | 'AK391/animegan2-pytorch:main', 13 | 'face2paint', 14 | size=512, 15 | side_by_side=False, 16 | ) 17 | print("Model initialization ends") 18 | 19 | def inference(img): 20 | out = face2paint(model, img) 21 | return out 22 | 23 | 24 | demo = gr.Interface( 25 | fn=inference, 26 | inputs=[ 27 | gr.inputs.Image(type="pil"), 28 | ], 29 | outputs=[ 30 | gr.outputs.Image(type="pil"), 31 | ], 32 | allow_flagging="never", 33 | title="AnimeGAN template", 34 | ) 35 | 36 | demo.launch(server_name="0.0.0.0") -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | # User-specific stuff 2 | .idea/**/workspace.xml 3 | .idea/**/tasks.xml 4 | .idea/**/usage.statistics.xml 5 | .idea/**/dictionaries 6 | .idea/**/shelf 7 | 8 | # AWS User-specific 9 | .idea/**/aws.xml 10 | 11 | # Generated files 12 | .idea/**/contentModel.xml 13 | 14 | # Sensitive or high-churn files 15 | .idea/**/dataSources/ 16 | .idea/**/dataSources.ids 17 | .idea/**/dataSources.local.xml 18 | .idea/**/sqlDataSources.xml 19 | .idea/**/dynamic.xml 20 | .idea/**/uiDesigner.xml 21 | .idea/**/dbnavigator.xml 22 | 23 | # Gradle 24 | .idea/**/gradle.xml 25 | .idea/**/libraries 26 | 27 | # Gradle and Maven with auto-import 28 | # When using Gradle or Maven with auto-import, you should exclude module files, 29 | # since they will be recreated, and may cause churn. Uncomment if using 30 | # auto-import. 31 | # .idea/artifacts 32 | # .idea/compiler.xml 33 | # .idea/jarRepositories.xml 34 | # .idea/modules.xml 35 | # .idea/*.iml 36 | # .idea/modules 37 | # *.iml 38 | # *.ipr 39 | 40 | # CMake 41 | cmake-build-*/ 42 | 43 | # Mongo Explorer plugin 44 | .idea/**/mongoSettings.xml 45 | 46 | # File-based project format 47 | *.iws 48 | 49 | # IntelliJ 50 | out/ 51 | 52 | # mpeltonen/sbt-idea plugin 53 | .idea_modules/ 54 | 55 | # JIRA plugin 56 | atlassian-ide-plugin.xml 57 | 58 | # Cursive Clojure plugin 59 | .idea/replstate.xml 60 | 61 | # SonarLint plugin 62 | .idea/sonarlint/ 63 | 64 | # Crashlytics plugin (for Android Studio and IntelliJ) 65 | com_crashlytics_export_strings.xml 66 | crashlytics.properties 67 | crashlytics-build.properties 68 | fabric.properties 69 | 70 | # Editor-based Rest Client 71 | .idea/httpRequests 72 | 73 | # Android studio 3.1+ serialized cache file 74 | .idea/caches/build_file_checksums.ser 75 | 76 | ### PyCharm Patch ### 77 | # Comment Reason: https://github.com/joeblau/gitignore.io/issues/186#issuecomment-215987721 78 | 79 | # *.iml 80 | # modules.xml 81 | # .idea/misc.xml 82 | # *.ipr 83 | 84 | # Sonarlint plugin 85 | # https://plugins.jetbrains.com/plugin/7973-sonarlint 86 | .idea/**/sonarlint/ 87 | 88 | # SonarQube Plugin 89 | # https://plugins.jetbrains.com/plugin/7238-sonarqube-community-plugin 90 | .idea/**/sonarIssues.xml 91 | 92 | # Markdown Navigator plugin 93 | # https://plugins.jetbrains.com/plugin/7896-markdown-navigator-enhanced 94 | .idea/**/markdown-navigator.xml 95 | .idea/**/markdown-navigator-enh.xml 96 | .idea/**/markdown-navigator/ 97 | 98 | # Cache file creation bug 99 | # See https://youtrack.jetbrains.com/issue/JBR-2257 100 | .idea/$CACHE_FILE$ 101 | 102 | # CodeStream plugin 103 | # https://plugins.jetbrains.com/plugin/12206-codestream 104 | .idea/codestream.xml 105 | 106 | ### Python ### 107 | # Byte-compiled / optimized / DLL files 108 | __pycache__/ 109 | *.py[cod] 110 | *$py.class 111 | 112 | # C extensions 113 | *.so 114 | 115 | # Distribution / packaging 116 | .Python 117 | build/ 118 | develop-eggs/ 119 | dist/ 120 | downloads/ 121 | eggs/ 122 | .eggs/ 123 | lib/ 124 | lib64/ 125 | parts/ 126 | sdist/ 127 | var/ 128 | wheels/ 129 | share/python-wheels/ 130 | *.egg-info/ 131 | .installed.cfg 132 | *.egg 133 | MANIFEST 134 | 135 | # PyInstaller 136 | # Usually these files are written by a python script from a template 137 | # before PyInstaller builds the exe, so as to inject date/other infos into it. 138 | *.manifest 139 | *.spec 140 | 141 | # Installer logs 142 | pip-log.txt 143 | pip-delete-this-directory.txt 144 | 145 | # Unit test / coverage reports 146 | htmlcov/ 147 | .tox/ 148 | .nox/ 149 | .coverage 150 | .coverage.* 151 | .cache 152 | nosetests.xml 153 | coverage.xml 154 | *.cover 155 | *.py,cover 156 | .hypothesis/ 157 | .pytest_cache/ 158 | cover/ 159 | 160 | # Translations 161 | *.mo 162 | *.pot 163 | 164 | # Django stuff: 165 | *.log 166 | local_settings.py 167 | db.sqlite3 168 | db.sqlite3-journal 169 | 170 | # Flask stuff: 171 | instance/ 172 | .webassets-cache 173 | 174 | # Scrapy stuff: 175 | .scrapy 176 | 177 | # Sphinx documentation 178 | docs/_build/ 179 | 180 | # PyBuilder 181 | .pybuilder/ 182 | target/ 183 | 184 | # Jupyter Notebook 185 | .ipynb_checkpoints 186 | 187 | # IPython 188 | profile_default/ 189 | ipython_config.py 190 | 191 | # pyenv 192 | # For a library or package, you might want to ignore these files since the code is 193 | # intended to run in multiple environments; otherwise, check them in: 194 | # .python-version 195 | 196 | # pipenv 197 | # According to pypa/pipenv#598, it is recommended to include Pipfile.lock in version control. 198 | # However, in case of collaboration, if having platform-specific dependencies or dependencies 199 | # having no cross-platform support, pipenv may install dependencies that don't work, or not 200 | # install all needed dependencies. 201 | #Pipfile.lock 202 | 203 | # poetry 204 | # Similar to Pipfile.lock, it is generally recommended to include poetry.lock in version control. 205 | # This is especially recommended for binary packages to ensure reproducibility, and is more 206 | # commonly ignored for libraries. 207 | # https://python-poetry.org/docs/basic-usage/#commit-your-poetrylock-file-to-version-control 208 | #poetry.lock 209 | 210 | # PEP 582; used by e.g. github.com/David-OConnor/pyflow 211 | __pypackages__/ 212 | 213 | # Celery stuff 214 | celerybeat-schedule 215 | celerybeat.pid 216 | 217 | # SageMath parsed files 218 | *.sage.py 219 | 220 | # Environments 221 | .idea 222 | .env 223 | .venv 224 | env/ 225 | venv/ 226 | ENV/ 227 | env.bak/ 228 | venv.bak/ 229 | 230 | # Spyder project settings 231 | .spyderproject 232 | .spyproject 233 | 234 | # Rope project settings 235 | .ropeproject 236 | 237 | # mkdocs documentation 238 | /site 239 | 240 | # mypy 241 | .mypy_cache/ 242 | .dmypy.json 243 | dmypy.json 244 | 245 | # Pyre type checker 246 | .pyre/ 247 | 248 | # pytype static type analyzer 249 | .pytype/ 250 | 251 | # Cython debug symbols 252 | cython_debug/ 253 | /resources --------------------------------------------------------------------------------