Niqull commited on
Commit
0ce8c49
1 Parent(s): d3a7770

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +18 -6
app.py CHANGED
@@ -3,6 +3,17 @@ from fastbook import load_learner
3
  from fastai.vision.all import *
4
  from PIL import Image
5
 
 
 
 
 
 
 
 
 
 
 
 
6
  def predict(im):
7
  resized_im = im['composite'].resize((28,28))
8
  pred,idx,probs = model.predict(resized_im)
@@ -12,10 +23,11 @@ categories = ('0', '1', '2', '3', '4', '5', '6', '7', '8', '9')
12
  model = load_learner('./dr_model.pkl')
13
  labels = model.dls.vocab
14
 
15
- demo = gr.Interface(
16
- fn=predict,
17
- inputs=gr.Sketchpad(image_mode='L', brush=gr.Brush(default_color="FFFFFFFF"), type='pil'),
18
- outputs = "label",
19
- theme=gr.themes.Monochrome())
 
20
 
21
- demo.launch()
 
3
  from fastai.vision.all import *
4
  from PIL import Image
5
 
6
+ js_func = """
7
+ function refresh() {
8
+ const url = new URL(window.location);
9
+
10
+ if (url.searchParams.get('__theme') !== 'dark') {
11
+ url.searchParams.set('__theme', 'dark');
12
+ window.location.href = url.href;
13
+ }
14
+ }
15
+ """
16
+
17
  def predict(im):
18
  resized_im = im['composite'].resize((28,28))
19
  pred,idx,probs = model.predict(resized_im)
 
23
  model = load_learner('./dr_model.pkl')
24
  labels = model.dls.vocab
25
 
26
+ with gr.Blocks(js=js_func) as demo:
27
+ demo = gr.Interface(
28
+ fn=predict,
29
+ inputs=gr.Sketchpad(image_mode='L', brush=gr.Brush(default_color="FFFFFFFF"), type='pil'),
30
+ outputs = "label",
31
+ theme=gr.themes.Monochrome())
32
 
33
+ demo.launch()