Spaces:
Running
Running
Update app.py
Browse files
app.py
CHANGED
@@ -4,7 +4,6 @@ import os
|
|
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")
|
@@ -86,10 +85,19 @@ if uploaded_image and API_KEY:
|
|
86 |
st.subheader("Generated Caption")
|
87 |
st.write(caption)
|
88 |
|
89 |
-
# Add a copy button for the caption
|
90 |
-
|
91 |
-
|
92 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
93 |
|
94 |
except Exception as e:
|
95 |
st.error(f"Error processing the response: {e}")
|
|
|
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")
|
|
|
85 |
st.subheader("Generated Caption")
|
86 |
st.write(caption)
|
87 |
|
88 |
+
# Add a copy button for the caption using JavaScript
|
89 |
+
st.markdown(
|
90 |
+
f"""
|
91 |
+
<button id="copy-button" onclick="navigator.clipboard.writeText('{caption}')">Copy Caption</button>
|
92 |
+
<script>
|
93 |
+
const copyButton = document.getElementById('copy-button');
|
94 |
+
copyButton.addEventListener('click', function() {{
|
95 |
+
copyButton.innerText = 'Copied!';
|
96 |
+
}});
|
97 |
+
</script>
|
98 |
+
""",
|
99 |
+
unsafe_allow_html=True,
|
100 |
+
)
|
101 |
|
102 |
except Exception as e:
|
103 |
st.error(f"Error processing the response: {e}")
|