SHAMIL SHAHBAZ AWAN commited on
Update app.py
Browse files11234534 unmodified lines404142424344444546474849505152535455565758596061626364656667686970717273747576777879808182838449865051523 unmodified lines56575896979899100101102103104105106107108109110111112113114115116117118119120121596012461626364
import gradio as gr
# Define gravity constants for each planet as a percentage of Earth's gravity34 unmodified lines min-height: 100vh; } .gradio-container .output-box { animation: fadein 2s ease-in-out, scaleup 1s ease-out, textcolor 3s ease-in-out; animation: fadein 2s ease-in-out; }
@keyframes fadein { from { opacity: 0; } to { opacity: 1; } }
@keyframes scaleup { from { transform: scale(0.8); } to { transform: scale(1); } }
@keyframes textcolor { 0% { color: #ff7e5f; } 50% { color: #feb47b; } 100% { color: #00b4d8; } }
/* Balloon Animation */ .balloon { position: absolute; bottom: 0; animation: rise 6s ease-in-out forwards, float 4s ease-in-out infinite; }
@keyframes rise { 0% { bottom: 0; opacity: 1; } 100% { bottom: 90%; opacity: 0; } }
@keyframes float { 0% { transform: translateX(0); } 50% { transform: translateX(30px); } 100% { transform: translateX(0); } }
.balloon-text { font-size: 1.5rem; color: white; text-align: center; font-weight: bold; } """) as demo:
gr.Markdown("# Weight Calculator on Different Planets") gr.Markdown("Enter your weight on Earth and choose a planet to find your weight on it.") 3 unmodified lines output = gr.Textbox(label="Equivalent Weight on Planet", interactive=False)
# HTML component for balloon effect trigger balloon_script = gr.HTML(""" <script> function triggerBalloonEffect() { const balloonCount = 5; // Number of balloons to show for (let i = 0; i < balloonCount; i++) { let balloon = document.createElement('div'); balloon.classList.add('balloon'); balloon.style.left = Math.random() * 100 + 'vw'; // Random horizontal position let balloonText = document.createElement('div'); balloonText.classList.add('balloon-text'); balloonText.textContent = '🎈'; // Emoji or custom text for the balloon balloon.appendChild(balloonText); document.body.appendChild(balloon); setTimeout(() => balloon.remove(), 6000); // Remove balloon after animation } } </script> """)
# Function to trigger balloon effect def trigger_balloon_and_weight(earth_weight, planet): result = calculate_weight(earth_weight, planet) balloon_script.trigger() # Trigger the balloon effect return result # Submit button and interaction button = gr.Button("Calculate Weight") button.click(trigger_balloon_and_weight, inputs=[earth_weight_input, planet_input], outputs=output) button.click(calculate_weight, inputs=[earth_weight_input, planet_input], outputs=output)
demo.launch()
app.py+4-67