jaisree67 commited on
Commit
bc5a4f8
1 Parent(s): 88ca63d

Upload 21 files

Browse files
.gitattributes CHANGED
@@ -1,35 +1,34 @@
1
- *.7z filter=lfs diff=lfs merge=lfs -text
2
- *.arrow filter=lfs diff=lfs merge=lfs -text
3
- *.bin filter=lfs diff=lfs merge=lfs -text
4
- *.bz2 filter=lfs diff=lfs merge=lfs -text
5
- *.ckpt filter=lfs diff=lfs merge=lfs -text
6
- *.ftz filter=lfs diff=lfs merge=lfs -text
7
- *.gz filter=lfs diff=lfs merge=lfs -text
8
- *.h5 filter=lfs diff=lfs merge=lfs -text
9
- *.joblib filter=lfs diff=lfs merge=lfs -text
10
- *.lfs.* filter=lfs diff=lfs merge=lfs -text
11
- *.mlmodel filter=lfs diff=lfs merge=lfs -text
12
- *.model filter=lfs diff=lfs merge=lfs -text
13
- *.msgpack filter=lfs diff=lfs merge=lfs -text
14
- *.npy filter=lfs diff=lfs merge=lfs -text
15
- *.npz filter=lfs diff=lfs merge=lfs -text
16
- *.onnx filter=lfs diff=lfs merge=lfs -text
17
- *.ot filter=lfs diff=lfs merge=lfs -text
18
- *.parquet filter=lfs diff=lfs merge=lfs -text
19
- *.pb filter=lfs diff=lfs merge=lfs -text
20
- *.pickle filter=lfs diff=lfs merge=lfs -text
21
- *.pkl filter=lfs diff=lfs merge=lfs -text
22
- *.pt filter=lfs diff=lfs merge=lfs -text
23
- *.pth filter=lfs diff=lfs merge=lfs -text
24
- *.rar filter=lfs diff=lfs merge=lfs -text
25
- *.safetensors filter=lfs diff=lfs merge=lfs -text
26
- saved_model/**/* filter=lfs diff=lfs merge=lfs -text
27
- *.tar.* filter=lfs diff=lfs merge=lfs -text
28
- *.tar filter=lfs diff=lfs merge=lfs -text
29
- *.tflite filter=lfs diff=lfs merge=lfs -text
30
- *.tgz filter=lfs diff=lfs merge=lfs -text
31
- *.wasm filter=lfs diff=lfs merge=lfs -text
32
- *.xz filter=lfs diff=lfs merge=lfs -text
33
- *.zip filter=lfs diff=lfs merge=lfs -text
34
- *.zst filter=lfs diff=lfs merge=lfs -text
35
- *tfevents* filter=lfs diff=lfs merge=lfs -text
 
1
+ *.7z filter=lfs diff=lfs merge=lfs -text
2
+ *.arrow filter=lfs diff=lfs merge=lfs -text
3
+ *.bin filter=lfs diff=lfs merge=lfs -text
4
+ *.bz2 filter=lfs diff=lfs merge=lfs -text
5
+ *.ckpt filter=lfs diff=lfs merge=lfs -text
6
+ *.ftz filter=lfs diff=lfs merge=lfs -text
7
+ *.gz filter=lfs diff=lfs merge=lfs -text
8
+ *.h5 filter=lfs diff=lfs merge=lfs -text
9
+ *.joblib filter=lfs diff=lfs merge=lfs -text
10
+ *.lfs.* filter=lfs diff=lfs merge=lfs -text
11
+ *.mlmodel filter=lfs diff=lfs merge=lfs -text
12
+ *.model filter=lfs diff=lfs merge=lfs -text
13
+ *.msgpack filter=lfs diff=lfs merge=lfs -text
14
+ *.npy filter=lfs diff=lfs merge=lfs -text
15
+ *.npz filter=lfs diff=lfs merge=lfs -text
16
+ *.onnx filter=lfs diff=lfs merge=lfs -text
17
+ *.ot filter=lfs diff=lfs merge=lfs -text
18
+ *.parquet filter=lfs diff=lfs merge=lfs -text
19
+ *.pb filter=lfs diff=lfs merge=lfs -text
20
+ *.pickle filter=lfs diff=lfs merge=lfs -text
21
+ *.pkl filter=lfs diff=lfs merge=lfs -text
22
+ *.pt filter=lfs diff=lfs merge=lfs -text
23
+ *.pth filter=lfs diff=lfs merge=lfs -text
24
+ *.rar filter=lfs diff=lfs merge=lfs -text
25
+ *.safetensors filter=lfs diff=lfs merge=lfs -text
26
+ saved_model/**/* filter=lfs diff=lfs merge=lfs -text
27
+ *.tar.* filter=lfs diff=lfs merge=lfs -text
28
+ *.tflite filter=lfs diff=lfs merge=lfs -text
29
+ *.tgz filter=lfs diff=lfs merge=lfs -text
30
+ *.wasm filter=lfs diff=lfs merge=lfs -text
31
+ *.xz filter=lfs diff=lfs merge=lfs -text
32
+ *.zip filter=lfs diff=lfs merge=lfs -text
33
+ *.zst filter=lfs diff=lfs merge=lfs -text
34
+ *tfevents* filter=lfs diff=lfs merge=lfs -text
 
