xszheng2020 commited on
Commit
f37f4b4
·
verified ·
1 Parent(s): 6444bd8

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +24 -13
app.py CHANGED
@@ -1,24 +1,13 @@
1
- # import sklearn
2
  import gradio as gr
3
- # import joblib
4
  import pandas as pd
5
  import numpy as np
6
  import lightgbm as lgb
7
  from sklearn.model_selection import train_test_split
8
  from PIL import Image
9
- # import datasets
10
-
11
- # pipe = joblib.load("./model.pkl")
12
 
13
  title = "RegMix"
14
  description = "TBD."
15
 
16
- df = pd.read_csv('data.csv')
17
- headers = df.columns.tolist()
18
-
19
- inputs = [gr.Dataframe(headers=headers, row_count = (8, "dynamic"), datatype='number', col_count=(4,"fixed"), label="Dataset", interactive=1)]
20
- outputs = [gr.ScatterPlot(), gr.Image(), gr.Dataframe(row_count = (2, "dynamic"), col_count=(2, "fixed"), datatype='number', label="Results", headers=["True Loss", "Pred Loss"])]
21
-
22
  def infer(inputs):
23
  df = pd.DataFrame(inputs, columns=headers)
24
 
@@ -177,5 +166,27 @@ def infer(inputs):
177
  gr.Image(Image.open('tmp.png')),
178
  df_val[['Target', 'Prediction']], ]
179
 
180
- gr.Interface(infer, inputs = inputs, outputs = outputs, title = title,
181
- description = description, examples=[df], cache_examples=False, allow_flagging='never').launch(debug=False)
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
  import gradio as gr
 
2
  import pandas as pd
3
  import numpy as np
4
  import lightgbm as lgb
5
  from sklearn.model_selection import train_test_split
6
  from PIL import Image
 
 
 
7
 
8
  title = "RegMix"
9
  description = "TBD."
10
 
 
 
 
 
 
 
11
  def infer(inputs):
12
  df = pd.DataFrame(inputs, columns=headers)
13
 
 
166
  gr.Image(Image.open('tmp.png')),
167
  df_val[['Target', 'Prediction']], ]
168
 
169
+ def display_csv(file):
170
+ df = pd.read_csv(file.name,
171
+ # encoding='utf-8'
172
+ )
173
+ # Return as formatted string
174
+ # print(df.head())
175
+ return df
176
+
177
+ df = pd.read_csv('data.csv')
178
+ headers = df.columns.tolist()
179
+
180
+ inputs = [gr.Dataframe(headers=headers, row_count = (8, "dynamic"), datatype='number', col_count=(4,"fixed"), label="Dataset", interactive=1)]
181
+ outputs = [gr.ScatterPlot(), gr.Image(), gr.Dataframe(row_count = (2, "dynamic"), col_count=(2, "fixed"), datatype='number', label="Results", headers=["True Loss", "Pred Loss"])]
182
+
183
+ with gr.Blocks() as demo:
184
+ upload_button = gr.UploadButton(label="Upload", file_types = ['.csv'],
185
+ # live=True,
186
+ file_count = "single")
187
+ upload_button.upload(fn=display_csv, inputs=upload_button, outputs=inputs, api_name="upload_csv")
188
+
189
+ gr.Interface(infer, inputs=inputs, outputs=outputs, title = title,
190
+ description = description, examples=[df], cache_examples=False, allow_flagging='never')
191
+
192
+ demo.launch(debug=False)