Spaces:
Runtime error
Runtime error
Upload app.py
Browse files
app.py
ADDED
|
@@ -0,0 +1,55 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import spaces
|
| 2 |
+
import gradio as gr
|
| 3 |
+
from gradio_pannellum import Pannellum
|
| 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
|
| 10 |
+
model_path = snapshot_download("archerfmy0831/sd-t2i-360panoimage")
|
| 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):
|
| 17 |
+
input_data = {'prompt': prompt, 'upscale': upscale, 'refinement': False}
|
| 18 |
+
output = txt2panoimg(input_data)
|
| 19 |
+
return output, output
|
| 20 |
+
|
| 21 |
+
title = """<h1 align="center">SD-T2I-360PanoImage</h1>
|
| 22 |
+
<p align="center">360Β° Panorama Image Generation</p>
|
| 23 |
+
<p><center>
|
| 24 |
+
<a href="https://github.com/ArcherFMY/SD-T2I-360PanoImage/" target="_blank">[Github]</a>
|
| 25 |
+
<a href="https://huggingface.co/archerfmy0831/sd-t2i-360panoimage" target="_blank">[Models]</a>
|
| 26 |
+
</center></p>
|
| 27 |
+
"""
|
| 28 |
+
|
| 29 |
+
with gr.Blocks(theme='bethecloud/storj_theme') as demo:
|
| 30 |
+
gr.HTML(title)
|
| 31 |
+
with gr.Row():
|
| 32 |
+
with gr.Column():
|
| 33 |
+
t2p_input = gr.Textbox(label="Enter your prompt", lines=3)
|
| 34 |
+
t2p_upscale = gr.Checkbox(label="Upscale (takes about 60 seconds 6144x3072 resolution)")
|
| 35 |
+
t2p_generate = gr.Button("Generate Panorama")
|
| 36 |
+
with gr.Column(variant="default"):
|
| 37 |
+
t2p_output = Pannellum(show_label=False, interactive=True)
|
| 38 |
+
|
| 39 |
+
with gr.Row():
|
| 40 |
+
t2p_image_output = gr.Image(label="Generated Image")
|
| 41 |
+
|
| 42 |
+
# Add a hidden component to store a random value
|
| 43 |
+
update_trigger = gr.State(value=0)
|
| 44 |
+
|
| 45 |
+
def generate_with_update(prompt, upscale, trigger):
|
| 46 |
+
output, image = text_to_pano(prompt, upscale)
|
| 47 |
+
return output, image, trigger + 1
|
| 48 |
+
|
| 49 |
+
t2p_generate.click(
|
| 50 |
+
generate_with_update,
|
| 51 |
+
inputs=[t2p_input, t2p_upscale, update_trigger],
|
| 52 |
+
outputs=[t2p_output, t2p_image_output, update_trigger]
|
| 53 |
+
)
|
| 54 |
+
|
| 55 |
+
demo.launch()
|