File size: 1,269 Bytes
1aa24ee
 
 
 
 
 
 
 
 
 
 
15fa72e
1aa24ee
ee53e2c
1aa24ee
 
 
 
 
 
 
579abe2
1aa24ee
 
 
 
 
 
 
9e70f61
1aa24ee
 
 
 
 
 
 
 
 
 
 
 
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
# -*- coding: utf-8 -*-
"""gradio-app.ipynb

Automatically generated by Colaboratory.

Original file is located at
    https://colab.research.google.com/drive/1hyrqC0U5hw9uVDX7jWPEFtcMixmDKzIi
"""
import gradio as gr
import numpy as np
import tensorflow as tf
from tensorflow.keras.models import load_model

model = load_model('game-or-book-cover-model.h5')

labels = ['Game', 'Book']

width = 130
height = 180

def classify_image(cover):
  normalized_img = cover / 255
  input = np.expand_dims(normalized_img, axis=0)
  prediction = model.predict(input)
  return {labels[i]: float(prediction[0][i]) for i in range(len(labels))}

cover = gr.inputs.Image(shape=(width, height), label='Upload cover image to classify')
label = gr.outputs.Label(label='Model prediction')

examples = ['fifa15.jpg', 'lotr.jpg', 'gta.jpg', 'sapiens.jpg', 'life3.jpg', 'fastai.jpg']

interface = gr.Interface(fn=classify_image, 
             inputs=cover, 
             outputs=label, 
             title="Game or book cover classifier",
             description="Classify if it's game or book cover with this neural network model created using Tensorflow library.", 
             theme="dark-grass", 
             examples=examples,
             allow_flagging="never")

interface.launch()