MuhammadHananKhan123 commited on
Commit
34398d0
·
verified ·
1 Parent(s): d39e161

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +45 -37
app.py CHANGED
@@ -1,39 +1,47 @@
 
1
  import streamlit as st
2
- import random
3
-
4
- # Simulated Gas Sensor Data (You can replace this with real sensor integration)
5
- def get_gas_data():
6
- gas_data = {
7
- "CO2 (Carbon Dioxide)": random.uniform(300, 500), # in ppm
8
- "O2 (Oxygen)": random.uniform(19, 21), # in %
9
- "N2 (Nitrogen)": random.uniform(78, 80), # in %
10
- "CFC (Chlorofluorocarbons)": random.uniform(0, 0.5), # in ppm
11
- "CO (Carbon Monoxide)": random.uniform(0, 10), # in ppm
12
- "SO2 (Sulfur Dioxide)": random.uniform(0, 5), # in ppm
13
- "NO (Nitric Oxide)": random.uniform(0, 5), # in ppm
 
 
 
 
 
 
 
 
 
 
 
14
  }
15
- return gas_data
16
-
17
- # Streamlit App Layout
18
- st.title("Gas Mixture Sensor")
19
- st.write("This app simulates a sensor that detects the mixture of gases in the surrounding air.")
20
-
21
- st.header("Detected Gas Levels")
22
- gas_data = get_gas_data()
23
- for gas, value in gas_data.items():
24
- if gas in ["O2 (Oxygen)", "N2 (Nitrogen)"]:
25
- unit = "%"
26
- else:
27
- unit = "ppm"
28
- st.metric(label=gas, value=f"{value:.2f} {unit}")
29
-
30
- st.sidebar.header("Settings")
31
- st.sidebar.write("Adjust the simulation parameters below.")
32
- refresh_rate = st.sidebar.slider("Refresh Rate (seconds)", 1, 10, 5)
33
-
34
- st.sidebar.write("Note: Values are simulated and change on every refresh.")
35
- st.sidebar.caption("This app is for demonstration purposes only.")
36
-
37
- # Auto-refresh the app based on the slider value
38
- st.experimental_set_query_params(refresh_rate=refresh_rate)
39
- st.stop() # Prevents an infinite loop of refresh
 
1
+ # app.py
2
  import streamlit as st
3
+
4
+ def adjust_ratios(components):
5
+ """Adjusts the ratio of each component."""
6
+ st.write("### Adjust Air Mixture Components")
7
+ adjusted_components = {}
8
+ for component, value in components.items():
9
+ adjusted_value = st.slider(
10
+ label=f"{component} Ratio (%)", min_value=0, max_value=100, value=int(value)
11
+ )
12
+ adjusted_components[component] = adjusted_value
13
+ return adjusted_components
14
+
15
+ def main():
16
+ st.title("Air Mixture Adjustment App")
17
+ st.write("This app allows you to sense and adjust the ratio of each component in an air mixture.")
18
+
19
+ # Simulate sensing air mixture (replace with actual sensing functionality if available)
20
+ st.write("### Sensed Air Components")
21
+ sensed_components = {
22
+ "Nitrogen": 78,
23
+ "Oxygen": 21,
24
+ "Carbon Dioxide": 0.04,
25
+ "Argon": 0.93
26
  }
27
+
28
+ # Display sensed components
29
+ for component, value in sensed_components.items():
30
+ st.write(f"{component}: {value}%")
31
+
32
+ # Adjust components
33
+ adjusted_components = adjust_ratios(sensed_components)
34
+
35
+ # Ensure the sum of the components is 100%
36
+ total = sum(adjusted_components.values())
37
+ if total != 100:
38
+ st.warning("The total percentage does not equal 100%. Please adjust the values.")
39
+
40
+ # Display adjusted components
41
+ st.write("### Final Adjusted Components")
42
+ for component, value in adjusted_components.items():
43
+ st.write(f"{component}: {value}%")
44
+
45
+ if __name__ == "__main__":
46
+ main()
47
+