Spaces:
Sleeping
Sleeping
File size: 1,611 Bytes
bf3366a 465b9da bf3366a 465b9da bf3366a 465b9da bf3366a 465b9da bf3366a 465b9da bf3366a 465b9da bf3366a 465b9da bf3366a 465b9da bf3366a 465b9da bf3366a 465b9da bf3366a 465b9da bf3366a |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 |
import gradio as gr
import pandas as pd
import numpy as np
from pycaret.regression import load_model, predict_model # Change to regression if needed
# Load your dataframe
df = pd.read_csv("data.csv") # Replace with your actual data file
# Identify columns
input_columns = df.columns[:-1].tolist() # First 4 columns as input
target_column = df.columns[-1] # Last column as target
# Min-Max scaling per column
min_max_dict = {
col: (df[col].min(), df[col].max()) for col in input_columns
}
# Load your PyCaret model
model = load_model("TVAESynthesizer_best") # Replace with your actual saved model
def pycaret_predict_function(inputs):
# Convert input list to DataFrame
input_data = pd.DataFrame([inputs], columns=input_columns)
# Predict using PyCaret model
prediction = predict_model(model, data=input_data)
return prediction[target_column].values[0]
# Create Gradio inputs dynamically based on scaled range
input_components = [
gr.Slider(
minimum=min_max_dict[col][0],
maximum=min_max_dict[col][1],
step=(min_max_dict[col][1] - min_max_dict[col][0]) / 100,
label=col,
) for col in input_columns
]
# Gradio UI
with gr.Blocks() as demo:
gr.Markdown("## 🔮 Predict the Target Variable using PyCaret Model")
with gr.Row():
inputs = [component.render() for component in input_components]
output = gr.Textbox(label=f"Predicted: {target_column}")
predict_btn = gr.Button("Predict")
predict_btn.click(fn=pycaret_predict_function, inputs=inputs, outputs=output)
if __name__ == "__main__":
demo.launch()
|