forked from kaiiyer/UBA
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmodel.py
More file actions
139 lines (107 loc) · 3.38 KB
/
Copy pathmodel.py
File metadata and controls
139 lines (107 loc) · 3.38 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
'''
Copyright 2019-Present The OpenUB Platform Authors
This file is part of the OpenUB Platform library.
The OpenUB Platform is free software: you can redistribute it and/or modify
it under the terms of the GNU Lesser General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
The OpenUB Platform is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU Lesser General Public License for more details.
You should have received a copy of the GNU Lesser General Public License
along with the OpenUB Platform. If not, see <http://www.gnu.org/licenses/>.
'''
'''
@name
@description for model sessions
'''
import logging
import threading
import time
import urllib.request
import sys
import os
import shutil
import io
'''
@name ModelLibrary
@description manage model library
'''
class ModelLibrary():
@staticmethod
def remove_model() -> bool:
path = "model_library/model_test"
try:
#os.rmdir(path)
shutil.rmtree(path)
print("Model removed")
return True
except Exception as e:
logging.error(e)
return False
@staticmethod
def store_fetched_model():
logging.info()
@staticmethod
def run_temp_model():
''' temporary files
import tempfile
# create a temporary directory
with tempfile.TemporaryDirectory() as directory:
print('The created temp dir is %s' % directory)
'''
pass
@staticmethod
def fetch_model():
logging.error("fetching model...")
url = "http://localhost:5000/display/test/"
access_rights = 0o755
path = "model_library/model_test/"
try:
os.mkdir(path, access_rights)
except Exception as e:
logging.error(e)
'''
@todo base 64 encode a model
#sample_code = open('model.py', 'r')
#sutf8 = sample_code.encode('UTF-8')
'''
logging.warning("codecs/io")
with io.open("model.py",
'r',
encoding='utf8',
errors="ignore") as local_model:
text = local_model.read()
logging.warning(text)
f = open('model_library/model_test/model_test.py', 'w')
f.write("def func_try():\n\tprint(\"model_test testing...\")\n\treturn \"return from model_Test\"")
f.close()
f = open('model_library/model_test/__init__.py', 'w')
f.write("from .model_test import func_try")
f.close()
# insert at 1, 0 is the script path (or '' in REPL)
sys.path.insert(1, 'model_library/model_test')
import model_test
return model_test.func_try()
'''
@name ModelDeployment
@description to alter deployed models set
'''
class ModelDeployment():
def __init__(self):
logging.info("Model Deployment made")
'''
@Session
@description start model session. A model session can have several jobs
'''
class Session():
def __init__(self):
self.selected_model_name = "SK"
'''
start a model session
'''
def start_job(name):
logging.info("Model Server %s: starting job")
time.sleep(2)
logging.info("Model Server %s: finishing job")