mishiawan commited on
Commit
141900d
·
verified ·
1 Parent(s): e7d4712

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +121 -33
app.py CHANGED
@@ -161,22 +161,56 @@ def joule_per_second_to_watt(joules_per_second):
161
  def watt_to_joule_per_second(watts):
162
  return watts
163
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
164
  # Streamlit UI
165
- st.title("Unit Conversion App")
166
 
167
  # Add selectbox for the type of conversion category
168
  category = st.selectbox("Choose a conversion category", [
169
- "Length",
170
- "Weight",
171
- "Time",
172
- "Temperature",
173
- "Pressure",
174
- "Energy",
175
- "Power"
 
 
176
  ])
177
 
178
  # Based on the selected category, add a selectbox for the specific conversion
179
- if category == "Length":
180
  conversion_type = st.selectbox("Choose a length conversion", [
181
  "Micrometers to Nanometers",
182
  "Angstroms to Nanometers",
@@ -235,7 +269,7 @@ if category == "Length":
235
  result = meter_to_centimeter(value)
236
  st.write(f"{value} meters is equal to {result} centimeters")
237
 
238
- elif category == "Weight":
239
  conversion_type = st.selectbox("Choose a weight conversion", [
240
  "Gram to Kilogram",
241
  "Kilogram to Gram",
@@ -274,7 +308,7 @@ elif category == "Weight":
274
  result = gram_to_ounce(value)
275
  st.write(f"{value} grams is equal to {result} ounces")
276
 
277
- elif category == "Time":
278
  conversion_type = st.selectbox("Choose a time conversion", [
279
  "Seconds to Minutes",
280
  "Minutes to Seconds",
@@ -305,7 +339,7 @@ elif category == "Time":
305
  result = hours_to_days(value)
306
  st.write(f"{value} hours is equal to {result} days")
307
 
308
- elif category == "Temperature":
309
  conversion_type = st.selectbox("Choose a temperature conversion", [
310
  "Celsius to Fahrenheit",
311
  "Fahrenheit to Celsius",
@@ -325,18 +359,18 @@ elif category == "Temperature":
325
  st.write(f"{value}°F is equal to {result}°C")
326
  elif conversion_type == "Celsius to Kelvin":
327
  result = celsius_to_kelvin(value)
328
- st.write(f"{value}°C is equal to {result} K")
329
  elif conversion_type == "Kelvin to Celsius":
330
  result = kelvin_to_celsius(value)
331
- st.write(f"{value} K is equal to {result}°C")
332
  elif conversion_type == "Fahrenheit to Kelvin":
333
  result = fahrenheit_to_kelvin(value)
334
- st.write(f"{value}°F is equal to {result} K")
335
  elif conversion_type == "Kelvin to Fahrenheit":
336
  result = kelvin_to_fahrenheit(value)
337
- st.write(f"{value} K is equal to {result}°F")
338
 
339
- elif category == "Pressure":
340
  conversion_type = st.selectbox("Choose a pressure conversion", [
341
  "Pascal to ATM",
342
  "ATM to Pascal",
@@ -350,31 +384,31 @@ elif category == "Pressure":
350
 
351
  if conversion_type == "Pascal to ATM":
352
  result = pascal_to_atm(value)
353
- st.write(f"{value} pascals is equal to {result} atmospheres")
354
  elif conversion_type == "ATM to Pascal":
355
  result = atm_to_pascal(value)
356
- st.write(f"{value} atmospheres is equal to {result} pascals")
357
  elif conversion_type == "Pascal to Bar":
358
  result = pascal_to_bar(value)
359
- st.write(f"{value} pascals is equal to {result} bars")
360
  elif conversion_type == "Bar to Pascal":
361
  result = bar_to_pascal(value)
362
- st.write(f"{value} bars is equal to {result} pascals")
363
  elif conversion_type == "PSI to Pascal":
364
  result = psi_to_pascal(value)
365
- st.write(f"{value} PSI is equal to {result} pascals")
366
  elif conversion_type == "Pascal to PSI":
367
  result = pascal_to_psi(value)
368
- st.write(f"{value} pascals is equal to {result} PSI")
369
 
370
- elif category == "Energy":
371
  conversion_type = st.selectbox("Choose an energy conversion", [
372
  "Joule to Calorie",
373
  "Calorie to Joule",
374
  "Joule to Kilojoule",
375
  "Kilojoule to Joule",
376
- "Watt-Hour to Joule",
377
- "Joule to Watt-Hour"
378
  ])
379
 
380
  value = st.number_input("Enter the value to convert", min_value=0.0)
@@ -391,21 +425,21 @@ elif category == "Energy":
391
  elif conversion_type == "Kilojoule to Joule":
392
  result = kilojoule_to_joule(value)
393
  st.write(f"{value} kilojoules is equal to {result} joules")
394
- elif conversion_type == "Watt-Hour to Joule":
395
  result = watt_hour_to_joule(value)
396
  st.write(f"{value} watt-hours is equal to {result} joules")
397
- elif conversion_type == "Joule to Watt-Hour":
398
  result = joule_to_watt_hour(value)
399
  st.write(f"{value} joules is equal to {result} watt-hours")
400
 
401
- elif category == "Power":
402
  conversion_type = st.selectbox("Choose a power conversion", [
403
  "Watt to Horsepower",
404
  "Horsepower to Watt",
405
  "Watt to Kilowatt",
406
  "Kilowatt to Watt",
407
- "Joule per second to Watt",
408
- "Watt to Joule per second"
409
  ])
410
 
411
  value = st.number_input("Enter the value to convert", min_value=0.0)
@@ -422,9 +456,63 @@ elif category == "Power":
422
  elif conversion_type == "Kilowatt to Watt":
423
  result = kilowatt_to_watt(value)
424
  st.write(f"{value} kilowatts is equal to {result} watts")
425
- elif conversion_type == "Joule per second to Watt":
426
  result = joule_per_second_to_watt(value)
427
  st.write(f"{value} joules per second is equal to {result} watts")
428
- elif conversion_type == "Watt to Joule per second":
429
  result = watt_to_joule_per_second(value)
430
  st.write(f"{value} watts is equal to {result} joules per second")
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
161
  def watt_to_joule_per_second(watts):
162
  return watts
163
 
164
+ # Volume conversions
165
+ def liter_to_milliliter(liters):
166
+ return liters * 1000
167
+
168
+ def milliliter_to_liter(milliliters):
169
+ return milliliters / 1000
170
+
171
+ def gallon_to_liter(gallons):
172
+ return gallons * 3.78541
173
+
174
+ def liter_to_gallon(liters):
175
+ return liters / 3.78541
176
+
177
+ def cubic_meter_to_liter(cubic_meters):
178
+ return cubic_meters * 1000
179
+
180
+ def liter_to_cubic_meter(liters):
181
+ return liters / 1000
182
+
183
+ # Speed conversions
184
+ def kilometer_per_hour_to_meter_per_second(kmph):
185
+ return kmph / 3.6
186
+
187
+ def meter_per_second_to_kilometer_per_hour(mps):
188
+ return mps * 3.6
189
+
190
+ def mile_per_hour_to_kilometer_per_hour(mph):
191
+ return mph * 1.60934
192
+
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
 
199
  # Add selectbox for the type of conversion category
200
  category = st.selectbox("Choose a conversion category", [
201
+ "Length 📏",
202
+ "Weight ⚖️",
203
+ "Time",
204
+ "Temperature 🌡️",
205
+ "Pressure 💨",
206
+ "Energy",
207
+ "Power 💪",
208
+ "Volume 🧃",
209
+ "Speed 🚗"
210
  ])
211
 
212
  # Based on the selected category, add a selectbox for the specific conversion
213
+ if category == "Length 📏":
214
  conversion_type = st.selectbox("Choose a length conversion", [
215
  "Micrometers to Nanometers",
216
  "Angstroms to Nanometers",
 
269
  result = meter_to_centimeter(value)
270
  st.write(f"{value} meters is equal to {result} centimeters")
271
 
272
+ elif category == "Weight ⚖️":
273
  conversion_type = st.selectbox("Choose a weight conversion", [
274
  "Gram to Kilogram",
275
  "Kilogram to Gram",
 
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",
 
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",
 
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",
 
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)
 
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)
 
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")