SHAMIL SHAHBAZ AWAN commited on
Commit
bd931ab
·
verified ·
1 Parent(s): 65486ba

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +29 -22
app.py CHANGED
@@ -33,7 +33,7 @@ def calculate_weight(earth_weight, planet):
33
  def main():
34
  with gr.Blocks(css="""
35
  .gradio-container {
36
- background: url('https://encrypted-tbn0.gstatic.com/images?q=tbn:ANd9GcQrpx_alD_MY29yHYIZryYkBbT-LB-Kb1PpdhDmhb4MPfAIX2WCfOIhYW_6WaxAmR6LW5U&usqp=CAU') no-repeat center center fixed;
37
  background-size: cover;
38
  min-height: 100vh;
39
  }
@@ -90,31 +90,38 @@ def main():
90
  earth_weight_input = gr.Number(label="Enter your weight on Earth (kg)", interactive=True)
91
  planet_input = gr.Dropdown(choices=list(gravity_factors.keys()), label="Choose a planet", interactive=True)
92
 
 
93
  output = gr.Textbox(label="Equivalent Weight on Planet", interactive=False)
94
 
95
- # Submit button and interaction
96
- button = gr.Button("Calculate Weight")
97
-
98
- # Function to trigger balloon effect using JavaScript
99
- def trigger_balloon_effect():
100
- return """
101
- const balloonCount = 5; // Number of balloons to show
102
- for (let i = 0; i < balloonCount; i++) {
103
- let balloon = document.createElement('div');
104
- balloon.classList.add('balloon');
105
- balloon.style.left = Math.random() * 100 + 'vw'; // Random horizontal position
106
- let balloonText = document.createElement('div');
107
- balloonText.classList.add('balloon-text');
108
- balloonText.textContent = '🎈'; // Emoji or custom text for the balloon
109
- balloon.appendChild(balloonText);
110
- document.body.appendChild(balloon);
111
- setTimeout(() => balloon.remove(), 6000); // Remove balloon after animation
112
  }
113
- """
 
 
 
 
 
 
 
114
 
115
- # Connect button click to calculate weight and trigger the balloon effect
116
- button.click(calculate_weight, inputs=[earth_weight_input, planet_input], outputs=output)
117
- button.click(trigger_balloon_effect)
118
 
119
  demo.launch()
120
 
 
33
  def main():
34
  with gr.Blocks(css="""
35
  .gradio-container {
36
+ 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;
37
  background-size: cover;
38
  min-height: 100vh;
39
  }
 
90
  earth_weight_input = gr.Number(label="Enter your weight on Earth (kg)", interactive=True)
91
  planet_input = gr.Dropdown(choices=list(gravity_factors.keys()), label="Choose a planet", interactive=True)
92
 
93
+ # Output section for the equivalent weight
94
  output = gr.Textbox(label="Equivalent Weight on Planet", interactive=False)
95
 
96
+ # HTML component for balloon effect trigger
97
+ balloon_script = gr.HTML("""
98
+ <script>
99
+ function triggerBalloonEffect() {
100
+ const balloonCount = 5; // Number of balloons to show
101
+ for (let i = 0; i < balloonCount; i++) {
102
+ let balloon = document.createElement('div');
103
+ balloon.classList.add('balloon');
104
+ balloon.style.left = Math.random() * 100 + 'vw'; // Random horizontal position
105
+ let balloonText = document.createElement('div');
106
+ balloonText.classList.add('balloon-text');
107
+ balloonText.textContent = '🎈'; // Emoji or custom text for the balloon
108
+ balloon.appendChild(balloonText);
109
+ document.body.appendChild(balloon);
110
+ setTimeout(() => balloon.remove(), 6000); // Remove balloon after animation
111
+ }
 
112
  }
113
+ </script>
114
+ """)
115
+
116
+ # Function to trigger balloon effect and then calculate weight
117
+ def trigger_balloon_and_weight(earth_weight, planet):
118
+ result = calculate_weight(earth_weight, planet)
119
+ balloon_script.trigger() # Trigger the balloon effect
120
+ return result
121
 
122
+ # Submit button and interaction
123
+ button = gr.Button("Calculate Weight")
124
+ button.click(trigger_balloon_and_weight, inputs=[earth_weight_input, planet_input], outputs=output)
125
 
126
  demo.launch()
127