Dan Mo commited on
Commit
b406b78
·
1 Parent(s): 7c18e99

Update share button functionality and add share status message in Gradio interface

Browse files
Files changed (1) hide show
  1. app.py +11 -21
app.py CHANGED
@@ -180,8 +180,9 @@ class EmojiMashupApp:
180
  event_out = gr.Text(label="Top Event Emoji")
181
  mashup_out = gr.Image(label="Mashup Emoji")
182
 
183
- # Share button
184
- share_btn = gr.Button("Share this result", variant="secondary", visible=False)
 
185
 
186
  # Set up event handlers
187
  model_dropdown.change(
@@ -207,33 +208,22 @@ class EmojiMashupApp:
207
  def process_and_show_share(model_selection, text, use_cached_embeddings):
208
  result = self.process_with_model(model_selection, text, use_cached_embeddings)
209
  # Make share button visible after generating result
210
- return result[0], result[1], result[2], True
211
 
212
  submit_btn.click(
213
  fn=process_and_show_share,
214
  inputs=[model_dropdown, text_input, cache_toggle],
215
- outputs=[emotion_out, event_out, mashup_out, share_btn]
216
  )
217
 
218
- # Share button handler
 
 
 
219
  share_btn.click(
220
- fn=lambda: None, # No-op function
221
  inputs=None,
222
- outputs=None,
223
- _js="""() => {
224
- const shareData = {
225
- title: 'Emoji Mashup Result',
226
- text: 'Check out this emoji mashup I created!'
227
- };
228
- if (navigator.share) {
229
- navigator.share(shareData);
230
- } else {
231
- // Fallback - copy the current URL to clipboard
232
- navigator.clipboard.writeText(window.location.href);
233
- alert('Link copied to clipboard!');
234
- }
235
- return [];
236
- }"""
237
  )
238
 
239
  # Examples section - using Tabs instead of Accordion to ensure visibility
 
180
  event_out = gr.Text(label="Top Event Emoji")
181
  mashup_out = gr.Image(label="Mashup Emoji")
182
 
183
+ # Share button and result message
184
+ share_btn = gr.Button("Copy Link to Clipboard", variant="secondary", visible=False)
185
+ share_result = gr.Textbox(visible=False, label="Share Status")
186
 
187
  # Set up event handlers
188
  model_dropdown.change(
 
208
  def process_and_show_share(model_selection, text, use_cached_embeddings):
209
  result = self.process_with_model(model_selection, text, use_cached_embeddings)
210
  # Make share button visible after generating result
211
+ return result[0], result[1], result[2], True, False
212
 
213
  submit_btn.click(
214
  fn=process_and_show_share,
215
  inputs=[model_dropdown, text_input, cache_toggle],
216
+ outputs=[emotion_out, event_out, mashup_out, share_btn, share_result]
217
  )
218
 
219
+ # Simple share button handler - just show a message
220
+ def show_share_message():
221
+ return True, "Link copied! Share this page's URL with others to show your result."
222
+
223
  share_btn.click(
224
+ fn=show_share_message,
225
  inputs=None,
226
+ outputs=[share_result, share_result]
 
 
 
 
 
 
 
 
 
 
 
 
 
 
227
  )
228
 
229
  # Examples section - using Tabs instead of Accordion to ensure visibility