arsath-sm commited on
Commit
b46efd4
1 Parent(s): c62f4a7

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +10 -11
app.py CHANGED
@@ -14,12 +14,11 @@ model2 = load_model_from_hub("arsath-sm/face_classification_model2", "face_class
14
 
15
  def preprocess_image(image):
16
  img = tf.image.resize(image, (224, 224)) # Resize to match the input size of your models
17
- img = tf.cast(img, tf.float32) / 255.0 # Normalize pixel values
18
- return tf.expand_dims(img, 0) # Add batch dimension
19
 
20
  def predict_image(image):
21
  preprocessed_image = preprocess_image(image)
22
-
23
  # Make predictions using both models
24
  pred1 = model1.predict(preprocessed_image)[0][0]
25
  pred2 = model2.predict(preprocessed_image)[0][0]
@@ -30,19 +29,19 @@ def predict_image(image):
30
  result2 = "Real" if pred2 > 0.5 else "Fake"
31
  confidence2 = pred2 if pred2 > 0.5 else 1 - pred2
32
 
33
- return {
34
- "Model 1 (ResNet) Prediction": f"{result1} (Confidence: {confidence1:.2f})",
35
- "Model 2 (Inception) Prediction": f"{result2} (Confidence: {confidence2:.2f})"
36
- }
37
 
38
  # Create the Gradio interface
39
  iface = gr.Interface(
40
  fn=predict_image,
41
  inputs=gr.Image(),
42
- outputs={
43
- "Model 1 (ResNet) Prediction": gr.Textbox(),
44
- "Model 2 (Inception) Prediction": gr.Textbox()
45
- },
46
  title="Real vs AI-Generated Face Classification",
47
  description="Upload an image to classify whether it's a real face or an AI-generated face using two different models: ResNet-style and Inception-style."
48
  )
 
14
 
15
  def preprocess_image(image):
16
  img = tf.image.resize(image, (224, 224)) # Resize to match the input size of your models
17
+ img = tf.cast(img, tf.float32) / 255.0 # Normalize pixel values
18
+ return tf.expand_dims(img, 0) # Add batch dimension
19
 
20
  def predict_image(image):
21
  preprocessed_image = preprocess_image(image)
 
22
  # Make predictions using both models
23
  pred1 = model1.predict(preprocessed_image)[0][0]
24
  pred2 = model2.predict(preprocessed_image)[0][0]
 
29
  result2 = "Real" if pred2 > 0.5 else "Fake"
30
  confidence2 = pred2 if pred2 > 0.5 else 1 - pred2
31
 
32
+ return (
33
+ f"Model 1 (ResNet) Prediction: {result1} (Confidence: {confidence1:.2f})",
34
+ f"Model 2 (Inception) Prediction: {result2} (Confidence: {confidence2:.2f})"
35
+ )
36
 
37
  # Create the Gradio interface
38
  iface = gr.Interface(
39
  fn=predict_image,
40
  inputs=gr.Image(),
41
+ outputs=[
42
+ gr.Textbox(label="Model 1 (ResNet) Prediction"),
43
+ gr.Textbox(label="Model 2 (Inception) Prediction")
44
+ ],
45
  title="Real vs AI-Generated Face Classification",
46
  description="Upload an image to classify whether it's a real face or an AI-generated face using two different models: ResNet-style and Inception-style."
47
  )