Spaces:
Build error
Build error
checkpoint 360 aframe fixed image
Browse files
app.py
CHANGED
@@ -42,76 +42,30 @@ title = """
|
|
42 |
|
43 |
"""
|
44 |
|
45 |
-
def create_aframe_html(image):
|
46 |
-
buffered = io.BytesIO()
|
47 |
-
image.save(buffered, format="JPEG")
|
48 |
-
img_str = base64.b64encode(buffered.getvalue()).decode('utf-8')
|
49 |
-
|
50 |
-
aframe_html = f"""
|
51 |
-
<html>
|
52 |
-
<head>
|
53 |
-
<script src="https://aframe.io/releases/1.3.0/aframe.min.js"></script>
|
54 |
-
</head>
|
55 |
-
<body>
|
56 |
-
<a-scene>
|
57 |
-
<a-sky src="data:image/jpeg;base64,{img_str}"></a-sky>
|
58 |
-
</a-scene>
|
59 |
-
</body>
|
60 |
-
</html>
|
61 |
-
"""
|
62 |
-
return aframe_html
|
63 |
-
|
64 |
-
|
65 |
-
def create_aframe_preview(image):
|
66 |
-
if image is None:
|
67 |
-
return gr.HTML("Error generating image. Please check the prompt or try again.")
|
68 |
-
|
69 |
-
buffered = io.BytesIO()
|
70 |
-
image.save(buffered, format="JPEG")
|
71 |
-
img_str = base64.b64encode(buffered.getvalue()).decode('utf-8')
|
72 |
-
|
73 |
-
aframe_html = f"""
|
74 |
-
<a-scene embedded style="width: 100%; height: 400px;">
|
75 |
-
<a-sky src="{img_str}" 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(f'<iframe srcdoc="{aframe_html}" allowfullscreen frameborder="0"></iframe>')
|
80 |
-
|
81 |
-
|
82 |
with gr.Blocks(theme=gr.themes.Soft()) as demo:
|
83 |
gr.HTML(title)
|
84 |
-
|
85 |
with gr.Row():
|
86 |
with gr.Column():
|
87 |
t2p_input = gr.Textbox(label="Enter your prompt", lines=3)
|
88 |
t2p_upscale = gr.Checkbox(label="Upscale (takes about 60 seconds 6144x3072 resolution)")
|
89 |
-
t2p_generate = gr.Button("Generate 360°
|
90 |
-
with gr.Column(variant="
|
91 |
t2p_output = Pannellum(show_label=False, interactive=True)
|
92 |
-
|
93 |
-
with gr.Row():
|
94 |
-
t2p_image_output = gr.Image(label="Generated Image")
|
95 |
-
output_html = gr.HTML(label="A-Frame HTML Code (Copy and use in Glitch)")
|
96 |
-
copy_html_button = gr.Button("Copy A-Frame HTML")
|
97 |
-
with gr.Column(variant="panel"): # Add wrapper for A-Frame to avoid split screen
|
98 |
-
aframe_preview = gr.HTML(label="A-Frame Preview")
|
99 |
|
|
|
|
|
|
|
|
|
100 |
update_trigger = gr.State(value=0)
|
101 |
|
102 |
def generate_with_update(prompt, upscale, trigger):
|
103 |
output, image = text_to_pano(prompt, upscale)
|
104 |
-
|
105 |
-
preview = create_aframe_preview(image)
|
106 |
-
return output, image, html, preview, trigger + 1
|
107 |
|
108 |
t2p_generate.click(
|
109 |
generate_with_update,
|
110 |
inputs=[t2p_input, t2p_upscale, update_trigger],
|
111 |
-
outputs=[t2p_output, t2p_image_output,
|
112 |
)
|
113 |
-
t2p_image_output.change(create_aframe_preview, inputs=[t2p_image_output], outputs=[aframe_preview])
|
114 |
-
|
115 |
-
copy_html_button.click(lambda html: gr.File.update(value=html, visible=True), inputs=[output_html], outputs=[gr.File(label="A-Frame HTML Code", visible=False)])
|
116 |
|
117 |
demo.launch()
|
|
|
42 |
|
43 |
"""
|
44 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
45 |
with gr.Blocks(theme=gr.themes.Soft()) as demo:
|
46 |
gr.HTML(title)
|
|
|
47 |
with gr.Row():
|
48 |
with gr.Column():
|
49 |
t2p_input = gr.Textbox(label="Enter your prompt", lines=3)
|
50 |
t2p_upscale = gr.Checkbox(label="Upscale (takes about 60 seconds 6144x3072 resolution)")
|
51 |
+
t2p_generate = gr.Button("Generate 360°Image")
|
52 |
+
with gr.Column(variant="default"):
|
53 |
t2p_output = Pannellum(show_label=False, interactive=True)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
54 |
|
55 |
+
with gr.Row():
|
56 |
+
t2p_image_output = gr.Image(label="Generated 360°Image")
|
57 |
+
|
58 |
+
# Add a hidden component to store a random value
|
59 |
update_trigger = gr.State(value=0)
|
60 |
|
61 |
def generate_with_update(prompt, upscale, trigger):
|
62 |
output, image = text_to_pano(prompt, upscale)
|
63 |
+
return output, image, trigger + 1
|
|
|
|
|
64 |
|
65 |
t2p_generate.click(
|
66 |
generate_with_update,
|
67 |
inputs=[t2p_input, t2p_upscale, update_trigger],
|
68 |
+
outputs=[t2p_output, t2p_image_output, update_trigger]
|
69 |
)
|
|
|
|
|
|
|
70 |
|
71 |
demo.launch()
|