.gitignore ADDED
@@ -0,0 +1,164 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ .gradio/
2
+ shap_e_model_cache/
3
+ corgi.png
4
+
5
+ # Byte-compiled / optimized / DLL files
6
+ __pycache__/
7
+ *.py[cod]
8
+ *$py.class
9
+
10
+ # C extensions
11
+ *.so
12
+
13
+ # Distribution / packaging
14
+ .Python
15
+ build/
16
+ develop-eggs/
17
+ dist/
18
+ downloads/
19
+ eggs/
20
+ .eggs/
21
+ lib/
22
+ lib64/
23
+ parts/
24
+ sdist/
25
+ var/
26
+ wheels/
27
+ share/python-wheels/
28
+ *.egg-info/
29
+ .installed.cfg
30
+ *.egg
31
+ MANIFEST
32
+
33
+ # PyInstaller
34
+ # Usually these files are written by a python script from a template
35
+ # before PyInstaller builds the exe, so as to inject date/other infos into it.
36
+ *.manifest
37
+ *.spec
38
+
39
+ # Installer logs
40
+ pip-log.txt
41
+ pip-delete-this-directory.txt
42
+
43
+ # Unit test / coverage reports
44
+ htmlcov/
45
+ .tox/
46
+ .nox/
47
+ .coverage
48
+ .coverage.*
49
+ .cache
50
+ nosetests.xml
51
+ coverage.xml
52
+ *.cover
53
+ *.py,cover
54
+ .hypothesis/
55
+ .pytest_cache/
56
+ cover/
57
+
58
+ # Translations
59
+ *.mo
60
+ *.pot
61
+
62
+ # Django stuff:
63
+ *.log
64
+ local_settings.py
65
+ db.sqlite3
66
+ db.sqlite3-journal
67
+
68
+ # Flask stuff:
69
+ instance/
70
+ .webassets-cache
71
+
72
+ # Scrapy stuff:
73
+ .scrapy
74
+
75
+ # Sphinx documentation
76
+ docs/_build/
77
+
78
+ # PyBuilder
79
+ .pybuilder/
80
+ target/
81
+
82
+ # Jupyter Notebook
83
+ .ipynb_checkpoints
84
+
85
+ # IPython
86
+ profile_default/
87
+ ipython_config.py
88
+
89
+ # pyenv
90
+ # For a library or package, you might want to ignore these files since the code is
91
+ # intended to run in multiple environments; otherwise, check them in:
92
+ # .python-version
93
+
94
+ # pipenv
95
+ # According to pypa/pipenv#598, it is recommended to include Pipfile.lock in version control.
96
+ # However, in case of collaboration, if having platform-specific dependencies or dependencies
97
+ # having no cross-platform support, pipenv may install dependencies that don't work, or not
98
+ # install all needed dependencies.
99
+ #Pipfile.lock
100
+
101
+ # poetry
102
+ # Similar to Pipfile.lock, it is generally recommended to include poetry.lock in version control.
103
+ # This is especially recommended for binary packages to ensure reproducibility, and is more
104
+ # commonly ignored for libraries.
105
+ # https://python-poetry.org/docs/basic-usage/#commit-your-poetrylock-file-to-version-control
106
+ #poetry.lock
107
+
108
+ # pdm
109
+ # Similar to Pipfile.lock, it is generally recommended to include pdm.lock in version control.
110
+ #pdm.lock
111
+ # pdm stores project-wide configurations in .pdm.toml, but it is recommended to not include it
112
+ # in version control.
113
+ # https://pdm.fming.dev/#use-with-ide
114
+ .pdm.toml
115
+
116
+ # PEP 582; used by e.g. github.com/David-OConnor/pyflow and github.com/pdm-project/pdm
117
+ __pypackages__/
118
+
119
+ # Celery stuff
120
+ celerybeat-schedule
121
+ celerybeat.pid
122
+
123
+ # SageMath parsed files
124
+ *.sage.py
125
+
126
+ # Environments
127
+ .env
128
+ .venv
129
+ env/
130
+ venv/
131
+ ENV/
132
+ env.bak/
133
+ venv.bak/
134
+
135
+ # Spyder project settings
136
+ .spyderproject
137
+ .spyproject
138
+
139
+ # Rope project settings
140
+ .ropeproject
141
+
142
+ # mkdocs documentation
143
+ /site
144
+
145
+ # mypy
146
+ .mypy_cache/
147
+ .dmypy.json
148
+ dmypy.json
149
+
150
+ # Pyre type checker
151
+ .pyre/
152
+
153
+ # pytype static type analyzer
154
+ .pytype/
155
+
156
+ # Cython debug symbols
157
+ cython_debug/
158
+
159
+ # PyCharm
160
+ # JetBrains specific template is maintained in a separate JetBrains.gitignore that can
161
+ # be found at https://github.com/github/gitignore/blob/main/Global/JetBrains.gitignore
162
+ # and can be added to the global gitignore or merged into this file. For a more nuclear
163
+ # option (not recommended) you can uncomment the following to ignore the entire idea folder.
164
+ #.idea/
.pre-commit-config.yaml ADDED
@@ -0,0 +1,60 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ repos:
2
+ - repo: https://github.com/pre-commit/pre-commit-hooks
3
+ rev: v4.6.0
4
+ hooks:
5
+ - id: check-executables-have-shebangs
6
+ - id: check-json
7
+ - id: check-merge-conflict
8
+ - id: check-shebang-scripts-are-executable
9
+ - id: check-toml
10
+ - id: check-yaml
11
+ - id: end-of-file-fixer
12
+ - id: mixed-line-ending
13
+ args: ["--fix=lf"]
14
+ - id: requirements-txt-fixer
15
+ - id: trailing-whitespace
16
+ - repo: https://github.com/myint/docformatter
17
+ rev: v1.7.5
18
+ hooks:
19
+ - id: docformatter
20
+ args: ["--in-place"]
21
+ - repo: https://github.com/pycqa/isort
22
+ rev: 5.13.2
23
+ hooks:
24
+ - id: isort
25
+ args: ["--profile", "black"]
26
+ - repo: https://github.com/pre-commit/mirrors-mypy
27
+ rev: v1.9.0
28
+ hooks:
29
+ - id: mypy
30
+ args: ["--ignore-missing-imports"]
31
+ additional_dependencies:
32
+ [
33
+ "types-python-slugify",
34
+ "types-requests",
35
+ "types-PyYAML",
36
+ "types-pytz",
37
+ ]
38
+ - repo: https://github.com/psf/black
39
+ rev: 24.4.0
40
+ hooks:
41
+ - id: black
42
+ language_version: python3.10
43
+ args: ["--line-length", "119"]
44
+ - repo: https://github.com/kynan/nbstripout
45
+ rev: 0.7.1
46
+ hooks:
47
+ - id: nbstripout
48
+ args:
49
+ [
50
+ "--extra-keys",
51
+ "metadata.interpreter metadata.kernelspec cell.metadata.pycharm",
52
+ ]
53
+ - repo: https://github.com/nbQA-dev/nbQA
54
+ rev: 1.8.5
55
+ hooks:
56
+ - id: nbqa-black
57
+ - id: nbqa-pyupgrade
58
+ args: ["--py37-plus"]
59
+ - id: nbqa-isort
60
+ args: ["--float-to-top"]
.python-version ADDED
@@ -0,0 +1 @@
 
 
1
+ 3.10
.vscode/settings.json ADDED
@@ -0,0 +1,30 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ {
2
+ "editor.formatOnSave": true,
3
+ "files.insertFinalNewline": false,
4
+ "[python]": {
5
+ "editor.defaultFormatter": "ms-python.black-formatter",
6
+ "editor.formatOnType": true,
7
+ "editor.codeActionsOnSave": {
8
+ "source.organizeImports": "explicit"
9
+ }
10
+ },
11
+ "[jupyter]": {
12
+ "files.insertFinalNewline": false
13
+ },
14
+ "black-formatter.args": [
15
+ "--line-length=119"
16
+ ],
17
+ "isort.args": ["--profile", "black"],
18
+ "flake8.args": [
19
+ "--max-line-length=119"
20
+ ],
21
+ "ruff.lint.args": [
22
+ "--line-length=119"
23
+ ],
24
+ "notebook.output.scrolling": true,
25
+ "notebook.formatOnCellExecution": true,
26
+ "notebook.formatOnSave.enabled": true,
27
+ "notebook.codeActionsOnSave": {
28
+ "source.organizeImports": "explicit"
29
+ }
30
+ }
LICENSE ADDED
@@ -0,0 +1,21 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ MIT License
2
+
3
+ Copyright (c) 2023 hysts
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
LICENSE.Shap-E ADDED
@@ -0,0 +1,21 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ MIT License
2
+
3
+ Copyright (c) 2023 OpenAI
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
README.md CHANGED
@@ -1,14 +1,17 @@
1
- ---
2
- title: 3D
3
- emoji: 🖼
4
- colorFrom: purple
5
- colorTo: red
6
- sdk: gradio
7
- sdk_version: 5.0.1
8
- app_file: app.py
9
- pinned: false
10
- license: apache-2.0
11
- short_description: 3d_model_generator
12
- ---
13
-
14
- Check out the configuration reference at https://huggingface.co/docs/hub/spaces-config-reference
 
 
 
 
1
+ ---
2
+ title: Shap-E
3
+ emoji: 🧢
4
+ colorFrom: yellow
5
+ colorTo: blue
6
+ sdk: gradio
7
+ sdk_version: 5.0.2
8
+ app_file: app.py
9
+ pinned: false
10
+ license: mit
11
+ suggested_hardware: t4-small
12
+ short_description: text-to-3D & image-to-3D
13
+ ---
14
+
15
+ Check out the configuration reference at https://huggingface.co/docs/hub/spaces-config-reference
16
+
17
+ https://arxiv.org/abs/2305.02463
__pycache__/model.cpython-311.pyc ADDED
Binary file (4.23 kB). View file
 
