adrin commited on
Commit
1a37806
1 Parent(s): da07405

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +27 -4
app.py CHANGED
@@ -1,10 +1,14 @@
 
 
1
  import tempfile
2
  import warnings
3
- import pickle
4
  from pathlib import Path
 
5
 
6
  import gradio as gr
7
  import joblib
 
8
  from skops import io as sio
9
 
10
  title = "skops converter"
@@ -41,11 +45,20 @@ https://github.com/skops-dev/skops/issues/new?title=CONVERSION+error+from+hf.spa
41
  """
42
 
43
 
44
- def convert(file):
45
  msg = ""
46
  try:
47
  with warnings.catch_warnings(record=True) as record:
48
  in_file = Path(file.name)
 
 
 
 
 
 
 
 
 
49
  try:
50
  obj = joblib.load(in_file)
51
  except:
@@ -66,11 +79,21 @@ def convert(file):
66
  msg = "\n".join([repr(w.message) for w in record])
67
  except Exception as e:
68
  return None, None, repr(e)
 
69
  return out_file, unknown_types, msg
70
 
71
 
72
  with gr.Blocks(title=title) as iface:
73
  gr.Markdown(desc)
 
 
 
 
 
 
 
 
 
74
  upload_button = gr.UploadButton(
75
  "Click to Upload a File",
76
  file_types=None,
@@ -79,13 +102,13 @@ with gr.Blocks(title=title) as iface:
79
  file_output = gr.File(label="Converted File")
80
  upload_button.upload(
81
  convert,
82
- upload_button,
83
  [
84
  file_output,
85
  gr.Text(label="Unknown Types"),
86
  gr.Text(label="Errors and Warnings"),
87
  ],
88
- api_name="upload-file"
89
  )
90
 
91
 
 
1
+ import os
2
+ import pickle
3
  import tempfile
4
  import warnings
5
+ from io import BytesIO
6
  from pathlib import Path
7
+ from uuid import uuid4
8
 
9
  import gradio as gr
10
  import joblib
11
+ from huggingface_hub import upload_file
12
  from skops import io as sio
13
 
14
  title = "skops converter"
 
45
  """
46
 
47
 
48
+ def convert(file, store):
49
  msg = ""
50
  try:
51
  with warnings.catch_warnings(record=True) as record:
52
  in_file = Path(file.name)
53
+ if store:
54
+ upload_file(
55
+ path_or_fileobj=str(in_file),
56
+ path_in_repo=f"{uuid4()}/{in_file.name}",
57
+ repo_id="adrin/pickle-to-skops",
58
+ repo_type="dataset",
59
+ token=os.environ["HF_TOKEN"],
60
+ )
61
+
62
  try:
63
  obj = joblib.load(in_file)
64
  except:
 
79
  msg = "\n".join([repr(w.message) for w in record])
80
  except Exception as e:
81
  return None, None, repr(e)
82
+
83
  return out_file, unknown_types, msg
84
 
85
 
86
  with gr.Blocks(title=title) as iface:
87
  gr.Markdown(desc)
88
+ store = gr.Checkbox(
89
+ label=(
90
+ "Store a copy: if you leave this box checked, we store a copy of your"
91
+ " pickle file in a private place, only used for us to find issues and"
92
+ " improve the skops format. Please uncheck this box if your pickle file"
93
+ " includes any personal or sensitive data."
94
+ ),
95
+ value=True,
96
+ )
97
  upload_button = gr.UploadButton(
98
  "Click to Upload a File",
99
  file_types=None,
 
102
  file_output = gr.File(label="Converted File")
103
  upload_button.upload(
104
  convert,
105
+ [upload_button, store],
106
  [
107
  file_output,
108
  gr.Text(label="Unknown Types"),
109
  gr.Text(label="Errors and Warnings"),
110
  ],
111
+ api_name="upload-file",
112
  )
113
 
114