Spaces:
Running
Running
Upload 3 files
Browse files- README.md +19 -12
- gradio_app.py +59 -0
- requirements.txt +1 -0
README.md
CHANGED
@@ -1,12 +1,19 @@
|
|
1 |
-
---
|
2 |
-
title: Image
|
3 |
-
emoji:
|
4 |
-
colorFrom:
|
5 |
-
colorTo:
|
6 |
-
sdk: gradio
|
7 |
-
sdk_version: 5.
|
8 |
-
app_file:
|
9 |
-
pinned: false
|
10 |
-
---
|
11 |
-
|
12 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
---
|
2 |
+
title: Image to 3D
|
3 |
+
emoji: ⚡
|
4 |
+
colorFrom: yellow
|
5 |
+
colorTo: yellow
|
6 |
+
sdk: gradio
|
7 |
+
sdk_version: 5.15.0
|
8 |
+
app_file: gradio_app.py
|
9 |
+
pinned: false
|
10 |
+
---
|
11 |
+
|
12 |
+
This space is a variant of [Stable Point-Aware 3D](https://huggingface.co/spaces/stabilityai/stable-point-aware-3d), but using text as input.
|
13 |
+
|
14 |
+
* **Repository**: [https://github.com/Stability-AI/stable-point-aware-3d](https://github.com/Stability-AI/stable-point-aware-3d)
|
15 |
+
* **Model**: [https://huggingface.co/stabilityai/stable-point-aware-3d](https://huggingface.co/stabilityai/stable-point-aware-3d)
|
16 |
+
* **Tech report**: [https://arxiv.org/pdf/2501.04689](https://arxiv.org/pdf/2501.04689)
|
17 |
+
* **Video summary**: [https://youtu.be/mlO3Nc3Nsng](https://youtu.be/mlO3Nc3Nsng)
|
18 |
+
* **Project page**: [https://spar3d.github.io](https://spar3d.github.io)
|
19 |
+
* **arXiv page**: [https://arxiv.org/abs/2501.04689](https://arxiv.org/abs/2501.04689)
|
gradio_app.py
ADDED
@@ -0,0 +1,59 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
import spaces
|
2 |
+
import os
|
3 |
+
from PIL import Image
|
4 |
+
import gradio as gr
|
5 |
+
from pathlib import Path
|
6 |
+
import uuid
|
7 |
+
import torch
|
8 |
+
import shutil
|
9 |
+
|
10 |
+
OUTPUT_DIR = "output"
|
11 |
+
|
12 |
+
@spaces.GPU
|
13 |
+
@torch.inference_mode()
|
14 |
+
def generate_and_process_3d(image: Image.Image) -> tuple[str | None, Image.Image | None]:
|
15 |
+
try:
|
16 |
+
# Export to GLB
|
17 |
+
unique_id = str(uuid.uuid4())
|
18 |
+
filename = f'model_{unique_id}.glb'
|
19 |
+
output_path = os.path.join(OUTPUT_DIR, filename)
|
20 |
+
public_url = f"https://john6666-image-to-3d-test2.hf.space/file={output_path}"
|
21 |
+
image_path = "image.png"
|
22 |
+
image.save(image_path)
|
23 |
+
shutil.copy(image_path, output_path)
|
24 |
+
|
25 |
+
return output_path, public_url
|
26 |
+
|
27 |
+
except Exception as e:
|
28 |
+
print(f"Error during generation: {str(e)}")
|
29 |
+
import traceback
|
30 |
+
traceback.print_exc()
|
31 |
+
return None
|
32 |
+
|
33 |
+
# Create Gradio app using Blocks
|
34 |
+
with gr.Blocks() as demo:
|
35 |
+
gr.Markdown("This space is based on [Stable Point-Aware 3D](https://huggingface.co/spaces/stabilityai/stable-point-aware-3d) by Stability AI, [Text to 3D](https://huggingface.co/spaces/jbilcke-hf/text-to-3d) by jbilcke-hf.")
|
36 |
+
|
37 |
+
with gr.Row():
|
38 |
+
input_img = gr.Image(
|
39 |
+
type="pil", label="Input Image", sources="upload", image_mode="RGBA"
|
40 |
+
)
|
41 |
+
|
42 |
+
with gr.Row():
|
43 |
+
model_output = gr.Model3D(
|
44 |
+
label="Generated .GLB model",
|
45 |
+
clear_color=[0.0, 0.0, 0.0, 0.0],
|
46 |
+
visible=False
|
47 |
+
)
|
48 |
+
output_url = gr.Textbox(label="Output URL", value="", lines=1, interactive=False)
|
49 |
+
|
50 |
+
# Event handler
|
51 |
+
input_img.upload(
|
52 |
+
fn=generate_and_process_3d,
|
53 |
+
inputs=[input_img],
|
54 |
+
outputs=[model_output, output_url],
|
55 |
+
api_name="generate"
|
56 |
+
)
|
57 |
+
|
58 |
+
if __name__ == "__main__":
|
59 |
+
demo.queue().launch(ssr_mode=False, allowed_paths=[Path(OUTPUT_DIR).resolve()])
|
requirements.txt
ADDED
@@ -0,0 +1 @@
|
|
|
|
|
1 |
+
huggingface-hub>=0.27.0
|