johnowhitaker commited on
Commit
08ac7ce
1 Parent(s): 74ded28

Create app.py

Browse files
Files changed (1) hide show
  1. app.py +36 -0
app.py ADDED
@@ -0,0 +1,36 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import gradio as gr
2
+ from fastai.vision.all import *
3
+ from os.path import file_exists
4
+ import requests
5
+
6
+ model_fn = 'quick_224px'
7
+ if not file_exists(model_fn):
8
+ with requests.get(url, stream=True) as r:
9
+ r.raise_for_status()
10
+ with open(model_fn, 'wb') as f:
11
+ for chunk in r.iter_content(chunk_size=8192):
12
+ f.write(chunk)
13
+
14
+ # Load the model
15
+ def open_img(fn:Path): return Image.open(fn).convert('RGB').copy()
16
+ def get_images(path):
17
+ return get_image_files(path/'train') + get_image_files(path/'test')
18
+ def get_x(item):
19
+ return np.array(open_img(item).crop((0, 0, 512, 512)))
20
+ def get_y(item):
21
+ return np.array(open_img(item).crop((512, 0, 1024, 512)))
22
+ sketch_model = load_learner(model_fn)
23
+
24
+
25
+ def sketchify(image_path):
26
+ pred = sketch_model.predict(image_path)
27
+ np_im = pred[0].permute(1, 2, 0).numpy()
28
+ return np_im
29
+
30
+
31
+
32
+ iface = gr.Interface(fn=sketchify,
33
+ inputs=[gr.inputs.Image(shape=(512, 512), type="filepath")],
34
+ outputs=[gr.outputs.Image(type="numpy", label="Output Image")]
35
+ )
36
+ iface.launch()