arsath-sm commited on
Commit
70e7571
1 Parent(s): a1e63f6

Create app.py

Browse files
Files changed (1) hide show
  1. app.py +50 -0
app.py ADDED
@@ -0,0 +1,50 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import gradio as gr
2
+ import tensorflow as tf
3
+ from tensorflow.keras.models import load_model
4
+ from tensorflow.keras.preprocessing import image
5
+ import numpy as np
6
+ from huggingface_hub import from_pretrained_keras
7
+
8
+ # Load the models
9
+ model1 = from_pretrained_keras("arsath-sm/face_classification_model1")
10
+ model2 = from_pretrained_keras("arsath-sm/face_classification_model2")
11
+
12
+ # Preprocess the image
13
+ def preprocess_image(img):
14
+ img = image.img_to_array(img)
15
+ img = np.expand_dims(img, axis=0)
16
+ img = img / 255.0
17
+ return img
18
+
19
+ # Make predictions
20
+ def predict(img):
21
+ preprocessed_img = preprocess_image(img)
22
+
23
+ prediction1 = model1.predict(preprocessed_img)[0][0]
24
+ prediction2 = model2.predict(preprocessed_img)[0][0]
25
+
26
+ result1 = "Real" if prediction1 > 0.5 else "Fake"
27
+ result2 = "Real" if prediction2 > 0.5 else "Fake"
28
+
29
+ confidence1 = prediction1 if result1 == "Real" else 1 - prediction1
30
+ confidence2 = prediction2 if result2 == "Real" else 1 - prediction2
31
+
32
+ return {
33
+ "Model 1 Prediction": f"{result1} (Confidence: {confidence1:.2f})",
34
+ "Model 2 Prediction": f"{result2} (Confidence: {confidence2:.2f})"
35
+ }
36
+
37
+ # Create the Gradio interface
38
+ iface = gr.Interface(
39
+ fn=predict,
40
+ inputs=gr.Image(type="pil"),
41
+ outputs={
42
+ "Model 1 Prediction": gr.Textbox(),
43
+ "Model 2 Prediction": gr.Textbox()
44
+ },
45
+ title="Real vs AI Face Classification",
46
+ description="Upload an image to classify whether it's a real face or an AI-generated face using two different models."
47
+ )
48
+
49
+ # Launch the app
50
+ iface.launch()