Cline AI Assistant
commited on
Commit
·
2eeb731
1
Parent(s):
e9373f6
Upload Mars pressure prediction model and documentation
Browse files- app.py +82 -0
- model/mars_pressure_model.joblib +2 -2
- requirements.txt +7 -0
app.py
ADDED
@@ -0,0 +1,82 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
import gradio as gr
|
2 |
+
import joblib
|
3 |
+
import numpy as np
|
4 |
+
import pandas as pd
|
5 |
+
|
6 |
+
# Load the model and scaler
|
7 |
+
model_info = joblib.load('model/mars_pressure_model.joblib')
|
8 |
+
model = model_info['model']
|
9 |
+
scaler = model_info['scaler']
|
10 |
+
feature_columns = model_info['feature_columns']
|
11 |
+
|
12 |
+
def predict_pressure(max_ground_temp, min_ground_temp, max_air_temp, min_air_temp, month):
|
13 |
+
# Create a feature dictionary
|
14 |
+
features = {
|
15 |
+
'max_ground_temp(°C)': float(max_ground_temp),
|
16 |
+
'min_ground_temp(°C)': float(min_ground_temp),
|
17 |
+
'max_air_temp(°C)': float(max_air_temp),
|
18 |
+
'min_air_temp(°C)': float(min_air_temp),
|
19 |
+
'earth_month': float(month),
|
20 |
+
'earth_day': 15 # Use middle of month as default
|
21 |
+
}
|
22 |
+
|
23 |
+
# Add season features
|
24 |
+
season = (month % 12) // 3
|
25 |
+
seasons = ['Winter', 'Spring', 'Summer', 'Fall']
|
26 |
+
for s in seasons:
|
27 |
+
features[f'season_{s}'] = 1.0 if seasons[season] == s else 0.0
|
28 |
+
|
29 |
+
# Create DataFrame with correct column order
|
30 |
+
X = pd.DataFrame([features])[feature_columns]
|
31 |
+
|
32 |
+
# Scale features
|
33 |
+
X_scaled = scaler.transform(X)
|
34 |
+
|
35 |
+
# Make prediction
|
36 |
+
prediction = model.predict(X_scaled)[0]
|
37 |
+
|
38 |
+
# Calculate uncertainty
|
39 |
+
uncertainty = model_info['metrics']['prediction_std']
|
40 |
+
|
41 |
+
return (
|
42 |
+
f"{prediction:.1f} Pa",
|
43 |
+
f"({prediction-uncertainty:.1f} to {prediction+uncertainty:.1f} Pa)",
|
44 |
+
f"±{uncertainty:.1f} Pa"
|
45 |
+
)
|
46 |
+
|
47 |
+
# Create the interface
|
48 |
+
iface = gr.Interface(
|
49 |
+
fn=predict_pressure,
|
50 |
+
inputs=[
|
51 |
+
gr.Slider(-70, 20, value=-13, label="Maximum Ground Temperature (°C)"),
|
52 |
+
gr.Slider(-100, -50, value=-75, label="Minimum Ground Temperature (°C)"),
|
53 |
+
gr.Slider(-60, 30, value=2, label="Maximum Air Temperature (°C)"),
|
54 |
+
gr.Slider(-140, -5, value=-80, label="Minimum Air Temperature (°C)"),
|
55 |
+
gr.Slider(1, 12, step=1, value=6, label="Month (1-12)")
|
56 |
+
],
|
57 |
+
outputs=[
|
58 |
+
gr.Label(label="Predicted Atmospheric Pressure"),
|
59 |
+
gr.Label(label="Prediction Range"),
|
60 |
+
gr.Label(label="Uncertainty")
|
61 |
+
],
|
62 |
+
title="Mars Atmospheric Pressure Predictor",
|
63 |
+
description="""
|
64 |
+
Predict atmospheric pressure on Mars based on environmental measurements.
|
65 |
+
Default values are set to typical conditions observed in the dataset.
|
66 |
+
The model has an R² score of 0.397 and provides uncertainty estimates.
|
67 |
+
""",
|
68 |
+
examples=[
|
69 |
+
[-13, -75, 2, -80, 6], # Average conditions
|
70 |
+
[11, -52, 24, -8, 3], # Warmest conditions
|
71 |
+
[-67, -100, -61, -136, 12] # Coldest conditions
|
72 |
+
]
|
73 |
+
)
|
74 |
+
|
75 |
+
# Launch the app with specific configurations for HuggingFace Spaces
|
76 |
+
if __name__ == "__main__":
|
77 |
+
iface.launch(
|
78 |
+
server_name="0.0.0.0",
|
79 |
+
server_port=7860, # Default port for HuggingFace Spaces
|
80 |
+
share=False,
|
81 |
+
show_error=True
|
82 |
+
)
|
model/mars_pressure_model.joblib
CHANGED
@@ -1,3 +1,3 @@
|
|
1 |
version https://git-lfs.github.com/spec/v1
|
2 |
-
oid sha256:
|
3 |
-
size
|
|
|
1 |
version https://git-lfs.github.com/spec/v1
|
2 |
+
oid sha256:6008323411642a4e5e47ccd3548f08724bebc0c0ef562b96937900077f2fc111
|
3 |
+
size 6899580
|
requirements.txt
ADDED
@@ -0,0 +1,7 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
gradio==3.41.0
|
2 |
+
numpy==1.24.1
|
3 |
+
pandas==1.5.3
|
4 |
+
scikit-learn==1.2.1
|
5 |
+
joblib==1.2.0
|
6 |
+
typing-extensions==4.5.0
|
7 |
+
python-multipart==0.0.6
|