Keyurjotaniya007 commited on
Commit
332de48
·
verified ·
1 Parent(s): c712fcf

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +28 -13
app.py CHANGED
@@ -5,6 +5,11 @@ from chatbot import generate_html_css_from_image
5
  def main():
6
  st.set_page_config(page_title="Gemini 2.5 Flash HTML/CSS Chatbot", layout="wide")
7
 
 
 
 
 
 
8
  st.markdown("""
9
  <div style='text-align: center; padding: 10px 0;'>
10
  <h1>Welcome, Gemini 2.5 Flash HTML/CSS Chatbot</h1>
@@ -47,29 +52,39 @@ def 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()
 
5
  def main():
6
  st.set_page_config(page_title="Gemini 2.5 Flash HTML/CSS Chatbot", layout="wide")
7
 
8
+ if "output_html" not in st.session_state:
9
+ st.session_state.output_html = None
10
+ if "last_image" not in st.session_state:
11
+ st.session_state.last_image = None
12
+
13
  st.markdown("""
14
  <div style='text-align: center; padding: 10px 0;'>
15
  <h1>Welcome, Gemini 2.5 Flash HTML/CSS Chatbot</h1>
 
52
 
53
  with right:
54
  if uploaded_image:
55
+ current_name = getattr(uploaded_image, "name", "uploaded_image")
56
+
57
+ if st.session_state.last_image != current_name or st.session_state.output_html is None:
58
  with st.spinner("Generating HTML + CSS using Gemini 2.5 Flash..."):
59
  try:
60
  output = generate_html_css_from_image(uploaded_image)
61
  st.session_state.output_html = output
62
+ st.session_state.last_image = current_name
63
  except Exception as e:
64
  st.error(f"Error: {e}")
65
  return
66
 
67
+ output = st.session_state.get("output_html")
68
+ if output:
69
+ st.subheader("💬 Generated HTML + CSS:")
70
+ placeholder = st.empty()
71
+ typed_text = ""
72
+ for char in output:
73
+ typed_text += char
74
+ placeholder.code(typed_text, language="html")
75
+ time.sleep(0.002)
76
 
77
+ st.download_button(
78
+ "💾 Download HTML file",
79
+ data=output,
80
+ file_name="generated_ui.html",
81
+ mime="text/html"
82
+ )
83
+ else:
84
+ st.error("No output generated.")
85
  else:
86
+ st.session_state.output_html = None
87
+ st.session_state.last_image = None
88
 
89
  if __name__ == "__main__":
90
  main()