Keyurjotaniya007 commited on
Commit
c712fcf
·
verified ·
1 Parent(s): 00c1960

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +22 -21
app.py CHANGED
@@ -47,28 +47,29 @@ def main():
47
 
48
  with right:
49
  if uploaded_image:
50
- with st.spinner("Generating HTML + CSS using Gemini 2.5 Flash..."):
51
- try:
52
- output = generate_html_css_from_image(uploaded_image)
53
- if output:
54
- st.subheader("💬 Generated HTML + CSS:")
55
- placeholder = st.empty()
56
- typed_text = ""
57
- for char in output:
58
- typed_text += char
59
- placeholder.code(typed_text, language="html")
60
- time.sleep(0.003)
61
 
62
- st.download_button(
63
- label="💾 Download HTML file",
64
- data=output,
65
- file_name="generated_ui.html",
66
- mime="text/html"
67
- )
68
- else:
69
- st.error("No output generated. Please try again.")
70
- except Exception as e:
71
- st.error(f"Error: {e}")
 
 
 
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()