Lokesh Jirati commited on
Commit
84771d4
·
1 Parent(s): 9ff4574
Files changed (2) hide show
  1. app.py +39 -0
  2. requirements.txt +6 -0
app.py ADDED
@@ -0,0 +1,39 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import gradio as gr
2
+ import pandas as pd
3
+ import joblib
4
+ import requests
5
+ import os
6
+
7
+ MODEL_URL = "https://huggingface.co/munnabhaimbbsfail/linear_regression_model/resolve/main/model.pkl"
8
+ MODEL_PATH = "model.pkl"
9
+
10
+ # Download the model if not already present
11
+ if not os.path.exists(MODEL_PATH):
12
+ response = requests.get(MODEL_URL)
13
+ with open(MODEL_PATH, "wb") as f:
14
+ f.write(response.content)
15
+
16
+ # Load model
17
+ model = joblib.load(MODEL_PATH)
18
+
19
+ # Define prediction function
20
+ def predict(x_values: str):
21
+ try:
22
+ x_list = [float(x.strip()) for x in x_values.split(",")]
23
+ df = pd.DataFrame({"x": x_list})
24
+ preds = model.predict(df)
25
+ return {"predictions": preds.tolist()}
26
+ except Exception as e:
27
+ return {"error": str(e)}
28
+
29
+ # Create Gradio interface
30
+ iface = gr.Interface(
31
+ fn=predict,
32
+ inputs=gr.Textbox(label="Enter x values (comma-separated)", placeholder="e.g., 5, 10, 15"),
33
+ outputs="json",
34
+ title="Linear Regression Predictor 2",
35
+ description="Enter a list of x values to get predictions from the trained model."
36
+ )
37
+
38
+ iface.launch()
39
+
requirements.txt ADDED
@@ -0,0 +1,6 @@
 
 
 
 
 
 
 
1
+ gradio
2
+ pandas
3
+ joblib
4
+ scikit-learn
5
+ requests
6
+