ahmad123445 commited on
Commit
a680b9d
·
verified ·
1 Parent(s): 46e6c8c

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +64 -0
app.py CHANGED
@@ -0,0 +1,64 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import streamlit as st
2
+
3
+ def convert_temperature(value, from_scale, to_scale):
4
+ try:
5
+ value = float(value)
6
+
7
+ # Same unit conversion
8
+ if from_scale == to_scale:
9
+ return value
10
+
11
+ # Celsius conversions
12
+ if from_scale == "Celsius":
13
+ if to_scale == "Kelvin":
14
+ return value + 273.15
15
+ elif to_scale == "Fahrenheit":
16
+ return (value * 9 / 5) + 32
17
+ elif to_scale == "Rankine":
18
+ return (value + 273.15) * 9 / 5
19
+
20
+ # Kelvin conversions
21
+ if from_scale == "Kelvin":
22
+ if to_scale == "Celsius":
23
+ return value - 273.15
24
+ elif to_scale == "Fahrenheit":
25
+ return (value - 273.15) * 9 / 5 + 32
26
+ elif to_scale == "Rankine":
27
+ return value * 9 / 5
28
+
29
+ # Fahrenheit conversions
30
+ if from_scale == "Fahrenheit":
31
+ if to_scale == "Celsius":
32
+ return (value - 32) * 5 / 9
33
+ elif to_scale == "Kelvin":
34
+ return (value - 32) * 5 / 9 + 273.15
35
+ elif to_scale == "Rankine":
36
+ return value + 459.67
37
+
38
+ # Rankine conversions
39
+ if from_scale == "Rankine":
40
+ if to_scale == "Celsius":
41
+ return (value - 491.67) * 5 / 9
42
+ elif to_scale == "Kelvin":
43
+ return value * 5 / 9
44
+ elif to_scale == "Fahrenheit":
45
+ return value - 459.67
46
+
47
+ return "Conversion not supported!"
48
+ except ValueError:
49
+ return "Invalid input! Please enter a numeric value."
50
+
51
+ # Streamlit App GUI
52
+ st.title("Temperature Conversion App")
53
+ st.subheader("Developed by Ahmad Hassan")
54
+ st.caption("Supervised by Dr. Hidayatullah Mahar")
55
+
56
+ # Input fields
57
+ temp_value = st.text_input("Enter Temperature Value:")
58
+ from_scale = st.selectbox("Convert From", ["Celsius", "Kelvin", "Fahrenheit", "Rankine"])
59
+ to_scale = st.selectbox("Convert To", ["Celsius", "Kelvin", "Fahrenheit", "Rankine"])
60
+
61
+ # Conversion logic
62
+ if st.button("Convert"):
63
+ result = convert_temperature(temp_value, from_scale, to_scale)
64
+ st.success(f"Converted Value: {result}")