Spaces:
Running
Running
Update app.py
Browse files
app.py
CHANGED
@@ -11,12 +11,6 @@ st.set_page_config(page_title="Image Caption Generator", layout="centered")
|
|
11 |
# API key from environment variable
|
12 |
API_KEY = os.environ.get("NEBIUS_API_KEY")
|
13 |
|
14 |
-
# UI for the app
|
15 |
-
st.title("Image Caption Generator")
|
16 |
-
st.write(
|
17 |
-
"Upload an image, and this app will generate a detailed caption for it using the Nebius AI API."
|
18 |
-
)
|
19 |
-
|
20 |
if not API_KEY:
|
21 |
st.error("API key not found. Please set the `NEBIUS_API_KEY` environment variable.")
|
22 |
|
@@ -85,15 +79,21 @@ if uploaded_image and API_KEY:
|
|
85 |
st.subheader("Generated Caption")
|
86 |
st.write(caption)
|
87 |
|
88 |
-
#
|
89 |
-
st.
|
90 |
f"""
|
91 |
-
<
|
|
|
|
|
|
|
92 |
<script>
|
93 |
-
|
94 |
-
|
95 |
-
|
96 |
-
|
|
|
|
|
|
|
97 |
</script>
|
98 |
""",
|
99 |
unsafe_allow_html=True,
|
@@ -116,6 +116,7 @@ st.markdown(
|
|
116 |
.css-1y4ccs5 {margin: 0 auto;}
|
117 |
.css-1aumxhk {display: flex; justify-content: center;}
|
118 |
.css-1k6kn8p {justify-content: center; align-items: center; display: flex;}
|
|
|
119 |
</style>
|
120 |
""", unsafe_allow_html=True
|
121 |
)
|
|
|
11 |
# API key from environment variable
|
12 |
API_KEY = os.environ.get("NEBIUS_API_KEY")
|
13 |
|
|
|
|
|
|
|
|
|
|
|
|
|
14 |
if not API_KEY:
|
15 |
st.error("API key not found. Please set the `NEBIUS_API_KEY` environment variable.")
|
16 |
|
|
|
79 |
st.subheader("Generated Caption")
|
80 |
st.write(caption)
|
81 |
|
82 |
+
# JavaScript for clipboard functionality (with custom HTML block)
|
83 |
+
st.components.v1.html(
|
84 |
f"""
|
85 |
+
<div style="text-align:center;">
|
86 |
+
<textarea id="caption-textarea" style="width: 80%; height: 100px;">{caption}</textarea><br><br>
|
87 |
+
<button onclick="copyToClipboard()">Copy Caption</button>
|
88 |
+
</div>
|
89 |
<script>
|
90 |
+
function copyToClipboard() {{
|
91 |
+
var copyText = document.getElementById("caption-textarea");
|
92 |
+
copyText.select();
|
93 |
+
copyText.setSelectionRange(0, 99999); // For mobile devices
|
94 |
+
document.execCommand("copy");
|
95 |
+
alert("Caption copied to clipboard!");
|
96 |
+
}}
|
97 |
</script>
|
98 |
""",
|
99 |
unsafe_allow_html=True,
|
|
|
116 |
.css-1y4ccs5 {margin: 0 auto;}
|
117 |
.css-1aumxhk {display: flex; justify-content: center;}
|
118 |
.css-1k6kn8p {justify-content: center; align-items: center; display: flex;}
|
119 |
+
.css-ffhzg6 {text-align: center;}
|
120 |
</style>
|
121 |
""", unsafe_allow_html=True
|
122 |
)
|