Spaces:
Running
on
Zero
Running
on
Zero
Update app.py
Browse files
app.py
CHANGED
|
@@ -35,6 +35,17 @@ import cv2
|
|
| 35 |
import os
|
| 36 |
import random
|
| 37 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 38 |
MAX_SEED = np.iinfo(np.int32).max
|
| 39 |
TMP_DIR = os.path.join(os.path.dirname(os.path.abspath(__file__)), 'tmp')
|
| 40 |
os.makedirs(TMP_DIR, exist_ok=True)
|
|
@@ -68,6 +79,7 @@ def end_session(req: gr.Request):
|
|
| 68 |
|
| 69 |
def preprocess_image(image: Image.Image,
|
| 70 |
prompt: str,
|
|
|
|
| 71 |
num_steps: int = 25,
|
| 72 |
guidance_scale: float = 5,
|
| 73 |
controlnet_conditioning_scale: float = 1.0,) -> Image.Image:
|
|
@@ -309,7 +321,7 @@ def split_image(image: Image.Image) -> List[Image.Image]:
|
|
| 309 |
return [preprocess_image(image) for image in images]
|
| 310 |
|
| 311 |
|
| 312 |
-
with gr.Blocks(delete_cache=(600, 600)) as demo:
|
| 313 |
gr.Markdown("""
|
| 314 |
## Image to 3D Asset with [TRELLIS](https://trellis3d.github.io/)
|
| 315 |
* Upload an image and click "Generate" to create a 3D asset. If the image has alpha channel, it be used as the mask. Otherwise, we use `rembg` to remove the background.
|
|
@@ -324,7 +336,9 @@ with gr.Blocks(delete_cache=(600, 600)) as demo:
|
|
| 324 |
with gr.Tab(label="Single Image", id=0) as single_image_input_tab:
|
| 325 |
#image_prompt = gr.Image(label="Image Prompt", format="png", image_mode="RGBA", type="pil", height=300)
|
| 326 |
image_prompt = image = gr.ImageEditor(type="pil", image_mode="L", crop_size=(512, 512))
|
| 327 |
-
|
|
|
|
|
|
|
| 328 |
with gr.Tab(label="Multiple Images", id=1) as multiimage_input_tab:
|
| 329 |
multiimage_prompt = gr.Gallery(label="Image Prompt", format="png", type="pil", height=300, columns=3)
|
| 330 |
gr.Markdown("""
|
|
@@ -408,7 +422,7 @@ with gr.Blocks(delete_cache=(600, 600)) as demo:
|
|
| 408 |
|
| 409 |
image_prompt.upload(
|
| 410 |
preprocess_image,
|
| 411 |
-
inputs=[image_prompt, prompt],
|
| 412 |
outputs=[image_prompt],
|
| 413 |
)
|
| 414 |
multiimage_prompt.upload(
|
|
|
|
| 35 |
import os
|
| 36 |
import random
|
| 37 |
|
| 38 |
+
js_func = """
|
| 39 |
+
function refresh() {
|
| 40 |
+
const url = new URL(window.location);
|
| 41 |
+
|
| 42 |
+
if (url.searchParams.get('__theme') !== 'dark') {
|
| 43 |
+
url.searchParams.set('__theme', 'dark');
|
| 44 |
+
window.location.href = url.href;
|
| 45 |
+
}
|
| 46 |
+
}
|
| 47 |
+
"""
|
| 48 |
+
|
| 49 |
MAX_SEED = np.iinfo(np.int32).max
|
| 50 |
TMP_DIR = os.path.join(os.path.dirname(os.path.abspath(__file__)), 'tmp')
|
| 51 |
os.makedirs(TMP_DIR, exist_ok=True)
|
|
|
|
| 79 |
|
| 80 |
def preprocess_image(image: Image.Image,
|
| 81 |
prompt: str,
|
| 82 |
+
negative_prompt: str = "",
|
| 83 |
num_steps: int = 25,
|
| 84 |
guidance_scale: float = 5,
|
| 85 |
controlnet_conditioning_scale: float = 1.0,) -> Image.Image:
|
|
|
|
| 321 |
return [preprocess_image(image) for image in images]
|
| 322 |
|
| 323 |
|
| 324 |
+
with gr.Blocks(delete_cache=(600, 600), js=js_func) as demo:
|
| 325 |
gr.Markdown("""
|
| 326 |
## Image to 3D Asset with [TRELLIS](https://trellis3d.github.io/)
|
| 327 |
* Upload an image and click "Generate" to create a 3D asset. If the image has alpha channel, it be used as the mask. Otherwise, we use `rembg` to remove the background.
|
|
|
|
| 336 |
with gr.Tab(label="Single Image", id=0) as single_image_input_tab:
|
| 337 |
#image_prompt = gr.Image(label="Image Prompt", format="png", image_mode="RGBA", type="pil", height=300)
|
| 338 |
image_prompt = image = gr.ImageEditor(type="pil", image_mode="L", crop_size=(512, 512))
|
| 339 |
+
with gr.Row():
|
| 340 |
+
prompt = gr.Textbox(label="Prompt")
|
| 341 |
+
#negative_prompt = gr.Textbox(label="Negative prompt")
|
| 342 |
with gr.Tab(label="Multiple Images", id=1) as multiimage_input_tab:
|
| 343 |
multiimage_prompt = gr.Gallery(label="Image Prompt", format="png", type="pil", height=300, columns=3)
|
| 344 |
gr.Markdown("""
|
|
|
|
| 422 |
|
| 423 |
image_prompt.upload(
|
| 424 |
preprocess_image,
|
| 425 |
+
inputs=[image_prompt, prompt, negative_prompt],
|
| 426 |
outputs=[image_prompt],
|
| 427 |
)
|
| 428 |
multiimage_prompt.upload(
|