adrin commited on
Commit
1451cd9
1 Parent(s): 48936ad

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +34 -18
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
- in_file = Path(file.name)
9
- obj = joblib.load(in_file)
 
 
 
10
 
11
- if "." in in_file.name:
12
- out_file = ".".join(in_file.name.split(".")[:-1])
13
- else:
14
- out_file = in_file.name
15
 
16
- out_file += ".skops.foo.bar"
17
- _, fname = tempfile.mkstemp(suffix="-" + out_file)
18
- sio.dump(obj, fname)
19
- return fname
 
 
 
 
 
 
20
 
21
 
22
  with gr.Blocks() as iface:
23
- file_output = gr.File()
24
- upload_button = gr.UploadButton("Click to Upload a File", file_types=None, file_count="single")
25
- upload_button.upload(convert, upload_button, file_output)
26
-
27
-
28
- iface.launch()
 
 
 
 
 
 
 
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()