Spaces:
Build error
Build error
fixed again app.py
Browse files
app.py
CHANGED
@@ -1,4 +1,3 @@
|
|
1 |
-
import spaces
|
2 |
import gradio as gr
|
3 |
from PIL import Image
|
4 |
from diffusers import StableDiffusionPipeline
|
@@ -9,73 +8,9 @@ from gradio_pannellum import Pannellum
|
|
9 |
import io
|
10 |
from huggingface_hub import snapshot_download
|
11 |
from txt2panoimg import Text2360PanoramaImagePipeline
|
|
|
12 |
|
13 |
-
|
14 |
-
# Download the model
|
15 |
-
model_path = snapshot_download("archerfmy0831/sd-t2i-360panoimage")
|
16 |
-
|
17 |
-
# Initialize pipelines
|
18 |
-
txt2panoimg = Text2360PanoramaImagePipeline(model_path, torch_dtype=torch.float16)
|
19 |
-
|
20 |
-
@spaces.GPU(duration=200)
|
21 |
-
def text_to_pano(prompt, upscale):
|
22 |
-
try:
|
23 |
-
input_data = {'prompt': prompt, 'upscale': upscale, 'refinement': False}
|
24 |
-
output = txt2panoimg(input_data)
|
25 |
-
return output, output
|
26 |
-
except Exception as e:
|
27 |
-
print(f"Error generating panorama: {e}")
|
28 |
-
return None, None
|
29 |
-
|
30 |
-
|
31 |
-
title = """
|
32 |
-
<div style="text-align: center;">
|
33 |
-
<img src="https://ant.dpu.ac.th/wp-content/uploads/2024/04/dpulogo.png" width="200"/>
|
34 |
-
<h1>SD-T2I-360PanoImage</h1>
|
35 |
-
<p>360° Panorama Image Generation</p>
|
36 |
-
</div>
|
37 |
-
<p><center>
|
38 |
-
<a href="https://github.com/ArcherFMY/SD-T2I-360PanoImage/" target="_blank">[Github]</a>
|
39 |
-
<a href="https://huggingface.co/archerfmy0831/sd-t2i-360panoimage" target="_blank">[Models]</a>
|
40 |
-
</center></p>
|
41 |
-
"""
|
42 |
-
|
43 |
-
def create_aframe_html(image):
|
44 |
-
buffered = io.BytesIO()
|
45 |
-
image.save(buffered, format="JPEG")
|
46 |
-
img_str = base64.b64encode(buffered.getvalue()).decode('utf-8')
|
47 |
-
|
48 |
-
aframe_html = f"""
|
49 |
-
<html>
|
50 |
-
<head>
|
51 |
-
<script src="https://aframe.io/releases/1.3.0/aframe.min.js"></script>
|
52 |
-
</head>
|
53 |
-
<body>
|
54 |
-
<a-scene>
|
55 |
-
<a-sky src="data:image/jpeg;base64,{img_str}"></a-sky>
|
56 |
-
</a-scene>
|
57 |
-
</body>
|
58 |
-
</html>
|
59 |
-
"""
|
60 |
-
return aframe_html
|
61 |
-
|
62 |
-
|
63 |
-
def create_aframe_preview(image):
|
64 |
-
if image is None:
|
65 |
-
return gr.HTML("Error generating image. Please check the prompt or try again.")
|
66 |
-
|
67 |
-
buffered = io.BytesIO()
|
68 |
-
image.save(buffered, format="JPEG")
|
69 |
-
img_str = base64.b64encode(buffered.getvalue()).decode('utf-8')
|
70 |
-
|
71 |
-
aframe_html = f"""
|
72 |
-
<a-scene embedded style="width: 100%; height: 400px;">
|
73 |
-
<a-sky src="data:image/jpeg;base64,{img_str}" rotation="0 -130 0"></a-sky>
|
74 |
-
<a-text font="kelsonsans" value="Create from AI" width="6" position="-2.5 0.25 -1.5" rotation="0 15 0"></a-text>
|
75 |
-
</a-scene>
|
76 |
-
"""
|
77 |
-
return gr.HTML(f'<iframe srcdoc="{aframe_html}" allowfullscreen frameborder="0"></iframe>')
|
78 |
-
|
79 |
|
80 |
with gr.Blocks(theme=gr.themes.Soft()) as demo:
|
81 |
gr.HTML(title)
|
@@ -87,13 +22,16 @@ with gr.Blocks(theme=gr.themes.Soft()) as demo:
|
|
87 |
t2p_generate = gr.Button("Generate Panorama")
|
88 |
with gr.Column(variant="panel"):
|
89 |
t2p_output = Pannellum(show_label=False, interactive=True)
|
90 |
-
|
91 |
with gr.Row():
|
92 |
-
t2p_image_output = gr.Image(label="Generated Image")
|
93 |
output_html = gr.HTML(label="A-Frame HTML Code (Copy and use in Glitch)")
|
94 |
copy_html_button = gr.Button("Copy A-Frame HTML")
|
95 |
aframe_preview = gr.HTML(label="A-Frame Preview")
|
96 |
|
|
|
|
|
|
|
97 |
update_trigger = gr.State(value=0)
|
98 |
|
99 |
def generate_with_update(prompt, upscale, trigger):
|
@@ -107,8 +45,8 @@ with gr.Blocks(theme=gr.themes.Soft()) as demo:
|
|
107 |
inputs=[t2p_input, t2p_upscale, update_trigger],
|
108 |
outputs=[t2p_output, t2p_image_output, output_html, aframe_preview, update_trigger]
|
109 |
)
|
110 |
-
t2p_image_output.change(create_aframe_preview, inputs=[t2p_image_output], outputs=[aframe_preview])
|
111 |
|
|
|
112 |
copy_html_button.click(
|
113 |
None,
|
114 |
inputs=[output_html],
|
|
|
|
|
1 |
import gradio as gr
|
2 |
from PIL import Image
|
3 |
from diffusers import StableDiffusionPipeline
|
|
|
8 |
import io
|
9 |
from huggingface_hub import snapshot_download
|
10 |
from txt2panoimg import Text2360PanoramaImagePipeline
|
11 |
+
import spaces
|
12 |
|
13 |
+
# ... (rest of your imports and functions)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
14 |
|
15 |
with gr.Blocks(theme=gr.themes.Soft()) as demo:
|
16 |
gr.HTML(title)
|
|
|
22 |
t2p_generate = gr.Button("Generate Panorama")
|
23 |
with gr.Column(variant="panel"):
|
24 |
t2p_output = Pannellum(show_label=False, interactive=True)
|
25 |
+
|
26 |
with gr.Row():
|
27 |
+
t2p_image_output = gr.Image(label="Generated Image") # This should be output_image
|
28 |
output_html = gr.HTML(label="A-Frame HTML Code (Copy and use in Glitch)")
|
29 |
copy_html_button = gr.Button("Copy A-Frame HTML")
|
30 |
aframe_preview = gr.HTML(label="A-Frame Preview")
|
31 |
|
32 |
+
# Move the change event handler inside the gr.Row() block:
|
33 |
+
t2p_image_output.change(create_aframe_preview, inputs=[t2p_image_output], outputs=[aframe_preview])
|
34 |
+
|
35 |
update_trigger = gr.State(value=0)
|
36 |
|
37 |
def generate_with_update(prompt, upscale, trigger):
|
|
|
45 |
inputs=[t2p_input, t2p_upscale, update_trigger],
|
46 |
outputs=[t2p_output, t2p_image_output, output_html, aframe_preview, update_trigger]
|
47 |
)
|
|
|
48 |
|
49 |
+
|
50 |
copy_html_button.click(
|
51 |
None,
|
52 |
inputs=[output_html],
|