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