mrbeliever commited on
Commit
bc04ce4
·
verified ·
1 Parent(s): d36bef0

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +13 -14
app.py CHANGED
@@ -11,6 +11,12 @@ 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
  if not API_KEY:
15
  st.error("API key not found. Please set the `NEBIUS_API_KEY` environment variable.")
16
 
@@ -79,21 +85,15 @@ if uploaded_image and API_KEY:
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,7 +116,6 @@ 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
- .css-ffhzg6 {text-align: center;}
120
  </style>
121
  """, unsafe_allow_html=True
122
  )
 
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
  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,
 
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
  )