Spaces:
Runtime error
Runtime error
| import gradio as gr | |
| import pickle | |
| import numpy as np | |
| # Load your model (update the path to your downloaded model) | |
| model_path = "model.pkl" # Change this to the path of your trained model | |
| with open(model_path, 'rb') as f: | |
| model = pickle.load(f) | |
| # Function to make predictions | |
| def predict_calories(age, height, weight, gender, job_type, goal): | |
| # You can customize this function based on how you trained the model | |
| # Convert input features into a numpy array or data structure required by the model | |
| # Here's a basic example assuming your model expects numeric features | |
| gender_map = {"muž": 0, "žena": 1} # Example gender encoding | |
| job_type_map = { | |
| 'Študent': 0, | |
| 'Sedavé': 1, | |
| 'Málo pohybu (do 2500 krokov)': 2, | |
| 'Stredne pohybu (do 5000 krokov)': 3, | |
| 'Veľa pohybu (do 10000 krokov)': 4, | |
| } | |
| # Prepare the input data in the format your model expects | |
| input_data = np.array([[age, height, weight, gender_map.get(gender, 0), job_type_map.get(job_type, 0), goal]]) | |
| # Predict using the loaded model | |
| prediction = model.predict(input_data) | |
| return f"Recommended Daily Calories: {prediction[0]:.2f} kcal" | |
| # Define Gradio interface | |
| interface = gr.Interface( | |
| fn=predict_calories, | |
| inputs=[ | |
| gr.Slider(minimum=18, maximum=100, label="Age", default=25), | |
| gr.Slider(minimum=120, maximum=250, label="Height (cm)", default=170), | |
| gr.Slider(minimum=30, maximum=200, label="Weight (kg)", default=70), | |
| gr.Radio(["muž", "žena"], label="Gender", default="muž"), | |
| gr.Dropdown( | |
| ["Študent", "Sedavé", "Málo pohybu (do 2500 krokov)", "Stredne pohybu (do 5000 krokov)", "Veľa pohybu (do 10000 krokov)"], | |
| label="Job Type", | |
| default="Sedavé" | |
| ), | |
| gr.Radio(["Znížiť váhu", "Udržať váhu", "Pribrať na váhe"], label="Goal", default="Udržať váhu"), | |
| ], | |
| outputs="text", | |
| live=True, | |
| ) | |
| # Launch the interface | |
| interface.launch() | |