Update app.py
Browse files
app.py
CHANGED
|
@@ -47,28 +47,29 @@ def main():
|
|
| 47 |
|
| 48 |
with right:
|
| 49 |
if uploaded_image:
|
| 50 |
-
|
| 51 |
-
|
| 52 |
-
|
| 53 |
-
|
| 54 |
-
st.
|
| 55 |
-
|
| 56 |
-
|
| 57 |
-
|
| 58 |
-
|
| 59 |
-
placeholder.code(typed_text, language="html")
|
| 60 |
-
time.sleep(0.003)
|
| 61 |
|
| 62 |
-
|
| 63 |
-
|
| 64 |
-
|
| 65 |
-
|
| 66 |
-
|
| 67 |
-
|
| 68 |
-
|
| 69 |
-
|
| 70 |
-
|
| 71 |
-
|
|
|
|
|
|
|
|
|
|
| 72 |
|
| 73 |
if __name__ == "__main__":
|
| 74 |
main()
|
|
|
|
| 47 |
|
| 48 |
with right:
|
| 49 |
if uploaded_image:
|
| 50 |
+
if "output_html" not in st.session_state or st.session_state.get("last_image") != uploaded_image.name:
|
| 51 |
+
with st.spinner("Generating HTML + CSS using Gemini 2.5 Flash..."):
|
| 52 |
+
try:
|
| 53 |
+
output = generate_html_css_from_image(uploaded_image)
|
| 54 |
+
st.session_state.output_html = output
|
| 55 |
+
st.session_state.last_image = uploaded_image.name
|
| 56 |
+
except Exception as e:
|
| 57 |
+
st.error(f"Error: {e}")
|
| 58 |
+
return
|
|
|
|
|
|
|
| 59 |
|
| 60 |
+
output = st.session_state.output_html
|
| 61 |
+
if output:
|
| 62 |
+
st.subheader("💬 Generated HTML + CSS:")
|
| 63 |
+
placeholder = st.empty()
|
| 64 |
+
typed_text = ""
|
| 65 |
+
for char in output:
|
| 66 |
+
typed_text += char
|
| 67 |
+
placeholder.code(typed_text, language="html")
|
| 68 |
+
time.sleep(0.002)
|
| 69 |
+
|
| 70 |
+
st.download_button("💾 Download HTML file", data=output, file_name="generated_ui.html", mime="text/html")
|
| 71 |
+
else:
|
| 72 |
+
st.error("No output generated.")
|
| 73 |
|
| 74 |
if __name__ == "__main__":
|
| 75 |
main()
|