|
|
|
|
|
|
|
|
import gradio as gr |
|
|
|
|
|
|
|
|
MERCURY_GRAVITY = 0.376 |
|
|
VENUS_GRAVITY = 0.889 |
|
|
MARS_GRAVITY = 0.378 |
|
|
JUPITER_GRAVITY = 2.36 |
|
|
SATURN_GRAVITY = 1.081 |
|
|
URANUS_GRAVITY = 0.815 |
|
|
NEPTUNE_GRAVITY = 1.14 |
|
|
|
|
|
|
|
|
gravity_factors = { |
|
|
"Mercury": MERCURY_GRAVITY, |
|
|
"Venus": VENUS_GRAVITY, |
|
|
"Mars": MARS_GRAVITY, |
|
|
"Jupiter": JUPITER_GRAVITY, |
|
|
"Saturn": SATURN_GRAVITY, |
|
|
"Uranus": URANUS_GRAVITY, |
|
|
"Neptune": NEPTUNE_GRAVITY |
|
|
} |
|
|
|
|
|
|
|
|
def calculate_weight(earth_weight, planet): |
|
|
try: |
|
|
gravity_constant = gravity_factors[planet] |
|
|
planetary_weight = earth_weight * gravity_constant |
|
|
return f"The equivalent weight on {planet}: {round(planetary_weight, 2)} kg" |
|
|
except KeyError: |
|
|
return "Invalid planet. Please choose a valid planet from the solar system." |
|
|
|
|
|
|
|
|
def main(): |
|
|
with gr.Blocks(css=""" |
|
|
.gradio-container { |
|
|
background: url('https://www.pixelstalk.net/wp-content/uploads/images6/Solar-System-HD-Wallpaper-Computer.jpg') no-repeat center center fixed; |
|
|
background-size: cover; |
|
|
min-height: 100vh; |
|
|
} |
|
|
.gradio-container .output-box { |
|
|
animation: fadein 2s ease-in-out; |
|
|
} |
|
|
@keyframes fadein { |
|
|
from { opacity: 0; } |
|
|
to { opacity: 1; } |
|
|
} |
|
|
""") 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.") |
|
|
|
|
|
with gr.Row(): |
|
|
earth_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) |
|
|
|
|
|
|
|
|
button = gr.Button("Calculate Weight") |
|
|
button.click(calculate_weight, inputs=[earth_weight_input, planet_input], outputs=output) |
|
|
|
|
|
demo.launch() |
|
|
|
|
|
if __name__ == "__main__": |
|
|
main() |
|
|
|
|
|
|