Spaces:
Running
on
Zero
Running
on
Zero
Update app.py
Browse files
app.py
CHANGED
@@ -4,7 +4,6 @@ from gradio_pannellum import Pannellum
|
|
4 |
import torch
|
5 |
from huggingface_hub import snapshot_download
|
6 |
from txt2panoimg import Text2360PanoramaImagePipeline
|
7 |
-
from img2panoimg import Image2360PanoramaImagePipeline
|
8 |
from PIL import Image
|
9 |
|
10 |
# Download the model
|
@@ -12,10 +11,6 @@ model_path = snapshot_download("archerfmy0831/sd-t2i-360panoimage")
|
|
12 |
|
13 |
# Initialize pipelines
|
14 |
txt2panoimg = Text2360PanoramaImagePipeline(model_path, torch_dtype=torch.float16)
|
15 |
-
img2panoimg = Image2360PanoramaImagePipeline(model_path, torch_dtype=torch.float16)
|
16 |
-
|
17 |
-
# Load the default mask image
|
18 |
-
default_mask = Image.open("i2p-mask.jpg").convert("RGB")
|
19 |
|
20 |
@spaces.GPU(duration=200)
|
21 |
def text_to_pano(prompt, upscale):
|
@@ -23,55 +18,21 @@ def text_to_pano(prompt, upscale):
|
|
23 |
output = txt2panoimg(input_data)
|
24 |
return output
|
25 |
|
26 |
-
|
27 |
-
def image_to_pano(image, mask, prompt, upscale):
|
28 |
-
image = image.resize((512, 512))
|
29 |
-
if mask is None:
|
30 |
-
mask = default_mask.resize((512, 512))
|
31 |
-
else:
|
32 |
-
mask = mask.resize((512, 512))
|
33 |
-
input_data = {
|
34 |
-
'prompt': prompt,
|
35 |
-
'image': image,
|
36 |
-
'mask': mask,
|
37 |
-
'upscale': upscale
|
38 |
-
}
|
39 |
-
output = img2panoimg(input_data)
|
40 |
-
return output
|
41 |
-
|
42 |
-
with gr.Blocks() as demo:
|
43 |
gr.Markdown("# 360° Panorama Image Generation")
|
44 |
|
45 |
-
with gr.
|
46 |
-
with gr.
|
47 |
-
|
48 |
-
|
49 |
-
|
50 |
-
|
51 |
-
|
52 |
-
|
53 |
-
|
54 |
-
|
55 |
-
|
56 |
-
|
57 |
-
|
58 |
-
)
|
59 |
-
|
60 |
-
with gr.Tab("Image to 360° Panorama"):
|
61 |
-
with gr.Row():
|
62 |
-
with gr.Column():
|
63 |
-
i2p_image = gr.Image(label="Upload Input Image", type="pil")
|
64 |
-
i2p_mask = gr.Image(label="Upload Mask Image (Optional)", type="pil")
|
65 |
-
i2p_prompt = gr.Textbox(label="Enter your prompt", lines=3)
|
66 |
-
i2p_upscale = gr.Checkbox(label="Upscale (requires >16GB GPU)")
|
67 |
-
i2p_generate = gr.Button("Generate Panorama")
|
68 |
-
with gr.Column():
|
69 |
-
i2p_output = Pannellum(label="Generated 360° Panorama")
|
70 |
-
|
71 |
-
i2p_generate.click(
|
72 |
-
image_to_pano,
|
73 |
-
inputs=[i2p_image, i2p_mask, i2p_prompt, i2p_upscale],
|
74 |
-
outputs=i2p_output
|
75 |
-
)
|
76 |
|
77 |
demo.launch()
|
|
|
4 |
import torch
|
5 |
from huggingface_hub import snapshot_download
|
6 |
from txt2panoimg import Text2360PanoramaImagePipeline
|
|
|
7 |
from PIL import Image
|
8 |
|
9 |
# Download the model
|
|
|
11 |
|
12 |
# Initialize pipelines
|
13 |
txt2panoimg = Text2360PanoramaImagePipeline(model_path, torch_dtype=torch.float16)
|
|
|
|
|
|
|
|
|
14 |
|
15 |
@spaces.GPU(duration=200)
|
16 |
def text_to_pano(prompt, upscale):
|
|
|
18 |
output = txt2panoimg(input_data)
|
19 |
return output
|
20 |
|
21 |
+
with gr.Blocks(theme='bethecloud/storj_theme') as demo:
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
22 |
gr.Markdown("# 360° Panorama Image Generation")
|
23 |
|
24 |
+
with gr.Row():
|
25 |
+
with gr.Column():
|
26 |
+
t2p_input = gr.Textbox(label="Enter your prompt", lines=3)
|
27 |
+
t2p_upscale = gr.Checkbox(label="Upscale (requires >16GB GPU)")
|
28 |
+
t2p_generate = gr.Button("Generate Panorama")
|
29 |
+
with gr.Column():
|
30 |
+
t2p_output = Pannellum(label="Generated 360° Panorama")
|
31 |
+
|
32 |
+
t2p_generate.click(
|
33 |
+
text_to_pano,
|
34 |
+
inputs=[t2p_input, t2p_upscale],
|
35 |
+
outputs=t2p_output
|
36 |
+
)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
37 |
|
38 |
demo.launch()
|