Spaces:
Starting
Starting
Update gradio_app.py
Browse files- gradio_app.py +29 -24
gradio_app.py
CHANGED
|
@@ -137,11 +137,14 @@ def forward_model(batch, system, guidance_scale=3.0, seed=0, device="cuda"):
|
|
| 137 |
|
| 138 |
return pc_cond
|
| 139 |
|
| 140 |
-
def generate_and_process_3d(prompt: str
|
| 141 |
"""Generate image from prompt and convert to 3D model."""
|
| 142 |
|
| 143 |
width: int = 1024
|
| 144 |
height: int = 1024
|
|
|
|
|
|
|
|
|
|
| 145 |
|
| 146 |
try:
|
| 147 |
# Set random seeds
|
|
@@ -219,32 +222,34 @@ def generate_and_process_3d(prompt: str, seed: int = 42) -> tuple[str | None, Im
|
|
| 219 |
import traceback
|
| 220 |
traceback.print_exc()
|
| 221 |
return None
|
| 222 |
-
|
| 223 |
-
# Create Gradio
|
| 224 |
-
|
| 225 |
-
|
| 226 |
-
|
| 227 |
-
|
|
|
|
|
|
|
| 228 |
label="Enter your prompt",
|
| 229 |
-
placeholder="
|
| 230 |
-
),
|
| 231 |
-
gr.Slider(
|
| 232 |
-
label="Seed",
|
| 233 |
-
minimum=0,
|
| 234 |
-
maximum=np.iinfo(np.int32).max,
|
| 235 |
-
step=1,
|
| 236 |
-
value=42
|
| 237 |
)
|
| 238 |
-
|
| 239 |
-
|
| 240 |
-
gr.
|
| 241 |
-
|
|
|
|
|
|
|
|
|
|
| 242 |
clear_color=[0.0, 0.0, 0.0, 0.0],
|
| 243 |
)
|
| 244 |
-
|
| 245 |
-
|
| 246 |
-
|
| 247 |
-
|
| 248 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
| 249 |
if __name__ == "__main__":
|
| 250 |
demo.queue().launch()
|
|
|
|
| 137 |
|
| 138 |
return pc_cond
|
| 139 |
|
| 140 |
+
def generate_and_process_3d(prompt: str) -> tuple[str | None, Image.Image | None]:
|
| 141 |
"""Generate image from prompt and convert to 3D model."""
|
| 142 |
|
| 143 |
width: int = 1024
|
| 144 |
height: int = 1024
|
| 145 |
+
|
| 146 |
+
# Generate random seed
|
| 147 |
+
seed = np.random.randint(0, np.iinfo(np.int32).max)
|
| 148 |
|
| 149 |
try:
|
| 150 |
# Set random seeds
|
|
|
|
| 222 |
import traceback
|
| 223 |
traceback.print_exc()
|
| 224 |
return None
|
| 225 |
+
|
| 226 |
+
# Create Gradio app using Blocks
|
| 227 |
+
with gr.Blocks() as demo:
|
| 228 |
+
gr.Markdown("# Text to 3D")
|
| 229 |
+
gr.Markdown("This space is base on Stable Point-Awaire 3D by Stability AI.")
|
| 230 |
+
|
| 231 |
+
with gr.Row():
|
| 232 |
+
prompt_input = gr.Text(
|
| 233 |
label="Enter your prompt",
|
| 234 |
+
placeholder="eg. isometric 3D game castle"
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 235 |
)
|
| 236 |
+
|
| 237 |
+
with gr.Row():
|
| 238 |
+
generate_btn = gr.Button("Generate", variant="primary")
|
| 239 |
+
|
| 240 |
+
with gr.Row():
|
| 241 |
+
model_output = gr.Model3D(
|
| 242 |
+
label="Generated .GLB model",
|
| 243 |
clear_color=[0.0, 0.0, 0.0, 0.0],
|
| 244 |
)
|
| 245 |
+
|
| 246 |
+
# Event handler
|
| 247 |
+
generate_btn.click(
|
| 248 |
+
fn=generate_and_process_3d,
|
| 249 |
+
inputs=[prompt_input],
|
| 250 |
+
outputs=[model_output],
|
| 251 |
+
api_name="generate"
|
| 252 |
+
)
|
| 253 |
+
|
| 254 |
if __name__ == "__main__":
|
| 255 |
demo.queue().launch()
|