rioanggara commited on
Commit
dc71877
·
1 Parent(s): e5b3900
Files changed (1) hide show
  1. app.py +5 -3
app.py CHANGED
@@ -4,6 +4,7 @@ import numpy as np
4
  from sklearn.linear_model import LinearRegression
5
  import matplotlib.pyplot as plt
6
  import io
 
7
 
8
  def linear_regression(input_csv, x_column, y_column):
9
  # Load dataset from binary
@@ -28,15 +29,16 @@ def linear_regression(input_csv, x_column, y_column):
28
  plt.ylabel(y_column)
29
  plt.title('Linear Regression')
30
 
31
- # Save plot to a buffer
32
  buf = io.BytesIO()
33
  plt.savefig(buf, format='png')
34
  buf.seek(0)
 
35
 
36
  # Regression info
37
  coef_info = f"Coefficient: {model.coef_[0]}\nIntercept: {model.intercept_}"
38
 
39
- return buf, coef_info
40
 
41
  # Gradio interface
42
  iface = gr.Interface(
@@ -47,7 +49,7 @@ iface = gr.Interface(
47
  gr.components.Textbox(label="Y Column Name"),
48
  ],
49
  outputs=[
50
- gr.components.Image(type="plot"),
51
  gr.components.Textbox(label="Regression Info")
52
  ],
53
  title="Automatic Linear Regression Modeling",
 
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(input_csv, x_column, y_column):
10
  # Load dataset from binary
 
29
  plt.ylabel(y_column)
30
  plt.title('Linear Regression')
31
 
32
+ # Save plot to a buffer and convert to PIL Image
33
  buf = io.BytesIO()
34
  plt.savefig(buf, format='png')
35
  buf.seek(0)
36
+ image = Image.open(buf)
37
 
38
  # Regression info
39
  coef_info = f"Coefficient: {model.coef_[0]}\nIntercept: {model.intercept_}"
40
 
41
+ return image, coef_info
42
 
43
  # Gradio interface
44
  iface = gr.Interface(
 
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",