konerusudhir commited on
Commit
91ad0c4
·
verified ·
1 Parent(s): dc105fe

Upload app.py with huggingface_hub

Browse files
Files changed (1) hide show
  1. app.py +32 -0
app.py ADDED
@@ -0,0 +1,32 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ # Write a Simple gradio app to take image as input run a model on it and Returnt the Probability (0 to 1) as a confidence bar
2
+
3
+ import gradio as gr
4
+ import tensorflow as tf
5
+ import numpy as np
6
+
7
+ from huggingface_hub import from_pretrained_keras
8
+
9
+ REPO_ID = "ai-or-not/ai-or-not-model"
10
+
11
+ model = from_pretrained_keras(REPO_ID)
12
+
13
+
14
+ # Define the function
15
+ def classify_image(array):
16
+ # image is numpy array
17
+ array = array / 255.0
18
+ image = tf.image.resize_with_pad(array, 224, 224)
19
+ image = np.expand_dims(image, axis=0)
20
+ print(image.shape)
21
+ prediction = model(image)
22
+ # there are 3 class probabilities in the model 0: "REAL", 1: "GAN", 2: "DIFFUSION"
23
+ real = prediction[0][0]
24
+ ai = 1 - real
25
+
26
+ return {"REAL": real, "AI": ai}
27
+
28
+
29
+ demo = gr.Interface(fn=classify_image, inputs="image", outputs="label", examples="examples")
30
+ demo.launch(
31
+ debug=True,
32
+ )