Spaces:
Runtime error
Runtime error
Update app.py
Browse files
app.py
CHANGED
|
@@ -1,47 +1,10 @@
|
|
| 1 |
-
import
|
| 2 |
-
|
| 3 |
import torch
|
| 4 |
from huggingface_hub import snapshot_download
|
| 5 |
from txt2panoimg import Text2360PanoramaImagePipeline
|
| 6 |
from img2panoimg import Image2360PanoramaImagePipeline
|
| 7 |
from PIL import Image
|
| 8 |
-
from streamlit_pannellum import streamlit_pannellum
|
| 9 |
-
|
| 10 |
-
# Custom CSS to make the UI more attractive
|
| 11 |
-
st.markdown("""
|
| 12 |
-
<style>
|
| 13 |
-
.stApp {
|
| 14 |
-
max-width: 1200px;
|
| 15 |
-
margin: 0 auto;
|
| 16 |
-
}
|
| 17 |
-
.main {
|
| 18 |
-
background-color: #f0f2f6;
|
| 19 |
-
}
|
| 20 |
-
h1 {
|
| 21 |
-
color: #1E3A8A;
|
| 22 |
-
text-align: center;
|
| 23 |
-
padding: 20px 0;
|
| 24 |
-
font-size: 2.5rem;
|
| 25 |
-
}
|
| 26 |
-
.stTabs {
|
| 27 |
-
background-color: white;
|
| 28 |
-
padding: 20px;
|
| 29 |
-
border-radius: 10px;
|
| 30 |
-
box-shadow: 0 4px 6px rgba(0, 0, 0, 0.1);
|
| 31 |
-
}
|
| 32 |
-
.stButton>button {
|
| 33 |
-
background-color: #1E3A8A;
|
| 34 |
-
color: white;
|
| 35 |
-
font-weight: bold;
|
| 36 |
-
}
|
| 37 |
-
.viewer-column {
|
| 38 |
-
background-color: white;
|
| 39 |
-
padding: 20px;
|
| 40 |
-
border-radius: 10px;
|
| 41 |
-
box-shadow: 0 4px 6px rgba(0, 0, 0, 0.1);
|
| 42 |
-
}
|
| 43 |
-
</style>
|
| 44 |
-
""", unsafe_allow_html=True)
|
| 45 |
|
| 46 |
# Download the model
|
| 47 |
model_path = snapshot_download("archerfmy0831/sd-t2i-360panoimage")
|
|
@@ -53,13 +16,11 @@ img2panoimg = Image2360PanoramaImagePipeline(model_path, torch_dtype=torch.float
|
|
| 53 |
# Load the default mask image
|
| 54 |
default_mask = Image.open("i2p-mask.jpg").convert("RGB")
|
| 55 |
|
| 56 |
-
@spaces.GPU(duration=200)
|
| 57 |
def text_to_pano(prompt, upscale):
|
| 58 |
input_data = {'prompt': prompt, 'upscale': upscale}
|
| 59 |
output = txt2panoimg(input_data)
|
| 60 |
return output
|
| 61 |
|
| 62 |
-
@spaces.GPU(duration=200)
|
| 63 |
def image_to_pano(image, mask, prompt, upscale):
|
| 64 |
image = image.resize((512, 512))
|
| 65 |
if mask is None:
|
|
@@ -75,72 +36,47 @@ def image_to_pano(image, mask, prompt, upscale):
|
|
| 75 |
output = img2panoimg(input_data)
|
| 76 |
return output
|
| 77 |
|
| 78 |
-
|
| 79 |
-
|
| 80 |
-
|
| 81 |
-
|
| 82 |
-
# Function to display the panorama viewer
|
| 83 |
-
def display_panorama(image):
|
| 84 |
-
streamlit_pannellum(
|
| 85 |
-
config={
|
| 86 |
-
"default": {
|
| 87 |
-
"firstScene": "generated",
|
| 88 |
-
},
|
| 89 |
-
"scenes": {
|
| 90 |
-
"generated": {
|
| 91 |
-
"title": "Generated Panorama",
|
| 92 |
-
"type": "equirectangular",
|
| 93 |
-
"panorama": image,
|
| 94 |
-
"autoLoad": True,
|
| 95 |
-
}
|
| 96 |
-
}
|
| 97 |
-
}
|
| 98 |
-
)
|
| 99 |
-
|
| 100 |
-
with tab1:
|
| 101 |
-
col1, col2 = st.columns([1, 1])
|
| 102 |
-
|
| 103 |
-
with col1:
|
| 104 |
-
st.subheader("Input")
|
| 105 |
-
t2p_input = st.text_area("Enter your prompt", height=100)
|
| 106 |
-
t2p_upscale = st.checkbox("Upscale (requires >16GB GPU)")
|
| 107 |
-
generate_button = st.button("Generate Panorama")
|
| 108 |
|
| 109 |
-
|
| 110 |
-
|
| 111 |
-
|
| 112 |
-
viewer_placeholder = st.empty()
|
| 113 |
|
| 114 |
-
|
| 115 |
-
|
| 116 |
-
output = text_to_pano(t2p_input, t2p_upscale)
|
| 117 |
-
output_placeholder.image(output, caption="Generated 360° Panorama", use_column_width=True)
|
| 118 |
-
with viewer_placeholder.container():
|
| 119 |
-
display_panorama(output)
|
| 120 |
|
| 121 |
-
with
|
| 122 |
-
|
| 123 |
-
|
| 124 |
-
|
| 125 |
-
|
| 126 |
-
|
| 127 |
-
|
| 128 |
-
|
| 129 |
-
|
| 130 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
| 131 |
|
| 132 |
-
with
|
| 133 |
-
|
| 134 |
-
|
| 135 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 136 |
|
| 137 |
-
|
| 138 |
-
with st.spinner("Generating your 360° panorama..."):
|
| 139 |
-
image = Image.open(i2p_image)
|
| 140 |
-
mask = Image.open(i2p_mask) if i2p_mask is not None else None
|
| 141 |
-
output = image_to_pano(image, mask, i2p_prompt, i2p_upscale)
|
| 142 |
-
output_placeholder.image(output, caption="Generated 360° Panorama", use_column_width=True)
|
| 143 |
-
with viewer_placeholder.container():
|
| 144 |
-
display_panorama(output)
|
| 145 |
-
elif generate_button and i2p_image is None:
|
| 146 |
-
st.error("Please upload an input image.")
|
|
|
|
| 1 |
+
import gradio as gr
|
| 2 |
+
from gradio_pannellum import Pannellum
|
| 3 |
import torch
|
| 4 |
from huggingface_hub import snapshot_download
|
| 5 |
from txt2panoimg import Text2360PanoramaImagePipeline
|
| 6 |
from img2panoimg import Image2360PanoramaImagePipeline
|
| 7 |
from PIL import Image
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 8 |
|
| 9 |
# Download the model
|
| 10 |
model_path = snapshot_download("archerfmy0831/sd-t2i-360panoimage")
|
|
|
|
| 16 |
# Load the default mask image
|
| 17 |
default_mask = Image.open("i2p-mask.jpg").convert("RGB")
|
| 18 |
|
|
|
|
| 19 |
def text_to_pano(prompt, upscale):
|
| 20 |
input_data = {'prompt': prompt, 'upscale': upscale}
|
| 21 |
output = txt2panoimg(input_data)
|
| 22 |
return output
|
| 23 |
|
|
|
|
| 24 |
def image_to_pano(image, mask, prompt, upscale):
|
| 25 |
image = image.resize((512, 512))
|
| 26 |
if mask is None:
|
|
|
|
| 36 |
output = img2panoimg(input_data)
|
| 37 |
return output
|
| 38 |
|
| 39 |
+
def text_to_pano_interface(prompt, upscale):
|
| 40 |
+
output = text_to_pano(prompt, upscale)
|
| 41 |
+
return Pannellum().update(panorama=output)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 42 |
|
| 43 |
+
def image_to_pano_interface(image, mask, prompt, upscale):
|
| 44 |
+
output = image_to_pano(image, mask, prompt, upscale)
|
| 45 |
+
return Pannellum().update(panorama=output)
|
|
|
|
| 46 |
|
| 47 |
+
with gr.Blocks() as demo:
|
| 48 |
+
gr.Markdown("# 360° Panorama Image Generation")
|
|
|
|
|
|
|
|
|
|
|
|
|
| 49 |
|
| 50 |
+
with gr.Tab("Text to 360° Panorama"):
|
| 51 |
+
with gr.Row():
|
| 52 |
+
with gr.Column():
|
| 53 |
+
t2p_input = gr.Textbox(label="Enter your prompt", lines=3)
|
| 54 |
+
t2p_upscale = gr.Checkbox(label="Upscale (requires >16GB GPU)")
|
| 55 |
+
t2p_generate = gr.Button("Generate Panorama")
|
| 56 |
+
with gr.Column():
|
| 57 |
+
t2p_output = Pannellum(label="Generated 360° Panorama")
|
| 58 |
+
|
| 59 |
+
t2p_generate.click(
|
| 60 |
+
text_to_pano_interface,
|
| 61 |
+
inputs=[t2p_input, t2p_upscale],
|
| 62 |
+
outputs=t2p_output
|
| 63 |
+
)
|
| 64 |
|
| 65 |
+
with gr.Tab("Image to 360° Panorama"):
|
| 66 |
+
with gr.Row():
|
| 67 |
+
with gr.Column():
|
| 68 |
+
i2p_image = gr.Image(label="Upload Input Image", type="pil")
|
| 69 |
+
i2p_mask = gr.Image(label="Upload Mask Image (Optional)", type="pil")
|
| 70 |
+
i2p_prompt = gr.Textbox(label="Enter your prompt", lines=3)
|
| 71 |
+
i2p_upscale = gr.Checkbox(label="Upscale (requires >16GB GPU)")
|
| 72 |
+
i2p_generate = gr.Button("Generate Panorama")
|
| 73 |
+
with gr.Column():
|
| 74 |
+
i2p_output = Pannellum(label="Generated 360° Panorama")
|
| 75 |
+
|
| 76 |
+
i2p_generate.click(
|
| 77 |
+
image_to_pano_interface,
|
| 78 |
+
inputs=[i2p_image, i2p_mask, i2p_prompt, i2p_upscale],
|
| 79 |
+
outputs=i2p_output
|
| 80 |
+
)
|
| 81 |
|
| 82 |
+
demo.launch()
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|