Alafun commited on
Commit
c5f5d07
1 Parent(s): b80ea78

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +26 -4
app.py CHANGED
@@ -3,15 +3,16 @@ Author : Alafun
3
  GitHub Page : https://github.com/Alafun/
4
  Date : 2022-06-21 16:43:21
5
  LastEditors : Alafun
6
- LastEditTime : 2022-06-21 16:45:11
7
  Description :
8
  FilePath : \\app.py
9
  Copyright (c) 2022 by Alafun, All Rights Reserved.
10
  '''
11
- import numpy as np
12
 
13
  import gradio as gr
14
 
 
15
  def sepia(input_img):
16
  sepia_filter = np.array(
17
  [[0.393, 0.769, 0.189], [0.349, 0.686, 0.168], [0.272, 0.534, 0.131]]
@@ -20,6 +21,27 @@ def sepia(input_img):
20
  sepia_img /= sepia_img.max()
21
  return sepia_img
22
 
23
- demo = gr.Interface(sepia, gr.Image(shape=(200, 200)), "image")
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
24
 
25
- demo.launch()
 
3
  GitHub Page : https://github.com/Alafun/
4
  Date : 2022-06-21 16:43:21
5
  LastEditors : Alafun
6
+ LastEditTime : 2022-06-21 18:51:37
7
  Description :
8
  FilePath : \\app.py
9
  Copyright (c) 2022 by Alafun, All Rights Reserved.
10
  '''
11
+
12
 
13
  import gradio as gr
14
 
15
+
16
  def sepia(input_img):
17
  sepia_filter = np.array(
18
  [[0.393, 0.769, 0.189], [0.349, 0.686, 0.168], [0.272, 0.534, 0.131]]
 
21
  sepia_img /= sepia_img.max()
22
  return sepia_img
23
 
24
+ import tensorflow as tf
25
+ import numpy as np
26
+ from urllib.request import urlretrieve
27
+
28
+
29
+
30
+ urlretrieve("https://gr-models.s3-us-west-2.amazonaws.com/mnist-model.h5", "mnist-model.h5")
31
+ model = tf.keras.models.load_model("mnist-model.h5")
32
+
33
+ def recognize_digit(image):
34
+ image = image.reshape(1, -1) # add a batch dimension
35
+ prediction = model.predict(image).tolist()[0]
36
+ return {str(i): prediction[i] for i in range(10)}
37
+
38
+ demo = gr.Interface(fn=recognize_digit,
39
+ inputs="sketchpad",
40
+ outputs=gr.outputs.Label(num_top_classes=3),
41
+ live=True,
42
+ css=".footer {display:none !important}",
43
+ # title="MNIST Sketchpad",
44
+ description="Draw a number 0 through 9 on the sketchpad, and see predictions in real time.",
45
+ thumbnail="https://raw.githubusercontent.com/gradio-app/real-time-mnist/master/thumbnail2.png")
46
 
47
+ demo.launch()