File size: 1,088 Bytes
84771d4 b3955d3 84771d4 b3955d3 84771d4 |
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 |
import gradio as gr
import pandas as pd
import joblib
import requests
import os
MODEL_URL = "https://huggingface.co/munnabhaimbbsfail/linear_regression_model/resolve/main/model.pkl"
MODEL_PATH = "model.pkl"
# Download the model if not already present
if not os.path.exists(MODEL_PATH):
response = requests.get(MODEL_URL)
with open(MODEL_PATH, "wb") as f:
f.write(response.content)
# Load model
model = joblib.load(MODEL_PATH)
# Define prediction function
def predict(x_values: str):
try:
x_list = [float(x.strip()) for x in x_values.split(",")]
df = pd.DataFrame({"x": x_list})
preds = model.predict(df)
return {"predictions": preds.tolist()}
except Exception as e:
return {"error": str(e)}
# Create Gradio interface
iface = gr.Interface(
fn=predict,
inputs=gr.Textbox(label="Enter x values (comma-separated)", placeholder="e.g., 4, 10, 15"),
outputs="json",
title="Linear Regression Predictor 3",
description="Enter a list of x values to get predictions from the trained model."
)
iface.launch()
|