Spaces:
Build error
Build error
checkpoint Aframe Block
Browse files
app.py
CHANGED
@@ -42,30 +42,61 @@ title = """
|
|
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="
|
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 |
-
|
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 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
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()
|
|
|
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 |
+
return f"data:image/jpeg;base64,{img_str}"
|
50 |
+
|
51 |
+
|
52 |
with gr.Blocks(theme=gr.themes.Soft()) as demo:
|
53 |
gr.HTML(title)
|
54 |
+
|
55 |
with gr.Row():
|
56 |
with gr.Column():
|
57 |
t2p_input = gr.Textbox(label="Enter your prompt", lines=3)
|
58 |
t2p_upscale = gr.Checkbox(label="Upscale (takes about 60 seconds 6144x3072 resolution)")
|
59 |
+
t2p_generate = gr.Button("Generate 360° Image")
|
60 |
+
with gr.Column(variant="panel"):
|
61 |
t2p_output = Pannellum(show_label=False, interactive=True)
|
|
|
62 |
with gr.Row():
|
63 |
t2p_image_output = gr.Image(label="Generated 360°Image")
|
64 |
+
|
65 |
+
# New A-Frame Code Block
|
66 |
+
with gr.Row():
|
67 |
+
output_html = gr.Textbox(label="A-Frame HTML Code (Copy and use in Glitch)", lines=15, interactive=False)
|
68 |
+
gr.Markdown("""
|
69 |
+
**Copy this code for Glitch.com:**
|
70 |
+
1. Create a new Glitch project ([https://glitch.com/](https://glitch.com/)).
|
71 |
+
2. Choose the **hello-webpage** template.
|
72 |
+
3. Paste this HTML code into the `index.html` file.
|
73 |
+
""")
|
74 |
|
75 |
+
update_trigger = gr.State(value=0)
|
|
|
76 |
|
77 |
def generate_with_update(prompt, upscale, trigger):
|
78 |
output, image = text_to_pano(prompt, upscale)
|
79 |
+
image_url = create_aframe_html(image)
|
80 |
+
html = f"""
|
81 |
+
<html>
|
82 |
+
<head>
|
83 |
+
<script src="https://aframe.io/releases/1.3.0/aframe.min.js"></script>
|
84 |
+
</head>
|
85 |
+
<body>
|
86 |
+
<a-scene>
|
87 |
+
<a-sky src="{image_url}" rotation="0 -130 0"></a-sky>
|
88 |
+
<a-text font="kelsonsans" value="Generated from AI" width="8" position="-2.5 0.25 -1.5" rotation="0 15 0"></a-text>
|
89 |
+
</a-scene>
|
90 |
+
</body>
|
91 |
+
</html>
|
92 |
+
""" if image_url is not None else "Failed to generate A-Frame HTML. Please try again."
|
93 |
+
return output, image, html, trigger + 1
|
94 |
|
95 |
t2p_generate.click(
|
96 |
generate_with_update,
|
97 |
inputs=[t2p_input, t2p_upscale, update_trigger],
|
98 |
+
outputs=[t2p_output, t2p_image_output, output_html, update_trigger]
|
99 |
)
|
100 |
+
|
101 |
|
102 |
demo.launch()
|