|
import gradio as gr |
|
import joblib |
|
import numpy as np |
|
import pandas as pd |
|
|
|
|
|
model_info = joblib.load('model/mars_pressure_model.joblib') |
|
model = model_info['model'] |
|
scaler = model_info['scaler'] |
|
feature_columns = model_info['feature_columns'] |
|
|
|
def predict_pressure(max_ground_temp, min_ground_temp, max_air_temp, min_air_temp, month): |
|
|
|
features = { |
|
'max_ground_temp(°C)': float(max_ground_temp), |
|
'min_ground_temp(°C)': float(min_ground_temp), |
|
'max_air_temp(°C)': float(max_air_temp), |
|
'min_air_temp(°C)': float(min_air_temp), |
|
'earth_month': float(month), |
|
'earth_day': 15 |
|
} |
|
|
|
|
|
season = (month % 12) // 3 |
|
seasons = ['Winter', 'Spring', 'Summer', 'Fall'] |
|
for s in seasons: |
|
features[f'season_{s}'] = 1.0 if seasons[season] == s else 0.0 |
|
|
|
|
|
X = pd.DataFrame([features])[feature_columns] |
|
|
|
|
|
X_scaled = scaler.transform(X) |
|
|
|
|
|
prediction = model.predict(X_scaled)[0] |
|
|
|
|
|
uncertainty = model_info['metrics']['prediction_std'] |
|
|
|
return ( |
|
f"{prediction:.1f} Pa", |
|
f"({prediction-uncertainty:.1f} to {prediction+uncertainty:.1f} Pa)", |
|
f"±{uncertainty:.1f} Pa" |
|
) |
|
|
|
|
|
iface = gr.Interface( |
|
fn=predict_pressure, |
|
inputs=[ |
|
gr.Slider(-70, 20, value=-13, label="Maximum Ground Temperature (°C)"), |
|
gr.Slider(-100, -50, value=-75, label="Minimum Ground Temperature (°C)"), |
|
gr.Slider(-60, 30, value=2, label="Maximum Air Temperature (°C)"), |
|
gr.Slider(-140, -5, value=-80, label="Minimum Air Temperature (°C)"), |
|
gr.Slider(1, 12, step=1, value=6, label="Month (1-12)") |
|
], |
|
outputs=[ |
|
gr.Label(label="Predicted Atmospheric Pressure"), |
|
gr.Label(label="Prediction Range"), |
|
gr.Label(label="Uncertainty") |
|
], |
|
title="Mars Atmospheric Pressure Predictor", |
|
description=""" |
|
Predict atmospheric pressure on Mars based on environmental measurements. |
|
Default values are set to typical conditions observed in the dataset. |
|
The model has an R² score of 0.397 and provides uncertainty estimates. |
|
""", |
|
examples=[ |
|
[-13, -75, 2, -80, 6], |
|
[11, -52, 24, -8, 3], |
|
[-67, -100, -61, -136, 12] |
|
] |
|
) |
|
|
|
|
|
if __name__ == "__main__": |
|
iface.launch( |
|
server_name="0.0.0.0", |
|
server_port=7860, |
|
share=False, |
|
show_error=True |
|
) |
|
|