adrin commited on
Commit
24266ff
1 Parent(s): 1451cd9

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +35 -5
app.py CHANGED
@@ -6,6 +6,29 @@ import gradio as gr
6
  import joblib
7
  from skops import io as sio
8
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
9
 
10
  def convert(file):
11
  msg = ""
@@ -23,21 +46,28 @@ def convert(file):
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
 
 
6
  import joblib
7
  from skops import io as sio
8
 
9
+ title = "skops converter"
10
+
11
+ desc = """
12
+ # Pickle to skops converter
13
+
14
+ This space converts your pickle files to skops format. You can read more on the
15
+ skops format [here]( https://skops.readthedocs.io/en/stable/persistence.html).
16
+ This space assumes you have used the latest `joblib` and `scikit-learn`
17
+ versions installed on your environment to create the pickle file.
18
+
19
+ You can use `skops.io.dump(joblib.load(in_file), out_file)` to do the
20
+ conversion yourself, where `in_file` is your source pickle file and `out_file`
21
+ is where you want to save the skops file. But only do that **if you trust the
22
+ source of the pickle file**.
23
+
24
+ You can then use `skops.io.load(skops_file, trusted=unknown_types)` to load the
25
+ file, where `skops_file` is the converted skops format file, and the
26
+ `unknown_types` is what you see in the "Unknown Types" box bellow. You can also
27
+ locally reproduce this list using
28
+ `skops.io.get_untrusted_types(file=skops_file)`. You should only load a `skops`
29
+ file that you trust all the types included in the `unknown_types` list.
30
+ """
31
+
32
 
33
  def convert(file):
34
  msg = ""
 
46
  path = tempfile.mkdtemp(prefix="gradio-convert-")
47
  out_file = Path(path) / out_file
48
  sio.dump(obj, out_file)
49
+ unknown_types = sio.get_untrusted_types(file=out_file)
50
  if len(record):
51
  msg = "\n".join([repr(w.message) for w in record])
52
  except Exception as e:
53
+ return None, None, repr(e)
54
+ return out_file, unknown_types, msg
55
 
56
 
57
+ with gr.Blocks(title=title) as iface:
58
+ gr.Markdown(desc)
59
  upload_button = gr.UploadButton(
60
  "Click to Upload a File", file_types=None, file_count="single"
61
  )
62
  file_output = gr.File(label="Converted File")
63
  upload_button.upload(
64
+ convert,
65
+ upload_button,
66
+ [
67
+ file_output,
68
+ gr.Text(label="Unknown Types"),
69
+ gr.Text(label="Errors and Warnings"),
70
+ ],
71
  )
72
 
73