mrbeliever commited on
Commit
03e23d5
1 Parent(s): 9d344e1

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +3 -20
app.py CHANGED
@@ -3,7 +3,7 @@ import requests
3
  import os
4
  import base64
5
  from PIL import Image
6
- from io import BytesIO
7
 
8
  # Set page title and layout
9
  st.set_page_config(page_title="Image Caption Generator", layout="centered")
@@ -53,7 +53,7 @@ uploaded_image = st.file_uploader("Upload an image", type=["png", "jpg", "jpeg"]
53
  if uploaded_image and API_KEY:
54
  # Convert the image to base64
55
  image = Image.open(uploaded_image)
56
- buffered = BytesIO()
57
  image.save(buffered, format="PNG")
58
  image_base64 = base64.b64encode(buffered.getvalue()).decode()
59
 
@@ -85,23 +85,6 @@ if uploaded_image and API_KEY:
85
  help="The generated caption will appear here.", label_visibility="collapsed"
86
  )
87
 
88
- # JavaScript to copy text from the text area
89
- st.markdown(
90
- """
91
- <script>
92
- function copyText() {
93
- var copyText = document.getElementById("caption_area");
94
- copyText.select();
95
- copyText.setSelectionRange(0, 99999); // For mobile devices
96
- document.execCommand("copy");
97
- }
98
- </script>
99
- """, unsafe_allow_html=True
100
- )
101
-
102
- # Add a button to trigger the copy functionality
103
- st.button("Copy Caption", on_click="copyText()")
104
-
105
  except Exception as e:
106
  st.error(f"Error processing the response: {e}")
107
  else:
@@ -121,7 +104,7 @@ st.markdown(
121
  font-size: 16px;
122
  padding: 10px;
123
  }
124
-
125
  /* Glowing blue button styling */
126
  .stButton>button {
127
  background-color: #007bff; /* Blue color */
 
3
  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 and layout
9
  st.set_page_config(page_title="Image Caption Generator", layout="centered")
 
53
  if uploaded_image and API_KEY:
54
  # Convert the image to base64
55
  image = Image.open(uploaded_image)
56
+ buffered = BytesIO() # Use BytesIO from the io module
57
  image.save(buffered, format="PNG")
58
  image_base64 = base64.b64encode(buffered.getvalue()).decode()
59
 
 
85
  help="The generated caption will appear here.", label_visibility="collapsed"
86
  )
87
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
88
  except Exception as e:
89
  st.error(f"Error processing the response: {e}")
90
  else:
 
104
  font-size: 16px;
105
  padding: 10px;
106
  }
107
+
108
  /* Glowing blue button styling */
109
  .stButton>button {
110
  background-color: #007bff; /* Blue color */