__pycache__/settings.cpython-311.pyc ADDED
Binary file (260 Bytes). View file
 
__pycache__/utils.cpython-311.pyc ADDED
Binary file (529 Bytes). View file
 
app.py CHANGED
@@ -1,154 +1,33 @@
1
- import gradio as gr
2
- import numpy as np
3
- import random
4
-
5
- # import spaces #[uncomment to use ZeroGPU]
6
- from diffusers import DiffusionPipeline
7
- import torch
8
-
9
- device = "cuda" if torch.cuda.is_available() else "cpu"
10
- model_repo_id = "stabilityai/sdxl-turbo" # Replace to the model you would like to use
11
-
12
- if torch.cuda.is_available():
13
- torch_dtype = torch.float16
14
- else:
15
- torch_dtype = torch.float32
16
-
17
- pipe = DiffusionPipeline.from_pretrained(model_repo_id, torch_dtype=torch_dtype)
18
- pipe = pipe.to(device)
19
-
20
- MAX_SEED = np.iinfo(np.int32).max
21
- MAX_IMAGE_SIZE = 1024
22
-
23
-
24
- # @spaces.GPU #[uncomment to use ZeroGPU]
25
- def infer(
26
- prompt,
27
- negative_prompt,
28
- seed,
29
- randomize_seed,
30
- width,
31
- height,
32
- guidance_scale,
33
- num_inference_steps,
34
- progress=gr.Progress(track_tqdm=True),
35
- ):
36
- if randomize_seed:
37
- seed = random.randint(0, MAX_SEED)
38
-
39
- generator = torch.Generator().manual_seed(seed)
40
-
41
- image = pipe(
42
- prompt=prompt,
43
- negative_prompt=negative_prompt,
44
- guidance_scale=guidance_scale,
45
- num_inference_steps=num_inference_steps,
46
- width=width,
47
- height=height,
48
- generator=generator,
49
- ).images[0]
50
-
51
- return image, seed
52
-
53
-
54
- examples = [
55
- "Astronaut in a jungle, cold color palette, muted colors, detailed, 8k",
56
- "An astronaut riding a green horse",
57
- "A delicious ceviche cheesecake slice",
58
- ]
59
-
60
- css = """
61
- #col-container {
62
- margin: 0 auto;
63
- max-width: 640px;
64
- }
65
- """
66
-
67
- with gr.Blocks(css=css) as demo:
68
- with gr.Column(elem_id="col-container"):
69
- gr.Markdown(" # Text-to-Image Gradio Template")
70
-
71
- with gr.Row():
72
- prompt = gr.Text(
73
- label="Prompt",
74
- show_label=False,
75
- max_lines=1,
76
- placeholder="Enter your prompt",
77
- container=False,
78
- )
79
-
80
- run_button = gr.Button("Run", scale=0, variant="primary")
81
-
82
- result = gr.Image(label="Result", show_label=False)
83
-
84
- with gr.Accordion("Advanced Settings", open=False):
85
- negative_prompt = gr.Text(
86
- label="Negative prompt",
87
- max_lines=1,
88
- placeholder="Enter a negative prompt",
89
- visible=False,
90
- )
91
-
92
- seed = gr.Slider(
93
- label="Seed",
94
- minimum=0,
95
- maximum=MAX_SEED,
96
- step=1,
97
- value=0,
98
- )
99
-
100
- randomize_seed = gr.Checkbox(label="Randomize seed", value=True)
101
-
102
- with gr.Row():
103
- width = gr.Slider(
104
- label="Width",
105
- minimum=256,
106
- maximum=MAX_IMAGE_SIZE,
107
- step=32,
108
- value=1024, # Replace with defaults that work for your model
109
- )
110
-
111
- height = gr.Slider(
112
- label="Height",
113
- minimum=256,
114
- maximum=MAX_IMAGE_SIZE,
115
- step=32,
116
- value=1024, # Replace with defaults that work for your model
117
- )
118
-
119
- with gr.Row():
120
- guidance_scale = gr.Slider(
121
- label="Guidance scale",
122
- minimum=0.0,
123
- maximum=10.0,
124
- step=0.1,
125
- value=0.0, # Replace with defaults that work for your model
126
- )
127
-
128
- num_inference_steps = gr.Slider(
129
- label="Number of inference steps",
130
- minimum=1,
131
- maximum=50,
132
- step=1,
133
- value=2, # Replace with defaults that work for your model
134
- )
135
-
136
- gr.Examples(examples=examples, inputs=[prompt])
137
- gr.on(
138
- triggers=[run_button.click, prompt.submit],
139
- fn=infer,
140
- inputs=[
141
- prompt,
142
- negative_prompt,
143
- seed,
144
- randomize_seed,
145
- width,
146
- height,
147
- guidance_scale,
148
- num_inference_steps,
149
- ],
150
- outputs=[result, seed],
151
- )
152
-
153
- if __name__ == "__main__":
154
- demo.launch()
 
