Skip to content

Commit

Permalink
Library now works in jupyter on cloud
Browse files Browse the repository at this point in the history
  • Loading branch information
ms8909 committed Aug 18, 2020
1 parent b3628a1 commit 2210542
Show file tree
Hide file tree
Showing 28 changed files with 101 additions and 11 deletions.
6 changes: 6 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,12 @@ Import **explainx**
from explainx import *
```

Runnning **explainx** for the first time? Run this function.

```python
explainx.run_only_first_time()
```

Load dataset as X_Data, Y_Data in your XGBoost Model

```python
Expand Down
Binary file removed __pycache__/__init__.cpython-37.pyc
Binary file not shown.
Binary file removed __pycache__/explain.cpython-37.pyc
Binary file not shown.
34 changes: 33 additions & 1 deletion explain.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
import os
import sys
from pathlib import Path

from sys import platform
import subprocess

path= Path(__file__).parent.absolute()
path_dataset= os.path.join(path, "datasets")
Expand Down Expand Up @@ -149,11 +150,42 @@ def dataset_heloc(self):
return X,y


def run_only_first_time(self):

if platform == "linux" or platform == "linux2":
try:
run_command("sudo apt install nodejs")
run_command("sudo apt install npm")
except:
run_command("sudo yum install nodejs")
run_command("sudo yum install npm")
run_command("npm install -g localtunnel")

elif platform == "darwin":
run_command("xcode-select --install")
run_command("brew install nodejs")
run_command("npm install -g localtunnel")

elif platform == "win32":
print("Please install nodejs, npm, and localtunnel manually")
run_command("npm install -g localtunnel")
elif platform == "win64":
print("Please install nodejs, npm, and localtunnel manually")
run_command("npm install -g localtunnel")


explainx=explain()


def run_command(command):
# subdomain= 'explainx-'+ get_random_string(10)
command_arr = command.split(" ")

task = subprocess.Popen(command_arr,
stdout=subprocess.PIPE, stderr=subprocess.PIPE, preexec_fn=os.setsid)

for line in iter(task.stdout.readline, b''):
print('{0}'.format(line.decode('utf-8')), end='')



Binary file removed lib/__pycache__/PDASH.cpython-37.pyc
Binary file not shown.
Binary file removed lib/__pycache__/PDASH_utils.cpython-37.pyc
Binary file not shown.
Binary file removed lib/__pycache__/__init__.cpython-37.pyc
Binary file not shown.
Binary file removed lib/__pycache__/calculate_shap.cpython-37.pyc
Binary file not shown.
Binary file removed lib/__pycache__/dashboard.cpython-37.pyc
Binary file not shown.
Binary file removed lib/__pycache__/data_for_shap_graphs.cpython-37.pyc
Binary file not shown.
Binary file removed lib/__pycache__/die.cpython-37.pyc
Binary file not shown.
Binary file removed lib/__pycache__/encode_decode_cat_col.cpython-37.pyc
Binary file not shown.
Binary file removed lib/__pycache__/feature_impact.cpython-37.pyc
Binary file not shown.
Binary file removed lib/__pycache__/feature_importance.cpython-37.pyc
Binary file not shown.
Binary file removed lib/__pycache__/imports.cpython-37.pyc
Binary file not shown.
Binary file not shown.
Binary file removed lib/__pycache__/insight_regression.cpython-37.pyc
Binary file not shown.
Binary file removed lib/__pycache__/insights.cpython-37.pyc
Binary file not shown.
Binary file removed lib/__pycache__/performance_metrics.cpython-37.pyc
Binary file not shown.
Binary file removed lib/__pycache__/plotly_css.cpython-37.pyc
Binary file not shown.
Binary file removed lib/__pycache__/plotly_graphs.cpython-37.pyc
Binary file not shown.
Binary file removed lib/__pycache__/protodash.cpython-37.pyc
Binary file not shown.
Binary file not shown.
Binary file removed lib/__pycache__/shap_pdp.cpython-37.pyc
Binary file not shown.
Binary file removed lib/__pycache__/summary_plot.cpython-37.pyc
Binary file not shown.
38 changes: 30 additions & 8 deletions lib/dashboard.py
Original file line number Diff line number Diff line change
Expand Up @@ -949,30 +949,35 @@ def multi_level(x_axis, y_axis, size, color, facet_col, facet_row, sql_query):
facet_col_wrap=4)

# Port Finder

port =8080
if mode == "inline":
try:
app.run_server(mode="inline")
app.run_server(mode="inline", port=port)
except:
app.run_server(mode="inline",port=self.find_free_port())
port= self.find_free_port()
app.run_server(mode="inline",port=port)
else:
try:
app.run_server(host='0.0.0.0', port=8080)
app.run_server(host='0.0.0.0', port=port)

except:
# try different ip in case 0.0.0.0 does not work
try:
try:
app.run_server(host='0.0.0.0', port=self.find_free_port())
port=self.find_free_port()
app.run_server(host='0.0.0.0', port=port)
except:
app.run_server(host='0.0.0.0', port=self.find_free_port())
port = self.find_free_port()
app.run_server(host='0.0.0.0', port=port)
except:
try:
app.run_server(host='127.0.0.1', port=self.find_free_port())
port = self.find_free_port()
app.run_server(host='127.0.0.1', port=port)
except:
print("Please restart Jupyter Notebook or Python IDE.")
return False


localtunnel(port)

#update counter here
try:
Expand Down Expand Up @@ -1006,3 +1011,20 @@ def increate_counter(self):
return True
else:
return False


def localtunnel(port):
# subdomain= 'explainx-'+ get_random_string(10)
task = subprocess.Popen(['lt', '-h', '"https://serverless.social"', '-p', str(port)],
stdout=subprocess.PIPE, stderr=subprocess.PIPE, preexec_fn=os.setsid)

outpt= task.stdout.readline()
outpt_string= outpt.decode("utf-8").split("is:")
print('Explainx.ai is running @ '+outpt_string[1])


def get_random_string(length):
letters = string.ascii_lowercase+ string.ascii_uppercase
result_str = ''.join(random.choice(letters) for i in range(length))
return result_str

9 changes: 7 additions & 2 deletions lib/imports.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,9 +17,14 @@
import numpy as np
import dash_bootstrap_components as dbc
import time
import shap
import dash_editor_components
import socket
from contextlib import closing
import requests

import subprocess
import os
import sys
import shap

import random
import string
25 changes: 25 additions & 0 deletions run_only_first_time.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
import os
from sys import platform


if platform == "linux" or platform == "linux2":
try:
os.system("sudo apt install nodejs")
os.system("sudo apt install npm")
except:
os.system("sudo yum install nodejs")
os.system("sudo yum install npm")
os.system("npm install -g localtunnel")

elif platform == "darwin":
os.system("xcode-select --install")
os.system("brew install nodejs")
os.system("npm install -g localtunnel")

elif platform == "win32":
print("Please install nodejs, npm, and localtunnel manually")
os.system("npm install -g localtunnel")
elif platform == "win64":
print("Please install nodejs, npm, and localtunnel manually")
os.system("npm install -g localtunnel")

0 comments on commit 2210542

Please sign in to comment.