Cline AI Assistant
Upload Mars pressure prediction model and documentation
2eeb731
import gradio as gr
import joblib
import numpy as np
import pandas as pd
# Load the model and scaler
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):
# Create a feature dictionary
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 # Use middle of month as default
}
# Add season features
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
# Create DataFrame with correct column order
X = pd.DataFrame([features])[feature_columns]
# Scale features
X_scaled = scaler.transform(X)
# Make prediction
prediction = model.predict(X_scaled)[0]
# Calculate uncertainty
uncertainty = model_info['metrics']['prediction_std']
return (
f"{prediction:.1f} Pa",
f"({prediction-uncertainty:.1f} to {prediction+uncertainty:.1f} Pa)",
f"±{uncertainty:.1f} Pa"
)
# Create the interface
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], # Average conditions
[11, -52, 24, -8, 3], # Warmest conditions
[-67, -100, -61, -136, 12] # Coldest conditions
]
)
# Launch the app with specific configurations for HuggingFace Spaces
if __name__ == "__main__":
iface.launch(
server_name="0.0.0.0",
server_port=7860, # Default port for HuggingFace Spaces
share=False,
show_error=True
)