Spaces:
Sleeping
Sleeping
Dan Mo
commited on
Commit
·
b668c7e
1
Parent(s):
dbad28d
Add share button functionality to Gradio interface and update event handling
Browse files
app.py
CHANGED
@@ -124,6 +124,9 @@ class EmojiMashupApp:
|
|
124 |
emotion_out = gr.Text(label="Top Emotion Emoji")
|
125 |
event_out = gr.Text(label="Top Event Emoji")
|
126 |
mashup_out = gr.Image(label="Mashup Emoji")
|
|
|
|
|
|
|
127 |
|
128 |
# Set up event handlers
|
129 |
model_dropdown.change(
|
@@ -138,14 +141,41 @@ class EmojiMashupApp:
|
|
138 |
outputs=[model_info]
|
139 |
)
|
140 |
|
|
|
|
|
|
|
|
|
|
|
|
|
141 |
submit_btn.click(
|
142 |
-
fn=
|
143 |
inputs=[model_dropdown, text_input, cache_toggle],
|
144 |
-
outputs=[emotion_out, event_out, mashup_out]
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
145 |
)
|
146 |
|
147 |
-
# Examples based on Plutchik's Wheel of Emotions
|
148 |
-
with gr.Accordion("Examples", open=
|
149 |
gr.Markdown("### Primary Emotions")
|
150 |
gr.Examples(
|
151 |
examples=[
|
|
|
124 |
emotion_out = gr.Text(label="Top Emotion Emoji")
|
125 |
event_out = gr.Text(label="Top Event Emoji")
|
126 |
mashup_out = gr.Image(label="Mashup Emoji")
|
127 |
+
|
128 |
+
# Share button
|
129 |
+
share_btn = gr.Button("Share this result", variant="secondary", visible=False)
|
130 |
|
131 |
# Set up event handlers
|
132 |
model_dropdown.change(
|
|
|
141 |
outputs=[model_info]
|
142 |
)
|
143 |
|
144 |
+
# Process button handler with share button visibility update
|
145 |
+
def process_and_show_share(model_selection, text, use_cached_embeddings):
|
146 |
+
result = self.process_with_model(model_selection, text, use_cached_embeddings)
|
147 |
+
# Make share button visible after generating result
|
148 |
+
return result[0], result[1], result[2], True
|
149 |
+
|
150 |
submit_btn.click(
|
151 |
+
fn=process_and_show_share,
|
152 |
inputs=[model_dropdown, text_input, cache_toggle],
|
153 |
+
outputs=[emotion_out, event_out, mashup_out, share_btn]
|
154 |
+
)
|
155 |
+
|
156 |
+
# Share button handler
|
157 |
+
share_btn.click(
|
158 |
+
fn=lambda: None, # No-op function
|
159 |
+
inputs=None,
|
160 |
+
outputs=None,
|
161 |
+
_js="""() => {
|
162 |
+
const shareData = {
|
163 |
+
title: 'Emoji Mashup Result',
|
164 |
+
text: 'Check out this emoji mashup I created!'
|
165 |
+
};
|
166 |
+
if (navigator.share) {
|
167 |
+
navigator.share(shareData);
|
168 |
+
} else {
|
169 |
+
// Fallback - copy the current URL to clipboard
|
170 |
+
navigator.clipboard.writeText(window.location.href);
|
171 |
+
alert('Link copied to clipboard!');
|
172 |
+
}
|
173 |
+
return [];
|
174 |
+
}"""
|
175 |
)
|
176 |
|
177 |
+
# Examples based on Plutchik's Wheel of Emotions - now open by default
|
178 |
+
with gr.Accordion("Examples", open=True):
|
179 |
gr.Markdown("### Primary Emotions")
|
180 |
gr.Examples(
|
181 |
examples=[
|