File size: 1,683 Bytes
b0b8109
 
 
 
 
c5f5d07
b0b8109
 
 
 
c5f5d07
b0b8109
 
 
c5f5d07
b0b8109
 
 
 
 
 
 
 
c5f5d07
 
 
 
 
 
 
 
 
 
 
 
 
76f039b
08945c1
76f039b
c5f5d07
76f039b
 
 
 
 
 
c5f5d07
 
 
 
 
76f039b
37c6028
c5f5d07
b0b8109
c5f5d07
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
'''
Author       : Alafun
GitHub Page  : https://github.com/Alafun/
Date         : 2022-06-21 16:43:21
LastEditors  : Alafun
LastEditTime : 2022-06-21 18:51:37
Description  : 
FilePath     : \\app.py
Copyright (c) 2022 by Alafun, All Rights Reserved. 
'''


import gradio as gr


def sepia(input_img):
    sepia_filter = np.array(
        [[0.393, 0.769, 0.189], [0.349, 0.686, 0.168], [0.272, 0.534, 0.131]]
    )
    sepia_img = input_img.dot(sepia_filter.T)
    sepia_img /= sepia_img.max()
    return sepia_img

import tensorflow as tf
import numpy as np
from urllib.request import urlretrieve



urlretrieve("https://gr-models.s3-us-west-2.amazonaws.com/mnist-model.h5", "mnist-model.h5")
model = tf.keras.models.load_model("mnist-model.h5")

def recognize_digit(image):
    image = image.reshape(1, -1)  # add a batch dimension
    prediction = model.predict(image).tolist()[0]
    return {str(i): prediction[i] for i in range(10)}
    
TITLE="RECOULLY: RECOgnize yoUr caLLigraphY"
description="""在手写区写出你心里想的以为数字(0~9), 查看小美同学的实时预测吧! 

### 项目介绍
- 中文名: 小美同学
- 英文名: Recoully
- 口头禅: 小美这么可爱, 就算猜错了也希望被原谅~~qaq

"""
demo = gr.Interface(fn=recognize_digit,
                    inputs="sketchpad",
                    outputs=gr.outputs.Label(num_top_classes=3),
                    live=True,
                    css=".footer {display:none !important}",
                    title=TITLE,
                    description=description,
                    thumbnail="https://raw.githubusercontent.com/gradio-app/real-time-mnist/master/thumbnail2.png")

demo.launch()