bhupen@gridflowAI
commited on
Commit
·
5c3c178
1
Parent(s):
f6b2f01
new model
Browse files- .gitattributes +2 -0
- app.py +61 -0
- requirements.txt +5 -0
- xgboost_model.json +3 -0
.gitattributes
CHANGED
@@ -33,3 +33,5 @@ saved_model/**/* filter=lfs diff=lfs merge=lfs -text
|
|
33 |
*.zip filter=lfs diff=lfs merge=lfs -text
|
34 |
*.zst filter=lfs diff=lfs merge=lfs -text
|
35 |
*tfevents* filter=lfs diff=lfs merge=lfs -text
|
|
|
|
|
|
33 |
*.zip filter=lfs diff=lfs merge=lfs -text
|
34 |
*.zst filter=lfs diff=lfs merge=lfs -text
|
35 |
*tfevents* filter=lfs diff=lfs merge=lfs -text
|
36 |
+
xgboost_model.json filter=lfs diff=lfs merge=lfs -text
|
37 |
+
xgboost_model filter=lfs diff=lfs merge=lfs -text
|
app.py
ADDED
@@ -0,0 +1,61 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
from io import StringIO
|
2 |
+
import gradio as gr
|
3 |
+
import pandas as pd
|
4 |
+
import xgboost as xgb
|
5 |
+
# Add this import
|
6 |
+
|
7 |
+
def preprocess_data(df):
|
8 |
+
|
9 |
+
|
10 |
+
# Assuming the model expects the input without the first 50 columns
|
11 |
+
processed_data = df.drop(df.columns[0:50], axis=1)
|
12 |
+
|
13 |
+
# Assuming you want the last column as the target.
|
14 |
+
X = processed_data.drop(processed_data.columns[-1], axis=1).values
|
15 |
+
y = processed_data[processed_data.columns[-1]].values
|
16 |
+
|
17 |
+
|
18 |
+
return (X, y)
|
19 |
+
|
20 |
+
|
21 |
+
|
22 |
+
def process_csv_text(temp_file):
|
23 |
+
if isinstance(temp_file, str):
|
24 |
+
df = pd.read_csv(StringIO(temp_file))
|
25 |
+
else:
|
26 |
+
df = pd.read_csv(temp_file.name)
|
27 |
+
print(df)
|
28 |
+
return df
|
29 |
+
|
30 |
+
|
31 |
+
def predict_interface(input_csv):
|
32 |
+
print(type(input_csv))
|
33 |
+
loaded_model = xgb.XGBRegressor()
|
34 |
+
loaded_model.load_model('xgboost_model.json')
|
35 |
+
|
36 |
+
# Check if the file is non-empty and has recognizable data
|
37 |
+
try:
|
38 |
+
# Load the csv content into a DataFrame
|
39 |
+
data = process_csv_text(input_csv)
|
40 |
+
if data is None:
|
41 |
+
return "Uploaded file is empty or not recognized as a valid CSV."
|
42 |
+
|
43 |
+
# Continue with the rest of the processing
|
44 |
+
processed_data = preprocess_data(data)
|
45 |
+
predictions = loaded_model.predict(processed_data[0]) # Access the X part
|
46 |
+
data['Predictions'] = predictions
|
47 |
+
data['Actual'] = processed_data[1] # Access the y part
|
48 |
+
return data.to_html()
|
49 |
+
except Exception as e:
|
50 |
+
return str(e)
|
51 |
+
|
52 |
+
|
53 |
+
# Define the Gradio interface
|
54 |
+
iface = gr.Interface(
|
55 |
+
fn=predict_interface,
|
56 |
+
inputs="file",
|
57 |
+
outputs="html",
|
58 |
+
live=True
|
59 |
+
)
|
60 |
+
|
61 |
+
iface.launch(server_name="0.0.0.0", server_port=7860)
|
requirements.txt
ADDED
@@ -0,0 +1,5 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
xgboost==1.7.6
|
2 |
+
gradio
|
3 |
+
scikit-learn==1.2.2
|
4 |
+
numpy
|
5 |
+
|
xgboost_model.json
ADDED
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
1 |
+
version https://git-lfs.github.com/spec/v1
|
2 |
+
oid sha256:d57f4ca019ba072956f422926ebc155ed8af4ce0bb954934d7e04a0f1458df52
|
3 |
+
size 15378107
|