shelby commited on
Commit
2122baa
1 Parent(s): 03f1c9d
Files changed (1) hide show
  1. app.py +27 -0
app.py ADDED
@@ -0,0 +1,27 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import gradio as gr
2
+ import tensorflow as tf
3
+ import numpy as np
4
+ from PIL import Image
5
+
6
+
7
+ model = tf.keras.models.load_model('my_model.h5')
8
+ labels = ["No rotated","Rotared to left","Upside down","Rotared to right"]
9
+ sample_images = [["0.jpeg"],["90.jpeg"],["180.jpeg"],["270.jpeg"]]
10
+ def classify_image(inp):
11
+
12
+ inp = tf.keras.preprocessing.image.load_img(inp.name, target_size=(90,90))
13
+ img_array = tf.keras.preprocessing.image.img_to_array(inp)
14
+ a_file = open("gradio.txt", "w")
15
+ for row in img_array:
16
+ np.savetxt(a_file, row)
17
+ a_file.close()
18
+ img_array = tf.expand_dims(inp, 0) # Create a batch
19
+ prediction = model.predict(img_array)
20
+ score = tf.nn.softmax(prediction[0])
21
+
22
+ return {labels[np.argmax(score)]:1 * np.max(score) for i in range(4)}
23
+
24
+ image = gr.inputs.Image(type="file", invert_colors=False)
25
+ label = gr.outputs.Label(num_top_classes=1)
26
+
27
+ gr.Interface(fn=classify_image, inputs=image, examples = sample_images, outputs=label, allow_flagging=None, title="Scan rotation app", theme="dark").launch()