Prashanthsrn commited on
Commit
ebeb5b8
·
verified ·
1 Parent(s): 5d238a1

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +36 -9
app.py CHANGED
@@ -7,18 +7,43 @@ from utils import load_image
7
 
8
  def main():
9
  st.set_page_config(page_title="Image Caption Generator", layout="wide")
10
- st.title("Image Caption Generator")
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
11
 
12
  uploaded_file = st.file_uploader("Choose an image...", type=["jpg", "jpeg", "png"])
13
 
 
 
14
  if uploaded_file is not None:
15
  image = Image.open(uploaded_file)
16
- st.image(image, caption="Uploaded Image", use_column_width=True)
17
 
18
- if st.button("Generate Caption"):
19
  with st.spinner("Processing image..."):
20
  # Generate initial caption
21
- progress_bar = st.progress(0)
22
  initial_caption = generate_initial_caption(image)
23
  progress_bar.progress(50)
24
 
@@ -26,21 +51,23 @@ def main():
26
  final_caption = refine_caption(initial_caption)
27
  progress_bar.progress(100)
28
 
29
- st.success("Caption generated successfully!")
30
- st.write("Generated Caption:")
31
- st.write(final_caption)
32
 
33
  # Add copy button
34
- st.text_area("Copy caption", final_caption, height=100)
35
 
36
  # Add download button
37
  caption_bytes = final_caption.encode()
38
- st.download_button(
39
  label="Download Caption",
40
  data=caption_bytes,
41
  file_name="generated_caption.txt",
42
  mime="text/plain"
43
  )
 
 
44
 
45
  if __name__ == "__main__":
46
  main()
 
7
 
8
  def main():
9
  st.set_page_config(page_title="Image Caption Generator", layout="wide")
10
+
11
+ # Custom CSS to improve the UI
12
+ st.markdown("""
13
+ <style>
14
+ .big-font {
15
+ font-size:30px !important;
16
+ font-weight: bold;
17
+ color: #1E90FF;
18
+ }
19
+ .stButton>button {
20
+ background-color: #4CAF50;
21
+ color: white;
22
+ font-size: 18px;
23
+ padding: 10px 24px;
24
+ border-radius: 12px;
25
+ border: none;
26
+ }
27
+ .stTextInput>div>div>input {
28
+ background-color: #F0F8FF;
29
+ }
30
+ </style>
31
+ """, unsafe_allow_html=True)
32
+
33
+ st.markdown('<p class="big-font">Image Caption Generator</p>', unsafe_allow_html=True)
34
 
35
  uploaded_file = st.file_uploader("Choose an image...", type=["jpg", "jpeg", "png"])
36
 
37
+ col1, col2 = st.columns(2)
38
+
39
  if uploaded_file is not None:
40
  image = Image.open(uploaded_file)
41
+ col1.image(image, caption="Uploaded Image", use_column_width=True)
42
 
43
+ if col2.button("Generate Caption"):
44
  with st.spinner("Processing image..."):
45
  # Generate initial caption
46
+ progress_bar = col2.progress(0)
47
  initial_caption = generate_initial_caption(image)
48
  progress_bar.progress(50)
49
 
 
51
  final_caption = refine_caption(initial_caption)
52
  progress_bar.progress(100)
53
 
54
+ col2.success("Caption generated successfully!")
55
+ col2.markdown("### Generated Caption:")
56
+ col2.write(final_caption)
57
 
58
  # Add copy button
59
+ col2.text_area("Copy caption", final_caption, height=100)
60
 
61
  # Add download button
62
  caption_bytes = final_caption.encode()
63
+ col2.download_button(
64
  label="Download Caption",
65
  data=caption_bytes,
66
  file_name="generated_caption.txt",
67
  mime="text/plain"
68
  )
69
+ else:
70
+ col1.info("Please upload an image to get started.")
71
 
72
  if __name__ == "__main__":
73
  main()