Ariel Gamino commited on
Commit
307a166
·
1 Parent(s): d6cbd2f

Initial commit

Browse files
Files changed (1) hide show
  1. app.py +65 -0
app.py ADDED
@@ -0,0 +1,65 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import os
2
+ from urllib.request import urlretrieve
3
+
4
+ import tensorflow as tf
5
+
6
+ import gradio
7
+ import gradio as gr
8
+
9
+ urlretrieve(
10
+ "https://gr-models.s3-us-west-2.amazonaws.com/mnist-model.h5", "mnist-model.h5"
11
+ )
12
+ model = tf.keras.models.load_model("mnist-model.h5")
13
+
14
+
15
+ def recognize_digit(image):
16
+ image = image.reshape(1, -1)
17
+ prediction = model.predict(image).tolist()[0]
18
+ return {str(i): prediction[i] for i in range(10)}
19
+
20
+
21
+ im = gradio.inputs.Image(
22
+ shape=(28, 28), image_mode="L", invert_colors=False, source="canvas"
23
+ )
24
+
25
+ iface = gr.Interface(
26
+ recognize_digit,
27
+ im,
28
+ gradio.outputs.Label(num_top_classes=3),
29
+ live=True,
30
+ interpretation="default",
31
+ capture_session=True,
32
+ title="Number Guesser",
33
+ description="""Draw a number. Give it your best shot.""",
34
+ css="""
35
+ .gradio-page {
36
+ background-image : url('https://raw.githubusercontent.com/arielgamino/githubpages/main/top-ranked-program-icon-small.png');
37
+ background-size: contain;
38
+ background-repeat: no-repeat;
39
+ background-position: top left;
40
+ background-size: auto;
41
+ border: 10px solid #102038;
42
+ }
43
+ body {background-color: #102038;}
44
+
45
+ p.description {
46
+ font-family: -apple-system, BlinkMacSystemFont, sans-serif;
47
+ font-size: 1.4em;
48
+ padding-top: 17px;
49
+ color: #bf5700;
50
+ }
51
+
52
+ h1 {
53
+ font-family: -apple-system, BlinkMacSystemFont, sans-serif;
54
+ color: #bf5700;
55
+ }
56
+
57
+ .gradio-page .title {
58
+ font-size: 2.50rem;
59
+ line-height: 2.75rem;
60
+ }
61
+ """
62
+ )
63
+
64
+ iface.test_launch()
65
+ iface.launch()