Spaces:
Build error
Build error
Update app.py
Browse files
app.py
CHANGED
@@ -1,28 +1,44 @@
|
|
1 |
-
import gradio as gr
|
2 |
-
from pathlib import Path
|
3 |
import tempfile
|
|
|
|
|
|
|
|
|
4 |
import joblib
|
5 |
from skops import io as sio
|
6 |
|
|
|
7 |
def convert(file):
|
8 |
-
|
9 |
-
|
|
|
|
|
|
|
10 |
|
11 |
-
|
12 |
-
|
13 |
-
|
14 |
-
|
15 |
|
16 |
-
|
17 |
-
|
18 |
-
|
19 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
20 |
|
21 |
|
22 |
with gr.Blocks() as iface:
|
23 |
-
|
24 |
-
|
25 |
-
|
26 |
-
|
27 |
-
|
28 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
import tempfile
|
2 |
+
import warnings
|
3 |
+
from pathlib import Path
|
4 |
+
|
5 |
+
import gradio as gr
|
6 |
import joblib
|
7 |
from skops import io as sio
|
8 |
|
9 |
+
|
10 |
def convert(file):
|
11 |
+
msg = ""
|
12 |
+
try:
|
13 |
+
with warnings.catch_warnings(record=True) as record:
|
14 |
+
in_file = Path(file.name)
|
15 |
+
obj = joblib.load(in_file)
|
16 |
|
17 |
+
if "." in in_file.name:
|
18 |
+
out_file = ".".join(in_file.name.split(".")[:-1])
|
19 |
+
else:
|
20 |
+
out_file = in_file.name
|
21 |
|
22 |
+
out_file += ".skops"
|
23 |
+
path = tempfile.mkdtemp(prefix="gradio-convert-")
|
24 |
+
out_file = Path(path) / out_file
|
25 |
+
sio.dump(obj, out_file)
|
26 |
+
print(out_file)
|
27 |
+
if len(record):
|
28 |
+
msg = "\n".join([repr(w.message) for w in record])
|
29 |
+
except Exception as e:
|
30 |
+
return None, repr(e)
|
31 |
+
return out_file, msg
|
32 |
|
33 |
|
34 |
with gr.Blocks() as iface:
|
35 |
+
upload_button = gr.UploadButton(
|
36 |
+
"Click to Upload a File", file_types=None, file_count="single"
|
37 |
+
)
|
38 |
+
file_output = gr.File(label="Converted File")
|
39 |
+
upload_button.upload(
|
40 |
+
convert, upload_button, [file_output, gr.Text(label="Errors and Warnings")]
|
41 |
+
)
|
42 |
+
|
43 |
+
|
44 |
+
iface.launch()
|