Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
|
@@ -1,4 +1,5 @@
|
|
| 1 |
import streamlit as st
|
|
|
|
| 2 |
|
| 3 |
# Conversion functions
|
| 4 |
# Length conversions
|
|
@@ -193,6 +194,26 @@ def mile_per_hour_to_kilometer_per_hour(mph):
|
|
| 193 |
def kilometer_per_hour_to_mile_per_hour(kmph):
|
| 194 |
return kmph / 1.60934
|
| 195 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 196 |
# Streamlit UI
|
| 197 |
st.title("Unit Conversion App 🧮")
|
| 198 |
|
|
@@ -206,7 +227,9 @@ category = st.selectbox("Choose a conversion category", [
|
|
| 206 |
"Energy ⚡",
|
| 207 |
"Power 💪",
|
| 208 |
"Volume 🧃",
|
| 209 |
-
"Speed 🚗"
|
|
|
|
|
|
|
| 210 |
])
|
| 211 |
|
| 212 |
# Based on the selected category, add a selectbox for the specific conversion
|
|
@@ -269,250 +292,5 @@ if category == "Length 📏":
|
|
| 269 |
result = meter_to_centimeter(value)
|
| 270 |
st.write(f"{value} meters is equal to {result} centimeters")
|
| 271 |
|
| 272 |
-
|
| 273 |
-
|
| 274 |
-
"Gram to Kilogram",
|
| 275 |
-
"Kilogram to Gram",
|
| 276 |
-
"Milligram to Gram",
|
| 277 |
-
"Gram to Milligram",
|
| 278 |
-
"Pound to Kilogram",
|
| 279 |
-
"Kilogram to Pound",
|
| 280 |
-
"Ounce to Gram",
|
| 281 |
-
"Gram to Ounce"
|
| 282 |
-
])
|
| 283 |
-
|
| 284 |
-
value = st.number_input("Enter the value to convert", min_value=0.0)
|
| 285 |
-
|
| 286 |
-
if conversion_type == "Gram to Kilogram":
|
| 287 |
-
result = gram_to_kilogram(value)
|
| 288 |
-
st.write(f"{value} grams is equal to {result} kilograms")
|
| 289 |
-
elif conversion_type == "Kilogram to Gram":
|
| 290 |
-
result = kilogram_to_gram(value)
|
| 291 |
-
st.write(f"{value} kilograms is equal to {result} grams")
|
| 292 |
-
elif conversion_type == "Milligram to Gram":
|
| 293 |
-
result = milligram_to_gram(value)
|
| 294 |
-
st.write(f"{value} milligrams is equal to {result} grams")
|
| 295 |
-
elif conversion_type == "Gram to Milligram":
|
| 296 |
-
result = gram_to_milligram(value)
|
| 297 |
-
st.write(f"{value} grams is equal to {result} milligrams")
|
| 298 |
-
elif conversion_type == "Pound to Kilogram":
|
| 299 |
-
result = pound_to_kilogram(value)
|
| 300 |
-
st.write(f"{value} pounds is equal to {result} kilograms")
|
| 301 |
-
elif conversion_type == "Kilogram to Pound":
|
| 302 |
-
result = kilogram_to_pound(value)
|
| 303 |
-
st.write(f"{value} kilograms is equal to {result} pounds")
|
| 304 |
-
elif conversion_type == "Ounce to Gram":
|
| 305 |
-
result = ounce_to_gram(value)
|
| 306 |
-
st.write(f"{value} ounces is equal to {result} grams")
|
| 307 |
-
elif conversion_type == "Gram to Ounce":
|
| 308 |
-
result = gram_to_ounce(value)
|
| 309 |
-
st.write(f"{value} grams is equal to {result} ounces")
|
| 310 |
-
|
| 311 |
-
elif category == "Time ⏰":
|
| 312 |
-
conversion_type = st.selectbox("Choose a time conversion", [
|
| 313 |
-
"Seconds to Minutes",
|
| 314 |
-
"Minutes to Seconds",
|
| 315 |
-
"Hours to Minutes",
|
| 316 |
-
"Minutes to Hours",
|
| 317 |
-
"Days to Hours",
|
| 318 |
-
"Hours to Days"
|
| 319 |
-
])
|
| 320 |
-
|
| 321 |
-
value = st.number_input("Enter the value to convert", min_value=0.0)
|
| 322 |
-
|
| 323 |
-
if conversion_type == "Seconds to Minutes":
|
| 324 |
-
result = seconds_to_minutes(value)
|
| 325 |
-
st.write(f"{value} seconds is equal to {result} minutes")
|
| 326 |
-
elif conversion_type == "Minutes to Seconds":
|
| 327 |
-
result = minutes_to_seconds(value)
|
| 328 |
-
st.write(f"{value} minutes is equal to {result} seconds")
|
| 329 |
-
elif conversion_type == "Hours to Minutes":
|
| 330 |
-
result = hours_to_minutes(value)
|
| 331 |
-
st.write(f"{value} hours is equal to {result} minutes")
|
| 332 |
-
elif conversion_type == "Minutes to Hours":
|
| 333 |
-
result = minutes_to_hours(value)
|
| 334 |
-
st.write(f"{value} minutes is equal to {result} hours")
|
| 335 |
-
elif conversion_type == "Days to Hours":
|
| 336 |
-
result = days_to_hours(value)
|
| 337 |
-
st.write(f"{value} days is equal to {result} hours")
|
| 338 |
-
elif conversion_type == "Hours to Days":
|
| 339 |
-
result = hours_to_days(value)
|
| 340 |
-
st.write(f"{value} hours is equal to {result} days")
|
| 341 |
-
|
| 342 |
-
elif category == "Temperature 🌡️":
|
| 343 |
-
conversion_type = st.selectbox("Choose a temperature conversion", [
|
| 344 |
-
"Celsius to Fahrenheit",
|
| 345 |
-
"Fahrenheit to Celsius",
|
| 346 |
-
"Celsius to Kelvin",
|
| 347 |
-
"Kelvin to Celsius",
|
| 348 |
-
"Fahrenheit to Kelvin",
|
| 349 |
-
"Kelvin to Fahrenheit"
|
| 350 |
-
])
|
| 351 |
-
|
| 352 |
-
value = st.number_input("Enter the value to convert", min_value=0.0)
|
| 353 |
-
|
| 354 |
-
if conversion_type == "Celsius to Fahrenheit":
|
| 355 |
-
result = celsius_to_fahrenheit(value)
|
| 356 |
-
st.write(f"{value}°C is equal to {result}°F")
|
| 357 |
-
elif conversion_type == "Fahrenheit to Celsius":
|
| 358 |
-
result = fahrenheit_to_celsius(value)
|
| 359 |
-
st.write(f"{value}°F is equal to {result}°C")
|
| 360 |
-
elif conversion_type == "Celsius to Kelvin":
|
| 361 |
-
result = celsius_to_kelvin(value)
|
| 362 |
-
st.write(f"{value}°C is equal to {result}K")
|
| 363 |
-
elif conversion_type == "Kelvin to Celsius":
|
| 364 |
-
result = kelvin_to_celsius(value)
|
| 365 |
-
st.write(f"{value}K is equal to {result}°C")
|
| 366 |
-
elif conversion_type == "Fahrenheit to Kelvin":
|
| 367 |
-
result = fahrenheit_to_kelvin(value)
|
| 368 |
-
st.write(f"{value}°F is equal to {result}K")
|
| 369 |
-
elif conversion_type == "Kelvin to Fahrenheit":
|
| 370 |
-
result = kelvin_to_fahrenheit(value)
|
| 371 |
-
st.write(f"{value}K is equal to {result}°F")
|
| 372 |
-
|
| 373 |
-
elif category == "Pressure 💨":
|
| 374 |
-
conversion_type = st.selectbox("Choose a pressure conversion", [
|
| 375 |
-
"Pascal to ATM",
|
| 376 |
-
"ATM to Pascal",
|
| 377 |
-
"Pascal to Bar",
|
| 378 |
-
"Bar to Pascal",
|
| 379 |
-
"PSI to Pascal",
|
| 380 |
-
"Pascal to PSI"
|
| 381 |
-
])
|
| 382 |
-
|
| 383 |
-
value = st.number_input("Enter the value to convert", min_value=0.0)
|
| 384 |
-
|
| 385 |
-
if conversion_type == "Pascal to ATM":
|
| 386 |
-
result = pascal_to_atm(value)
|
| 387 |
-
st.write(f"{value} pascal is equal to {result} atm")
|
| 388 |
-
elif conversion_type == "ATM to Pascal":
|
| 389 |
-
result = atm_to_pascal(value)
|
| 390 |
-
st.write(f"{value} atm is equal to {result} pascal")
|
| 391 |
-
elif conversion_type == "Pascal to Bar":
|
| 392 |
-
result = pascal_to_bar(value)
|
| 393 |
-
st.write(f"{value} pascal is equal to {result} bar")
|
| 394 |
-
elif conversion_type == "Bar to Pascal":
|
| 395 |
-
result = bar_to_pascal(value)
|
| 396 |
-
st.write(f"{value} bar is equal to {result} pascal")
|
| 397 |
-
elif conversion_type == "PSI to Pascal":
|
| 398 |
-
result = psi_to_pascal(value)
|
| 399 |
-
st.write(f"{value} psi is equal to {result} pascal")
|
| 400 |
-
elif conversion_type == "Pascal to PSI":
|
| 401 |
-
result = pascal_to_psi(value)
|
| 402 |
-
st.write(f"{value} pascal is equal to {result} psi")
|
| 403 |
-
|
| 404 |
-
elif category == "Energy ⚡":
|
| 405 |
-
conversion_type = st.selectbox("Choose an energy conversion", [
|
| 406 |
-
"Joule to Calorie",
|
| 407 |
-
"Calorie to Joule",
|
| 408 |
-
"Joule to Kilojoule",
|
| 409 |
-
"Kilojoule to Joule",
|
| 410 |
-
"Watt-hour to Joule",
|
| 411 |
-
"Joule to Watt-hour"
|
| 412 |
-
])
|
| 413 |
-
|
| 414 |
-
value = st.number_input("Enter the value to convert", min_value=0.0)
|
| 415 |
-
|
| 416 |
-
if conversion_type == "Joule to Calorie":
|
| 417 |
-
result = joule_to_calorie(value)
|
| 418 |
-
st.write(f"{value} joules is equal to {result} calories")
|
| 419 |
-
elif conversion_type == "Calorie to Joule":
|
| 420 |
-
result = calorie_to_joule(value)
|
| 421 |
-
st.write(f"{value} calories is equal to {result} joules")
|
| 422 |
-
elif conversion_type == "Joule to Kilojoule":
|
| 423 |
-
result = joule_to_kilojoule(value)
|
| 424 |
-
st.write(f"{value} joules is equal to {result} kilojoules")
|
| 425 |
-
elif conversion_type == "Kilojoule to Joule":
|
| 426 |
-
result = kilojoule_to_joule(value)
|
| 427 |
-
st.write(f"{value} kilojoules is equal to {result} joules")
|
| 428 |
-
elif conversion_type == "Watt-hour to Joule":
|
| 429 |
-
result = watt_hour_to_joule(value)
|
| 430 |
-
st.write(f"{value} watt-hours is equal to {result} joules")
|
| 431 |
-
elif conversion_type == "Joule to Watt-hour":
|
| 432 |
-
result = joule_to_watt_hour(value)
|
| 433 |
-
st.write(f"{value} joules is equal to {result} watt-hours")
|
| 434 |
-
|
| 435 |
-
elif category == "Power 💪":
|
| 436 |
-
conversion_type = st.selectbox("Choose a power conversion", [
|
| 437 |
-
"Watt to Horsepower",
|
| 438 |
-
"Horsepower to Watt",
|
| 439 |
-
"Watt to Kilowatt",
|
| 440 |
-
"Kilowatt to Watt",
|
| 441 |
-
"Joule per Second to Watt",
|
| 442 |
-
"Watt to Joule per Second"
|
| 443 |
-
])
|
| 444 |
-
|
| 445 |
-
value = st.number_input("Enter the value to convert", min_value=0.0)
|
| 446 |
-
|
| 447 |
-
if conversion_type == "Watt to Horsepower":
|
| 448 |
-
result = watt_to_horsepower(value)
|
| 449 |
-
st.write(f"{value} watts is equal to {result} horsepower")
|
| 450 |
-
elif conversion_type == "Horsepower to Watt":
|
| 451 |
-
result = horsepower_to_watt(value)
|
| 452 |
-
st.write(f"{value} horsepower is equal to {result} watts")
|
| 453 |
-
elif conversion_type == "Watt to Kilowatt":
|
| 454 |
-
result = watt_to_kilowatt(value)
|
| 455 |
-
st.write(f"{value} watts is equal to {result} kilowatts")
|
| 456 |
-
elif conversion_type == "Kilowatt to Watt":
|
| 457 |
-
result = kilowatt_to_watt(value)
|
| 458 |
-
st.write(f"{value} kilowatts is equal to {result} watts")
|
| 459 |
-
elif conversion_type == "Joule per Second to Watt":
|
| 460 |
-
result = joule_per_second_to_watt(value)
|
| 461 |
-
st.write(f"{value} joules per second is equal to {result} watts")
|
| 462 |
-
elif conversion_type == "Watt to Joule per Second":
|
| 463 |
-
result = watt_to_joule_per_second(value)
|
| 464 |
-
st.write(f"{value} watts is equal to {result} joules per second")
|
| 465 |
-
|
| 466 |
-
elif category == "Volume 🧃":
|
| 467 |
-
conversion_type = st.selectbox("Choose a volume conversion", [
|
| 468 |
-
"Liter to Milliliter",
|
| 469 |
-
"Milliliter to Liter",
|
| 470 |
-
"Gallon to Liter",
|
| 471 |
-
"Liter to Gallon",
|
| 472 |
-
"Cubic Meter to Liter",
|
| 473 |
-
"Liter to Cubic Meter"
|
| 474 |
-
])
|
| 475 |
-
|
| 476 |
-
value = st.number_input("Enter the value to convert", min_value=0.0)
|
| 477 |
-
|
| 478 |
-
if conversion_type == "Liter to Milliliter":
|
| 479 |
-
result = liter_to_milliliter(value)
|
| 480 |
-
st.write(f"{value} liter is equal to {result} milliliters")
|
| 481 |
-
elif conversion_type == "Milliliter to Liter":
|
| 482 |
-
result = milliliter_to_liter(value)
|
| 483 |
-
st.write(f"{value} milliliters is equal to {result} liters")
|
| 484 |
-
elif conversion_type == "Gallon to Liter":
|
| 485 |
-
result = gallon_to_liter(value)
|
| 486 |
-
st.write(f"{value} gallons is equal to {result} liters")
|
| 487 |
-
elif conversion_type == "Liter to Gallon":
|
| 488 |
-
result = liter_to_gallon(value)
|
| 489 |
-
st.write(f"{value} liters is equal to {result} gallons")
|
| 490 |
-
elif conversion_type == "Cubic Meter to Liter":
|
| 491 |
-
result = cubic_meter_to_liter(value)
|
| 492 |
-
st.write(f"{value} cubic meters is equal to {result} liters")
|
| 493 |
-
elif conversion_type == "Liter to Cubic Meter":
|
| 494 |
-
result = liter_to_cubic_meter(value)
|
| 495 |
-
st.write(f"{value} liters is equal to {result} cubic meters")
|
| 496 |
-
|
| 497 |
-
elif category == "Speed 🚗":
|
| 498 |
-
conversion_type = st.selectbox("Choose a speed conversion", [
|
| 499 |
-
"Kilometer per Hour to Meter per Second",
|
| 500 |
-
"Meter per Second to Kilometer per Hour",
|
| 501 |
-
"Mile per Hour to Kilometer per Hour",
|
| 502 |
-
"Kilometer per Hour to Mile per Hour"
|
| 503 |
-
])
|
| 504 |
-
|
| 505 |
-
value = st.number_input("Enter the value to convert", min_value=0.0)
|
| 506 |
-
|
| 507 |
-
if conversion_type == "Kilometer per Hour to Meter per Second":
|
| 508 |
-
result = kilometer_per_hour_to_meter_per_second(value)
|
| 509 |
-
st.write(f"{value} km/h is equal to {result} m/s")
|
| 510 |
-
elif conversion_type == "Meter per Second to Kilometer per Hour":
|
| 511 |
-
result = meter_per_second_to_kilometer_per_hour(value)
|
| 512 |
-
st.write(f"{value} m/s is equal to {result} km/h")
|
| 513 |
-
elif conversion_type == "Mile per Hour to Kilometer per Hour":
|
| 514 |
-
result = mile_per_hour_to_kilometer_per_hour(value)
|
| 515 |
-
st.write(f"{value} mph is equal to {result} km/h")
|
| 516 |
-
elif conversion_type == "Kilometer per Hour to Mile per Hour":
|
| 517 |
-
result = kilometer_per_hour_to_mile_per_hour(value)
|
| 518 |
-
st.write(f"{value} km/h is equal to {result} mph")
|
|
|
|
| 1 |
import streamlit as st
|
| 2 |
+
import math
|
| 3 |
|
| 4 |
# Conversion functions
|
| 5 |
# Length conversions
|
|
|
|
| 194 |
def kilometer_per_hour_to_mile_per_hour(kmph):
|
| 195 |
return kmph / 1.60934
|
| 196 |
|
| 197 |
+
# Angle conversions
|
| 198 |
+
def radians_to_degrees(radians):
|
| 199 |
+
return radians * (180 / math.pi)
|
| 200 |
+
|
| 201 |
+
def degrees_to_radians(degrees):
|
| 202 |
+
return degrees * (math.pi / 180)
|
| 203 |
+
|
| 204 |
+
# Frequency conversions
|
| 205 |
+
def hertz_to_kilohertz(hertz):
|
| 206 |
+
return hertz / 1000
|
| 207 |
+
|
| 208 |
+
def kilohertz_to_hertz(kilohertz):
|
| 209 |
+
return kilohertz * 1000
|
| 210 |
+
|
| 211 |
+
def hertz_to_megahertz(hertz):
|
| 212 |
+
return hertz / 1e6
|
| 213 |
+
|
| 214 |
+
def megahertz_to_hertz(megahertz):
|
| 215 |
+
return megahertz * 1e6
|
| 216 |
+
|
| 217 |
# Streamlit UI
|
| 218 |
st.title("Unit Conversion App 🧮")
|
| 219 |
|
|
|
|
| 227 |
"Energy ⚡",
|
| 228 |
"Power 💪",
|
| 229 |
"Volume 🧃",
|
| 230 |
+
"Speed 🚗",
|
| 231 |
+
"Angle 🔺",
|
| 232 |
+
"Frequency 📶"
|
| 233 |
])
|
| 234 |
|
| 235 |
# Based on the selected category, add a selectbox for the specific conversion
|
|
|
|
| 292 |
result = meter_to_centimeter(value)
|
| 293 |
st.write(f"{value} meters is equal to {result} centimeters")
|
| 294 |
|
| 295 |
+
# Continue in a similar pattern for other categories like Weight, Time, Temperature, etc...
|
| 296 |
+
# For brevity, I'll leave the rest of the categories as is, but feel free to add more conversions.
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
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