ggg4mless commited on
Commit
200a05a
·
verified ·
1 Parent(s): 85d31f9

Create app.py

Browse files
Files changed (1) hide show
  1. app.py +44 -0
app.py ADDED
@@ -0,0 +1,44 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import gradio as gr
2
+ import tensorflow as tf
3
+ import numpy as np
4
+ from PIL import Image
5
+ from huggingface_hub import hf_hub_download
6
+
7
+ MODEL_PATH = hf_hub_download(
8
+ repo_id="ggg4mless/RateBooru_Efficient",
9
+ filename="ratebooru_efficientnetb1.keras"
10
+ )
11
+ model = tf.keras.models.load_model(MODEL_PATH)
12
+
13
+ class_names = ['explicit', 'general', 'questionable']
14
+ IMG_SIZE = (240, 240)
15
+
16
+ print("Loaded")
17
+
18
+ def predict_image(input_img):
19
+ img = Image.fromarray(input_img.astype('uint8'), 'RGB')
20
+ img = img.resize(IMG_SIZE)
21
+
22
+ img_array = tf.keras.utils.img_to_array(img)
23
+ img_array = tf.expand_dims(img_array, 0)
24
+
25
+ predictions = model.predict(img_array)
26
+
27
+ score = tf.nn.softmax(predictions[0])
28
+
29
+ confidences = {class_names[i]: float(score[i]) for i in range(len(class_names))}
30
+
31
+ return confidences
32
+
33
+ image_input = gr.Image(label="Upload your Picture")
34
+ label_output = gr.Label(num_top_classes=1, label="Prediction Result")
35
+
36
+ demo = gr.Interface(
37
+ fn=predict_image,
38
+ inputs=image_input,
39
+ outputs=label_output,
40
+ title="Ratebooru",
41
+ description="Upload image to be classified into categories: General, Questionable, or Explicit."
42
+ )
43
+
44
+ demo.launch(debug=False, share=True)