Spaces:
Build error
Build error
checkpoint 360 aframe fixed image
Browse files
app.py
CHANGED
@@ -14,20 +14,17 @@ import spaces
|
|
14 |
model_path = snapshot_download("archerfmy0831/sd-t2i-360panoimage")
|
15 |
|
16 |
# Initialize pipelines
|
17 |
-
|
18 |
-
pipe = pipe.to("cuda")
|
19 |
|
20 |
-
|
21 |
-
@spaces.GPU(duration=200) # Assuming you have a GPU available
|
22 |
def text_to_pano(prompt, upscale):
|
23 |
try:
|
24 |
input_data = {'prompt': prompt, 'upscale': upscale, 'refinement': False}
|
25 |
-
|
26 |
-
return
|
27 |
except Exception as e:
|
28 |
print(f"Error generating panorama: {e}")
|
29 |
-
return None
|
30 |
-
|
31 |
|
32 |
title = """
|
33 |
<div style="text-align: left;">
|
@@ -42,12 +39,12 @@ title = """
|
|
42 |
</div>
|
43 |
"""
|
44 |
|
45 |
-
|
46 |
def create_aframe_html(image):
|
47 |
buffered = io.BytesIO()
|
48 |
image.save(buffered, format="JPEG")
|
49 |
img_str = base64.b64encode(buffered.getvalue()).decode('utf-8')
|
50 |
-
|
|
|
51 |
<html>
|
52 |
<head>
|
53 |
<script src="https://aframe.io/releases/1.3.0/aframe.min.js"></script>
|
@@ -59,23 +56,58 @@ def create_aframe_html(image):
|
|
59 |
</body>
|
60 |
</html>
|
61 |
"""
|
|
|
62 |
|
63 |
|
64 |
def create_aframe_preview(image):
|
65 |
if image is None:
|
66 |
return gr.HTML("Error generating image. Please check the prompt or try again.")
|
67 |
|
68 |
-
|
|
|
|
|
|
|
|
|
69 |
<a-scene embedded style="width: 100%; height: 400px;">
|
70 |
-
<a-
|
|
|
|
|
|
|
71 |
<a-text font="kelsonsans" value="Create from AI" width="6" position="-2.5 0.25 -1.5" rotation="0 15 0"></a-text>
|
72 |
</a-scene>
|
73 |
-
"""
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
74 |
|
75 |
|
76 |
with gr.Blocks(theme=gr.themes.Soft()) as demo:
|
77 |
gr.HTML(title)
|
78 |
-
|
79 |
with gr.Row():
|
80 |
with gr.Column():
|
81 |
t2p_input = gr.Textbox(label="Enter your prompt", lines=3)
|
@@ -83,27 +115,27 @@ with gr.Blocks(theme=gr.themes.Soft()) as demo:
|
|
83 |
t2p_generate = gr.Button("Generate 360° Image")
|
84 |
with gr.Column(variant="panel"):
|
85 |
t2p_output = Pannellum(show_label=False, interactive=True)
|
86 |
-
|
87 |
|
88 |
with gr.Row():
|
89 |
with gr.Column():
|
90 |
-
t2p_image_output = gr.Image(label="Generated Image"
|
91 |
image_url_output = gr.Textbox(label="Image URL")
|
92 |
gr.Button("Download Image").click(
|
93 |
None, inputs=[t2p_image_output], outputs=[t2p_image_output], _js="(img) => {window.open(img,'_blank');}"
|
94 |
)
|
95 |
with gr.Column(variant="panel"):
|
96 |
-
|
97 |
-
|
|
|
98 |
|
99 |
-
with gr.Column():
|
100 |
-
aframe_preview = gr.HTML(label="A-Frame Preview")
|
101 |
|
102 |
update_trigger = gr.State(value=0)
|
103 |
|
104 |
def generate_with_update(prompt, upscale, trigger):
|
105 |
-
image = text_to_pano(prompt, upscale)
|
106 |
-
image_url = get_image_url(image)
|
107 |
html = create_aframe_html(image) if image is not None else "Failed to generate A-Frame HTML. Please try again."
|
108 |
preview = create_aframe_preview(image)
|
109 |
return output, image, html, preview, image_url, trigger + 1
|
@@ -117,4 +149,4 @@ with gr.Blocks(theme=gr.themes.Soft()) as demo:
|
|
117 |
|
118 |
image_url_output.change(fn=get_aframe_code, inputs=[image_url_output], outputs=[output_html])
|
119 |
|
120 |
-
demo.launch()
|
|
|
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 |
title = """
|
30 |
<div style="text-align: left;">
|
|
|
39 |
</div>
|
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>
|
|
|
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-assets>
|
73 |
+
<img id="pano-img" src="data:image/jpeg;base64,{img_str}">
|
74 |
+
</a-assets>
|
75 |
+
<a-sky src="#pano-img" rotation="0 -130 0"></a-sky>
|
76 |
<a-text font="kelsonsans" value="Create from AI" width="6" position="-2.5 0.25 -1.5" rotation="0 15 0"></a-text>
|
77 |
</a-scene>
|
78 |
+
"""
|
79 |
+
return gr.HTML(aframe_html)
|
80 |
+
|
81 |
+
def get_image_url(image):
|
82 |
+
if image is None:
|
83 |
+
return None
|
84 |
+
buffered = io.BytesIO()
|
85 |
+
image.save(buffered, format="JPEG")
|
86 |
+
img_str = base64.b64encode(buffered.getvalue()).decode('utf-8')
|
87 |
+
return f"data:image/jpeg;base64,{img_str}"
|
88 |
+
|
89 |
+
def get_aframe_code(image_url):
|
90 |
+
if image_url is None:
|
91 |
+
return "Error generating A-Frame code. Please generate an image first."
|
92 |
+
aframe_html = f"""
|
93 |
+
<html>
|
94 |
+
<head>
|
95 |
+
<script src="https://aframe.io/releases/1.3.0/aframe.min.js"></script>
|
96 |
+
</head>
|
97 |
+
<body>
|
98 |
+
<a-scene>
|
99 |
+
<a-sky src="{image_url}" rotation="0 -130 0"></a-sky>
|
100 |
+
<a-text font="kelsonsans" value="Create from AI" width="6" position="-2.5 0.25 -1.5" rotation="0 15 0"></a-text>
|
101 |
+
</a-scene>
|
102 |
+
</body>
|
103 |
+
</html>
|
104 |
+
"""
|
105 |
+
return aframe_html
|
106 |
+
|
107 |
|
108 |
|
109 |
with gr.Blocks(theme=gr.themes.Soft()) as demo:
|
110 |
gr.HTML(title)
|
|
|
111 |
with gr.Row():
|
112 |
with gr.Column():
|
113 |
t2p_input = gr.Textbox(label="Enter your prompt", lines=3)
|
|
|
115 |
t2p_generate = gr.Button("Generate 360° Image")
|
116 |
with gr.Column(variant="panel"):
|
117 |
t2p_output = Pannellum(show_label=False, interactive=True)
|
|
|
118 |
|
119 |
with gr.Row():
|
120 |
with gr.Column():
|
121 |
+
t2p_image_output = gr.Image(label="Generated Image")
|
122 |
image_url_output = gr.Textbox(label="Image URL")
|
123 |
gr.Button("Download Image").click(
|
124 |
None, inputs=[t2p_image_output], outputs=[t2p_image_output], _js="(img) => {window.open(img,'_blank');}"
|
125 |
)
|
126 |
with gr.Column(variant="panel"):
|
127 |
+
with gr.Column():
|
128 |
+
output_html = gr.Textbox(label="A-Frame HTML Code (Copy and use in Glitch)", lines=15)
|
129 |
+
gr.Markdown("Copy the HTML code below and paste it into a new Glitch project to view your 360° panorama in VR.")
|
130 |
|
131 |
+
with gr.Column(variant="panel"): # Add wrapper for A-Frame to avoid split screen
|
132 |
+
aframe_preview = gr.HTML(label="A-Frame Preview")
|
133 |
|
134 |
update_trigger = gr.State(value=0)
|
135 |
|
136 |
def generate_with_update(prompt, upscale, trigger):
|
137 |
+
output, image = text_to_pano(prompt, upscale)
|
138 |
+
image_url = get_image_url(image)
|
139 |
html = create_aframe_html(image) if image is not None else "Failed to generate A-Frame HTML. Please try again."
|
140 |
preview = create_aframe_preview(image)
|
141 |
return output, image, html, preview, image_url, trigger + 1
|
|
|
149 |
|
150 |
image_url_output.change(fn=get_aframe_code, inputs=[image_url_output], outputs=[output_html])
|
151 |
|
152 |
+
demo.launch()
|