|
|
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" |
|
|
|
|
|
|
|
|
if not os.path.exists(MODEL_PATH): |
|
|
response = requests.get(MODEL_URL) |
|
|
with open(MODEL_PATH, "wb") as f: |
|
|
f.write(response.content) |
|
|
|
|
|
|
|
|
model = joblib.load(MODEL_PATH) |
|
|
|
|
|
|
|
|
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)} |
|
|
|
|
|
|
|
|
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() |
|
|
|
|
|
|