1
+ #!/usr/bin/env python
2
+
3
+ import os
4
+
5
+ import gradio as gr
6
+ import torch
7
+
8
+ from app_image_to_3d import create_demo as create_demo_image_to_3d
9
+ from app_text_to_3d import create_demo as create_demo_text_to_3d
10
+ from model import Model
11
+
12
+ DESCRIPTION = "# [Shap-E](https://github.com/openai/shap-e)"
13
+
14
+ if not torch.cuda.is_available():
15
+ DESCRIPTION += "\n<p>Running on CPU 🥶 This demo does not work on CPU.</p>"
16
+
17
+ model = Model()
18
+
19
+ with gr.Blocks(css_paths="style.css") as demo:
20
+ gr.Markdown(DESCRIPTION)
21
+ gr.DuplicateButton(
22
+ value="Duplicate Space for private use",
23
+ elem_id="duplicate-button",
24
+ visible=os.getenv("SHOW_DUPLICATE_BUTTON") == "1",
25
+ )
26
+ with gr.Tabs():
27
+ with gr.Tab(label="Text to 3D"):
28
+ create_demo_text_to_3d(model)
29
+ with gr.Tab(label="Image to 3D"):
30
+ create_demo_image_to_3d(model)
31
+
32
+ if __name__ == "__main__":
33
+ demo.queue(max_size=10).launch()
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
app_image_to_3d.py ADDED
@@ -0,0 +1,88 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ #!/usr/bin/env python
2
+
3
+ import pathlib
4
+ import shlex
5
+ import subprocess
6
+
7
+ import gradio as gr
8
+ import PIL.Image
9
+ import spaces
10
+
11
+ from model import Model
12
+ from settings import MAX_SEED
13
+ from utils import randomize_seed_fn
14
+
15
+
16
+ def create_demo(model: Model) -> gr.Blocks:
17
+ if not pathlib.Path("corgi.png").exists():
18
+ subprocess.run(
19
+ shlex.split(
20
+ "wget https://raw.githubusercontent.com/openai/shap-e/d99cedaea18e0989e340163dbaeb4b109fa9e8ec/shap_e/examples/example_data/corgi.png -O corgi.png"
21
+ )
22
+ )
23
+ examples = ["corgi.png"]
24
+
25
+ @spaces.GPU
26
+ def process_example_fn(image_path: str) -> str:
27
+ return model.run_image(image_path)
28
+
29
+ @spaces.GPU
30
+ def run(image: PIL.Image.Image, seed: int, guidance_scale: float, num_inference_steps: int) -> str:
31
+ return model.run_image(image, seed, guidance_scale, num_inference_steps)
32
+
33
+ with gr.Blocks() as demo:
34
+ with gr.Group():
35
+ image = gr.Image(label="Input image", show_label=False, type="pil")
36
+ run_button = gr.Button("Run")
37
+ result = gr.Model3D(label="Result", show_label=False)
38
+ with gr.Accordion("Advanced options", open=False):
39
+ seed = gr.Slider(
40
+ label="Seed",
41
+ minimum=0,
42
+ maximum=MAX_SEED,
43
+ step=1,
44
+ value=0,
45
+ )
46
+ randomize_seed = gr.Checkbox(label="Randomize seed", value=True)
47
+ guidance_scale = gr.Slider(
48
+ label="Guidance scale",
49
+ minimum=1,
50
+ maximum=20,
51
+ step=0.1,
52
+ value=3.0,
53
+ )
54
+ num_inference_steps = gr.Slider(
55
+ label="Number of inference steps",
56
+ minimum=2,
57
+ maximum=100,
58
+ step=1,
59
+ value=64,
60
+ )
61
+
62
+ gr.Examples(
63
+ examples=examples,
64
+ inputs=image,
65
+ outputs=result,
66
+ fn=process_example_fn,
67
+ )
68
+
69
+ run_button.click(
70
+ fn=randomize_seed_fn,
71
+ inputs=[seed, randomize_seed],
72
+ outputs=seed,
73
+ api_name=False,
74
+ concurrency_limit=None,
75
+ ).then(
76
+ fn=run,
77
+ inputs=[
78
+ image,
79
+ seed,
80
+ guidance_scale,
81
+ num_inference_steps,
82
+ ],
83
+ outputs=result,
84
+ api_name="image-to-3d",
85
+ concurrency_id="gpu",
86
+ concurrency_limit=1,
87
+ )
88
+ return demo
app_text_to_3d.py ADDED
@@ -0,0 +1,93 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ #!/usr/bin/env python
2
+
3
+ import gradio as gr
4
+ import spaces
5
+
6
+ from model import Model
7
+ from settings import MAX_SEED
8
+ from utils import randomize_seed_fn
9
+
10
+
11
+ def create_demo(model: Model) -> gr.Blocks:
12
+ examples = [
13
+ "A chair that looks like an avocado",
14
+ "An airplane that looks like a banana",
15
+ "A spaceship",
16
+ "A birthday cupcake",
17
+ "A chair that looks like a tree",
18
+ "A green boot",
19
+ "A penguin",
20
+ "Ube ice cream cone",
21
+ "A bowl of vegetables",
22
+ ]
23
+
24
+ @spaces.GPU
25
+ def process_example_fn(prompt: str) -> str:
26
+ return model.run_text(prompt)
27
+
28
+ @spaces.GPU
29
+ def run(prompt: str, seed: int, guidance_scale: float, num_inference_steps: int) -> str:
30
+ return model.run_text(prompt, seed, guidance_scale, num_inference_steps)
31
+
32
+ with gr.Blocks() as demo:
33
+ with gr.Group():
34
+ with gr.Row(elem_id="prompt-container"):
35
+ prompt = gr.Text(
36
+ label="Prompt",
37
+ show_label=False,
38
+ max_lines=1,
39
+ placeholder="Enter your prompt",
40
+ submit_btn=True,
41
+ )
42
+ result = gr.Model3D(label="Result", show_label=False)
43
+ with gr.Accordion("Advanced options", open=False):
44
+ seed = gr.Slider(
45
+ label="Seed",
46
+ minimum=0,
47
+ maximum=MAX_SEED,
48
+ step=1,
49
+ value=0,
50
+ )
51
+ randomize_seed = gr.Checkbox(label="Randomize seed", value=True)
52
+ guidance_scale = gr.Slider(
53
+ label="Guidance scale",
54
+ minimum=1,
55
+ maximum=20,
56
+ step=0.1,
57
+ value=15.0,
58
+ )
59
+ num_inference_steps = gr.Slider(
60
+ label="Number of inference steps",
61
+ minimum=2,
62
+ maximum=100,
63
+ step=1,
64
+ value=64,
65
+ )
66
+
67
+ gr.Examples(
68
+ examples=examples,
69
+ inputs=prompt,
70
+ outputs=result,
71
+ fn=process_example_fn,
72
+ )
73
+
74
+ prompt.submit(
75
+ fn=randomize_seed_fn,
76
+ inputs=[seed, randomize_seed],
77
+ outputs=seed,
78
+ api_name=False,
79
+ concurrency_limit=None,
80
+ ).then(
81
+ fn=run,
82
+ inputs=[
83
+ prompt,
84
+ seed,
85
+ guidance_scale,
86
+ num_inference_steps,
87
+ ],
88
+ outputs=result,
89
+ api_name="text-to-3d",
90
+ concurrency_id="gpu",
91
+ concurrency_limit=1,
92
+ )
93
+ return demo
model.py ADDED
@@ -0,0 +1,56 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import tempfile
2
+
3
+ import numpy as np
4
+ import PIL.Image
5
+ import torch
6
+ import trimesh
7
+ from diffusers import ShapEImg2ImgPipeline, ShapEPipeline
8
+ from diffusers.utils import export_to_ply
9
+
10
+
11
+ class Model:
12
+ def __init__(self):
13
+ self.device = torch.device("cuda" if torch.cuda.is_available() else "cpu")
14
+ self.pipe = ShapEPipeline.from_pretrained("openai/shap-e", torch_dtype=torch.float16)
15
+ self.pipe.to(self.device)
16
+
17
+ self.pipe_img = ShapEImg2ImgPipeline.from_pretrained("openai/shap-e-img2img", torch_dtype=torch.float16)
18
+ self.pipe_img.to(self.device)
19
+
20
+ def to_glb(self, ply_path: str) -> str:
21
+ mesh = trimesh.load(ply_path)
22
+ rot = trimesh.transformations.rotation_matrix(-np.pi / 2, [1, 0, 0])
23
+ mesh = mesh.apply_transform(rot)
24
+ rot = trimesh.transformations.rotation_matrix(np.pi, [0, 1, 0])
25
+ mesh = mesh.apply_transform(rot)
26
+ mesh_path = tempfile.NamedTemporaryFile(suffix=".glb", delete=False)
27
+ mesh.export(mesh_path.name, file_type="glb")
28
+ return mesh_path.name
29
+
30
+ def run_text(self, prompt: str, seed: int = 0, guidance_scale: float = 15.0, num_steps: int = 64) -> str:
31
+ generator = torch.Generator(device=self.device).manual_seed(seed)
32
+ images = self.pipe(
33
+ prompt,
34
+ generator=generator,
35
+ guidance_scale=guidance_scale,
36
+ num_inference_steps=num_steps,
37
+ output_type="mesh",
38
+ ).images
39
+ ply_path = tempfile.NamedTemporaryFile(suffix=".ply", delete=False, mode="w+b")
40
+ export_to_ply(images[0], ply_path.name)
41
+ return self.to_glb(ply_path.name)
42
+
43
+ def run_image(
44
+ self, image: PIL.Image.Image, seed: int = 0, guidance_scale: float = 3.0, num_steps: int = 64
45
+ ) -> str:
46
+ generator = torch.Generator(device=self.device).manual_seed(seed)
47
+ images = self.pipe_img(
48
+ image,
49
+ generator=generator,
50
+ guidance_scale=guidance_scale,
51
+ num_inference_steps=num_steps,
52
+ output_type="mesh",
53
+ ).images
54
+ ply_path = tempfile.NamedTemporaryFile(suffix=".ply", delete=False, mode="w+b")
55
+ export_to_ply(images[0], ply_path.name)
56
+ return self.to_glb(ply_path.name)
pyproject.toml ADDED
@@ -0,0 +1,16 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ [project]
2
+ name = "shap-e"
3
+ version = "0.1.0"
4
+ description = ""
5
+ readme = "README.md"
6
+ requires-python = ">=3.10"
7
+ dependencies = [
8
+ "accelerate>=1.0.0",
9
+ "diffusers>=0.30.3",
10
+ "gradio==5.0.2",
11
+ "spaces>=0.30.3",
12
+ "torch==2.4.0",
13
+ "torchvision>=0.19.0",
14
+ "transformers>=4.45.2",
15
+ "trimesh>=4.4.9",
16
+ ]
requirements.txt CHANGED
@@ -1,6 +1,258 @@
1
- accelerate
2
- diffusers
3
- invisible_watermark
4
- torch
5
- transformers
6
- xformers
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ # This file was autogenerated by uv via the following command:
2
+ # uv pip compile pyproject.toml -o requirements.txt
3
+ accelerate==1.0.0
4
+ # via shap-e (pyproject.toml)
5
+ aiofiles==23.2.1
6
+ # via gradio
7
+ annotated-types==0.7.0
8
+ # via pydantic
9
+ anyio==4.6.0
10
+ # via
11
+ # gradio
12
+ # httpx
13
+ # starlette
14
+ certifi==2024.8.30
15
+ # via
16
+ # httpcore
17
+ # httpx
18
+ # requests
19
+ charset-normalizer==3.4.0
20
+ # via requests
21
+ click==8.1.7
22
+ # via
23
+ # typer
24
+ # uvicorn
25
+ diffusers==0.30.3
26
+ # via shap-e (pyproject.toml)
27
+ exceptiongroup==1.2.2
28
+ # via anyio
29
+ fastapi==0.115.0
30
+ # via gradio
31
+ ffmpy==0.4.0
32
+ # via gradio
33
+ filelock==3.16.1
34
+ # via
35
+ # diffusers
36
+ # huggingface-hub
37
+ # torch
38
+ # transformers
39
+ # triton
40
+ fsspec==2024.9.0
41
+ # via
42
+ # gradio-client
43
+ # huggingface-hub
44
+ # torch
45
+ gradio==5.0.2
46
+ # via
47
+ # shap-e (pyproject.toml)
48
+ # spaces
49
+ gradio-client==1.4.0
50
+ # via gradio
51
+ h11==0.14.0
52
+ # via
53
+ # httpcore
54
+ # uvicorn
55
+ httpcore==1.0.6
56
+ # via httpx
57
+ httpx==0.27.2
58
+ # via
59
+ # gradio
60
+ # gradio-client
61
+ # spaces
62
+ huggingface-hub==0.25.2
63
+ # via
64
+ # accelerate
65
+ # diffusers
66
+ # gradio
67
+ # gradio-client
68
+ # tokenizers
69
+ # transformers
70
+ idna==3.10
71
+ # via
72
+ # anyio
73
+ # httpx
74
+ # requests
75
+ importlib-metadata==8.5.0
76
+ # via diffusers
77
+ jinja2==3.1.4
78
+ # via
79
+ # gradio
80
+ # torch
81
+ markdown-it-py==3.0.0
82
+ # via rich
83
+ markupsafe==2.1.5
84
+ # via
85
+ # gradio
86
+ # jinja2
87
+ mdurl==0.1.2
88
+ # via markdown-it-py
89
+ mpmath==1.3.0
90
+ # via sympy
91
+ networkx==3.3
92
+ # via torch
93
+ numpy==1.26.4
94
+ # via
95
+ # accelerate
96
+ # diffusers
97
+ # gradio
98
+ # pandas
99
+ # torchvision
100
+ # transformers
101
+ # trimesh
102
+ nvidia-cublas-cu12==12.1.3.1
103
+ # via
104
+ # nvidia-cudnn-cu12
105
+ # nvidia-cusolver-cu12
106
+ # torch
107
+ nvidia-cuda-cupti-cu12==12.1.105
108
+ # via torch
109
+ nvidia-cuda-nvrtc-cu12==12.1.105
110
+ # via torch
111
+ nvidia-cuda-runtime-cu12==12.1.105
112
+ # via torch
113
+ nvidia-cudnn-cu12==9.1.0.70
114
+ # via torch
115
+ nvidia-cufft-cu12==11.0.2.54
116
+ # via torch
117
+ nvidia-curand-cu12==10.3.2.106
118
+ # via torch
119
+ nvidia-cusolver-cu12==11.4.5.107
120
+ # via torch
121
+ nvidia-cusparse-cu12==12.1.0.106
122
+ # via
123
+ # nvidia-cusolver-cu12
124
+ # torch
125
+ nvidia-nccl-cu12==2.20.5
126
+ # via torch
127
+ nvidia-nvjitlink-cu12==12.6.77
128
+ # via
129
+ # nvidia-cusolver-cu12
130
+ # nvidia-cusparse-cu12
131
+ nvidia-nvtx-cu12==12.1.105
132
+ # via torch
133
+ orjson==3.10.7
134
+ # via gradio
135
+ packaging==24.1
136
+ # via
137
+ # accelerate
138
+ # gradio
139
+ # gradio-client
140
+ # huggingface-hub
141
+ # spaces
142
+ # transformers
143
+ pandas==2.2.3
144
+ # via gradio
145
+ pillow==10.4.0
146
+ # via
147
+ # diffusers
148
+ # gradio
149
+ # torchvision
150
+ psutil==5.9.8
151
+ # via
152
+ # accelerate
153
+ # spaces
154
+ pydantic==2.9.2
155
+ # via
156
+ # fastapi
157
+ # gradio
158
+ # spaces
159
+ pydantic-core==2.23.4
160
+ # via pydantic
161
+ pydub==0.25.1
162
+ # via gradio
163
+ pygments==2.18.0
164
+ # via rich
165
+ python-dateutil==2.9.0.post0
166
+ # via pandas
167
+ python-multipart==0.0.12
168
+ # via gradio
169
+ pytz==2024.2
170
+ # via pandas
171
+ pyyaml==6.0.2
172
+ # via
173
+ # accelerate
174
+ # gradio
175
+ # huggingface-hub
176
+ # transformers
177
+ regex==2024.9.11
178
+ # via
179
+ # diffusers
180
+ # transformers
181
+ requests==2.32.3
182
+ # via
183
+ # diffusers
184
+ # huggingface-hub
185
+ # spaces
186
+ # transformers
187
+ rich==13.9.2
188
+ # via typer
189
+ ruff==0.6.9
190
+ # via gradio
191
+ safetensors==0.4.5
192
+ # via
193
+ # accelerate
194
+ # diffusers
195
+ # transformers
196
+ semantic-version==2.10.0
197
+ # via gradio
198
+ shellingham==1.5.4
199
+ # via typer
200
+ six==1.16.0
201
+ # via python-dateutil
202
+ sniffio==1.3.1
203
+ # via
204
+ # anyio
205
+ # httpx
206
+ spaces==0.30.3
207
+ # via shap-e (pyproject.toml)
208
+ starlette==0.38.6
209
+ # via fastapi
210
+ sympy==1.13.3
211
+ # via torch
212
+ tokenizers==0.20.0
213
+ # via transformers
214
+ tomlkit==0.12.0
215
+ # via gradio
216
+ torch==2.4.0
217
+ # via
218
+ # shap-e (pyproject.toml)
219
+ # accelerate
220
+ # torchvision
221
+ torchvision==0.19.0
222
+ # via shap-e (pyproject.toml)
223
+ tqdm==4.66.5
224
+ # via
225
+ # huggingface-hub
226
+ # transformers
227
+ transformers==4.45.2
228
+ # via shap-e (pyproject.toml)
229
+ trimesh==4.4.9
230
+ # via shap-e (pyproject.toml)
231
+ triton==3.0.0
232
+ # via torch
233
+ typer==0.12.5
234
+ # via gradio
235
+ typing-extensions==4.12.2
236
+ # via
237
+ # anyio
238
+ # fastapi
239
+ # gradio
240
+ # gradio-client
241
+ # huggingface-hub
242
+ # pydantic
243
+ # pydantic-core
244
+ # rich
245
+ # spaces
246
+ # torch
247
+ # typer
248
+ # uvicorn
249
+ tzdata==2024.2
250
+ # via pandas
251
+ urllib3==2.2.3
252
+ # via requests
253
+ uvicorn==0.31.0
254
+ # via gradio
255
+ websockets==12.0
256
+ # via gradio-client
257
+ zipp==3.20.2
258
+ # via importlib-metadata
settings.py ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ import numpy as np
2
+
3
+ MAX_SEED = np.iinfo(np.int32).max
style.css ADDED
@@ -0,0 +1,22 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ h1 {
2
+ text-align: center;
3
+ display: block;
4
+ }
5
+
6
+ .contain {
7
+ max-width: 730px;
8
+ min-width: 400px;
9
+ margin: auto;
10
+ padding-top: 1.5rem;
11
+ }
12
+
13
+ #prompt-container {
14
+ gap: 0;
15
+ }
16
+
17
+ #duplicate-button {
18
+ margin: auto;
19
+ color: #fff;
20
+ background: #1565c0;
21
+ border-radius: 100vh;
22
+ }
utils.py ADDED
@@ -0,0 +1,9 @@
 
 
 
 
 
 
 
 
 
 
1
+ import random
2
+
3
+ from settings import MAX_SEED
4
+
5
+
6
+ def randomize_seed_fn(seed: int, randomize_seed: bool) -> int:
7
+ if randomize_seed:
8
+ seed = random.randint(0, MAX_SEED)
9
+ return seed
uv.lock ADDED
The diff for this file is too large to render. See raw diff