marwanto606 commited on
Commit
1748e13
·
verified ·
1 Parent(s): 1af7e7d

Update app.py

Browse files

update stCopyButton

Files changed (1) hide show
  1. app.py +27 -21
app.py CHANGED
@@ -18,10 +18,9 @@ def get_gemini_response(image):
18
 
19
  # Konfigurasi halaman
20
  st.set_page_config(page_title="Prompt Generation from Image", layout="wide")
21
-
22
  st.title("🖼️ Prompt Generator from Image")
23
 
24
- # Membuat dua kolom
25
  col1, col2 = st.columns(2)
26
 
27
  with col1:
@@ -46,26 +45,33 @@ with col2:
46
  prompt = get_gemini_response(image)
47
  st.code(prompt, language="markdown")
48
 
49
- # Tombol copy dengan interaksi
50
- st.markdown(f"""
51
- <button id="copyButton"
52
- onclick="copyToClipboard()"
53
- style="background-color:#4CAF50;color:white;padding:8px 12px;
54
- border:none;border-radius:4px;cursor:pointer;margin-top:10px;">
55
- 📋 Copy Prompt
56
- </button>
57
  <script>
58
- function copyToClipboard() {{
59
- const text = `{prompt}`;
60
- navigator.clipboard.writeText(text).then(function() {{
61
- const btn = document.getElementById("copyButton");
62
- btn.innerHTML = "✅ Copied!";
63
- setTimeout(() => {{
64
- btn.innerHTML = "📋 Copy Prompt";
65
- }}, 2000);
66
- }});
67
- }}
 
 
 
 
 
 
 
 
 
 
 
 
 
68
  </script>
69
- """, unsafe_allow_html=True)
70
  else:
71
  st.info("Please upload an image to generate a prompt.")
 
18
 
19
  # Konfigurasi halaman
20
  st.set_page_config(page_title="Prompt Generation from Image", layout="wide")
 
21
  st.title("🖼️ Prompt Generator from Image")
22
 
23
+ # Dua kolom layout
24
  col1, col2 = st.columns(2)
25
 
26
  with col1:
 
45
  prompt = get_gemini_response(image)
46
  st.code(prompt, language="markdown")
47
 
48
+ # Inject JavaScript untuk notifikasi klik tombol copy
49
+ st.markdown("""
 
 
 
 
 
 
50
  <script>
51
+ setTimeout(() => {
52
+ const copyBtns = window.parent.document.querySelectorAll('[data-testid="stCopyButton"]');
53
+ copyBtns.forEach(btn => {
54
+ btn.addEventListener('click', () => {
55
+ const notice = document.createElement("div");
56
+ notice.innerText = "✅ Prompt copied to clipboard!";
57
+ notice.style.position = "fixed";
58
+ notice.style.bottom = "30px";
59
+ notice.style.right = "30px";
60
+ notice.style.backgroundColor = "#4CAF50";
61
+ notice.style.color = "white";
62
+ notice.style.padding = "10px 16px";
63
+ notice.style.borderRadius = "8px";
64
+ notice.style.boxShadow = "0 4px 6px rgba(0,0,0,0.2)";
65
+ notice.style.zIndex = "9999";
66
+ notice.style.fontSize = "14px";
67
+ document.body.appendChild(notice);
68
+ setTimeout(() => {
69
+ notice.remove();
70
+ }, 2000);
71
+ });
72
+ });
73
+ }, 1000);
74
  </script>
75
+ """, unsafe_allow_html=True)
76
  else:
77
  st.info("Please upload an image to generate a prompt.")