Spaces:
Sleeping
Sleeping
| import joblib | |
| import pandas as pd | |
| import gradio as gr | |
| # π Lade das neue Modell | |
| model = joblib.load("random_forest_regression_neu.pkl") | |
| # π Funktion zur Vorhersage | |
| def predict_price(rooms, area, pop_dens, has_balcony): | |
| input_data = pd.DataFrame([[rooms, area, pop_dens, has_balcony]], | |
| columns=model.feature_names_in_) | |
| prediction = model.predict(input_data)[0] | |
| return f"Predicted price: {prediction:.2f} CHF" | |
| # π Gradio UI | |
| demo = gr.Interface( | |
| fn=predict_price, | |
| inputs=[ | |
| gr.Number(label="Rooms"), | |
| gr.Number(label="Area (mΒ²)"), | |
| gr.Number(label="Population Density"), | |
| gr.Number(label="Has Balcony (0 = No, 1 = Yes)") | |
| ], | |
| outputs="text", | |
| ) | |
| # π Starte die Web-App | |
| demo.launch() | |