mrbeliever commited on
Commit
2e0de3d
1 Parent(s): d6030a5

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +22 -4
app.py CHANGED
@@ -4,8 +4,9 @@ import os
4
  import base64
5
  from PIL import Image
6
  from io import BytesIO # Correctly import BytesIO from the io module
 
7
 
8
- # Set page title
9
  st.set_page_config(page_title="Image Caption Generator", layout="centered")
10
 
11
  # API key from environment variable
@@ -64,10 +65,10 @@ if uploaded_image and API_KEY:
64
  image_base64 = base64.b64encode(buffered.getvalue()).decode()
65
 
66
  # Show the uploaded image
67
- st.image(image, caption="Uploaded Image", use_column_width=True)
68
 
69
  # Add a button to trigger caption generation
70
- if st.button("Generate Caption"):
71
  st.write("Generating caption...")
72
  result = generate_caption(image_base64, API_KEY)
73
 
@@ -84,6 +85,12 @@ if uploaded_image and API_KEY:
84
  )
85
  st.subheader("Generated Caption")
86
  st.write(caption)
 
 
 
 
 
 
87
  except Exception as e:
88
  st.error(f"Error processing the response: {e}")
89
  else:
@@ -92,4 +99,15 @@ else:
92
  else:
93
  st.info("Please upload an image.")
94
 
95
- st.sidebar.write("Built with ❤️ by OpenAI GPT-4")
 
 
 
 
 
 
 
 
 
 
 
 
4
  import base64
5
  from PIL import Image
6
  from io import BytesIO # Correctly import BytesIO from the io module
7
+ import pyperclip # To copy the caption to clipboard
8
 
9
+ # Set page title and layout
10
  st.set_page_config(page_title="Image Caption Generator", layout="centered")
11
 
12
  # API key from environment variable
 
65
  image_base64 = base64.b64encode(buffered.getvalue()).decode()
66
 
67
  # Show the uploaded image
68
+ st.image(image, caption="Uploaded Image", use_container_width=True)
69
 
70
  # Add a button to trigger caption generation
71
+ if st.button("Generate Caption", use_container_width=True):
72
  st.write("Generating caption...")
73
  result = generate_caption(image_base64, API_KEY)
74
 
 
85
  )
86
  st.subheader("Generated Caption")
87
  st.write(caption)
88
+
89
+ # Add a copy button for the caption
90
+ if st.button("Copy Caption", key="copy_button"):
91
+ pyperclip.copy(caption) # Copy the caption to clipboard
92
+ st.success("Caption copied to clipboard!")
93
+
94
  except Exception as e:
95
  st.error(f"Error processing the response: {e}")
96
  else:
 
99
  else:
100
  st.info("Please upload an image.")
101
 
102
+ # Remove the sidebar and center the content
103
+ st.markdown(
104
+ """
105
+ <style>
106
+ .css-1d391kg {text-align: center;}
107
+ .css-1v3fvcr {justify-content: center; display: flex;}
108
+ .css-1y4ccs5 {margin: 0 auto;}
109
+ .css-1aumxhk {display: flex; justify-content: center;}
110
+ .css-1k6kn8p {justify-content: center; align-items: center; display: flex;}
111
+ </style>
112
+ """, unsafe_allow_html=True
113
+ )