Spaces:
Sleeping
Sleeping
Commit
·
a6fb37c
1
Parent(s):
dc71877
changes
Browse files
app.py
CHANGED
|
@@ -1,18 +1,14 @@
|
|
| 1 |
import gradio as gr
|
| 2 |
-
import pandas as pd
|
| 3 |
import numpy as np
|
| 4 |
from sklearn.linear_model import LinearRegression
|
| 5 |
import matplotlib.pyplot as plt
|
| 6 |
import io
|
| 7 |
from PIL import Image
|
| 8 |
|
| 9 |
-
def linear_regression(
|
| 10 |
-
#
|
| 11 |
-
|
| 12 |
-
|
| 13 |
-
# Prepare data for regression
|
| 14 |
-
X = df[[x_column]].values
|
| 15 |
-
y = df[y_column].values
|
| 16 |
|
| 17 |
# Perform linear regression
|
| 18 |
model = LinearRegression()
|
|
@@ -25,8 +21,8 @@ def linear_regression(input_csv, x_column, y_column):
|
|
| 25 |
plt.figure(figsize=(10, 6))
|
| 26 |
plt.scatter(X, y, color='blue')
|
| 27 |
plt.plot(X, y_pred, color='red')
|
| 28 |
-
plt.xlabel(
|
| 29 |
-
plt.ylabel(
|
| 30 |
plt.title('Linear Regression')
|
| 31 |
|
| 32 |
# Save plot to a buffer and convert to PIL Image
|
|
@@ -44,16 +40,15 @@ def linear_regression(input_csv, x_column, y_column):
|
|
| 44 |
iface = gr.Interface(
|
| 45 |
fn=linear_regression,
|
| 46 |
inputs=[
|
| 47 |
-
gr.components.
|
| 48 |
-
gr.components.Textbox(
|
| 49 |
-
gr.components.Textbox(label="Y Column Name"),
|
| 50 |
],
|
| 51 |
outputs=[
|
| 52 |
gr.components.Image(type="pil"),
|
| 53 |
gr.components.Textbox(label="Regression Info")
|
| 54 |
],
|
| 55 |
title="Automatic Linear Regression Modeling",
|
| 56 |
-
description="
|
| 57 |
)
|
| 58 |
|
| 59 |
# Launch the app
|
|
|
|
| 1 |
import gradio as gr
|
|
|
|
| 2 |
import numpy as np
|
| 3 |
from sklearn.linear_model import LinearRegression
|
| 4 |
import matplotlib.pyplot as plt
|
| 5 |
import io
|
| 6 |
from PIL import Image
|
| 7 |
|
| 8 |
+
def linear_regression(x_values, y_values):
|
| 9 |
+
# Convert string inputs to numpy arrays
|
| 10 |
+
X = np.array([float(x) for x in x_values.split(',')]).reshape(-1, 1)
|
| 11 |
+
y = np.array([float(y) for y in y_values.split(',')])
|
|
|
|
|
|
|
|
|
|
| 12 |
|
| 13 |
# Perform linear regression
|
| 14 |
model = LinearRegression()
|
|
|
|
| 21 |
plt.figure(figsize=(10, 6))
|
| 22 |
plt.scatter(X, y, color='blue')
|
| 23 |
plt.plot(X, y_pred, color='red')
|
| 24 |
+
plt.xlabel("X Values")
|
| 25 |
+
plt.ylabel("Y Values")
|
| 26 |
plt.title('Linear Regression')
|
| 27 |
|
| 28 |
# Save plot to a buffer and convert to PIL Image
|
|
|
|
| 40 |
iface = gr.Interface(
|
| 41 |
fn=linear_regression,
|
| 42 |
inputs=[
|
| 43 |
+
gr.components.Textbox(placeholder="Enter X values separated by commas (e.g., 1,2,3)", label="X Values"),
|
| 44 |
+
gr.components.Textbox(placeholder="Enter Y values separated by commas (e.g., 2,4,6)", label="Y Values")
|
|
|
|
| 45 |
],
|
| 46 |
outputs=[
|
| 47 |
gr.components.Image(type="pil"),
|
| 48 |
gr.components.Textbox(label="Regression Info")
|
| 49 |
],
|
| 50 |
title="Automatic Linear Regression Modeling",
|
| 51 |
+
description="Enter X and Y values as comma-separated lists to perform linear regression."
|
| 52 |
)
|
| 53 |
|
| 54 |
# Launch the app
|