Prashanthsrn commited on
Commit
8b4c31a
·
verified ·
1 Parent(s): becb527

Create app.py

Browse files
Files changed (1) hide show
  1. app.py +46 -0
app.py ADDED
@@ -0,0 +1,46 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import streamlit as st
2
+ from PIL import Image
3
+ import io
4
+ from image_to_text import generate_initial_caption
5
+ from caption_refiner import refine_caption
6
+ 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
+
25
+ # Refine caption
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()