SHAMIL SHAHBAZ AWAN commited on
Update app.py
Browse files32 unmodified lines3334353637383950 unmodified lines9091929394959697989910010110210310410510610710810911011111211311411511611711811912032 unmodified linesdef main():with gr.Blocks(css=""".gradio-container {background: url('https://encrypted-tbn0.gstatic.com/images?q=tbn:ANd9GcQrpx_alD_MY29yHYIZryYkBbT-LB-Kb1PpdhDmhb4MPfAIX2WCfOIhYW_6WaxAmR6LW5U&usqp=CAU') no-repeat center center fixed;background-size: cover;min-height: 100vh;}50 unmodified linesearth_weight_input = gr.Number(label="Enter your weight on Earth (kg)", interactive=True)planet_input = gr.Dropdown(choices=list(gravity_factors.keys()), label="Choose a planet", interactive=True)output = gr.Textbox(label="Equivalent Weight on Planet", interactive=False)# Submit button and interactionbutton = gr.Button("Calculate Weight")# Function to trigger balloon effect using JavaScriptdef trigger_balloon_effect():return """const balloonCount = 5; // Number of balloons to showfor (let i = 0; i < balloonCount; i++) {let balloon = document.createElement('div');balloon.classList.add('balloon');balloon.style.left = Math.random() * 100 + 'vw'; // Random horizontal positionlet balloonText = document.createElement('div');balloonText.classList.add('balloon-text');balloonText.textContent = '🎈'; // Emoji or custom text for the balloonballoon.appendChild(balloonText);document.body.appendChild(balloon);setTimeout(() => balloon.remove(), 6000); // Remove balloon after animation}"""# Connect button click to calculate weight and trigger the balloon effectbutton.click(calculate_weight, inputs=[earth_weight_input, planet_input], outputs=output)button.click(trigger_balloon_effect)demo.launch()32 unmodified lines3334353637383950 unmodified lines9091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612732 unmodified linesdef main():with gr.Blocks(css=""".gradio-container {background: url('https://img.freepik.com/free-photo/purple-black-futuristic-aztec-abstract-background-with-squares-neon-lights_181624-27830.jpg') no-repeat center center fixed;background-size: cover;min-height: 100vh;}50 unmodified linesearth_weight_input = gr.Number(label="Enter your weight on Earth (kg)", interactive=True)planet_input = gr.Dropdown(choices=list(gravity_factors.keys()), label="Choose a planet", interactive=True)# Output section for the equivalent weightoutput = gr.Textbox(label="Equivalent Weight on Planet", interactive=False)# HTML component for balloon effect triggerballoon_script = gr.HTML("""<script>function triggerBalloonEffect() {const balloonCount = 5; // Number of balloons to showfor (let i = 0; i < balloonCount; i++) {let balloon = document.createElement('div');balloon.classList.add('balloon');balloon.style.left = Math.random() * 100 + 'vw'; // Random horizontal positionlet balloonText = document.createElement('div');balloonText.classList.add('balloon-text');balloonText.textContent = '🎈'; // Emoji or custom text for the balloonballoon.appendChild(balloonText);document.body.appendChild(balloon);setTimeout(() => balloon.remove(), 6000); // Remove balloon after animation}}</script>""")# Function to trigger balloon effect and then calculate weightdef trigger_balloon_and_weight(earth_weight, planet):result = calculate_weight(earth_weight, planet)balloon_script.trigger() # Trigger the balloon effectreturn result# Submit button and interactionbutton = gr.Button("Calculate Weight")button.click(trigger_balloon_and_weight, inputs=[earth_weight_input, planet_input], outputs=output)demo.launch()
app.py+29-22