Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
|
@@ -1,4 +1,3 @@
|
|
| 1 |
-
|
| 2 |
import gradio as gr
|
| 3 |
import os
|
| 4 |
import torch
|
|
@@ -8,12 +7,14 @@ from timeit import default_timer as timer
|
|
| 8 |
from typing import Tuple, Dict
|
| 9 |
|
| 10 |
# Setup class names
|
| 11 |
-
class_names = ['
|
| 12 |
|
| 13 |
### 2. Model and transforms preparation ###
|
| 14 |
|
| 15 |
# Create model
|
| 16 |
-
model,
|
|
|
|
|
|
|
| 17 |
|
| 18 |
# Load saved weights
|
| 19 |
model.load_state_dict(
|
|
@@ -33,7 +34,7 @@ def predict(img) -> Tuple[Dict, float]:
|
|
| 33 |
start_time = timer()
|
| 34 |
|
| 35 |
# Transform the target image and add a batch dimension
|
| 36 |
-
img =
|
| 37 |
|
| 38 |
# Put model into evaluation mode and turn on inference mode
|
| 39 |
model.eval()
|
|
@@ -54,7 +55,22 @@ def predict(img) -> Tuple[Dict, float]:
|
|
| 54 |
|
| 55 |
# Create title, description and article strings
|
| 56 |
title = "Reality Check"
|
| 57 |
-
description = "
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 58 |
article = "Created at [Real Or Fake]"
|
| 59 |
|
| 60 |
# Create examples list from "examples/" directory
|
|
@@ -72,4 +88,4 @@ demo = gr.Interface(fn=predict, # mapping function from input to output
|
|
| 72 |
article=article)
|
| 73 |
|
| 74 |
# Launch the demo!
|
| 75 |
-
demo.launch()
|
|
|
|
|
|
|
| 1 |
import gradio as gr
|
| 2 |
import os
|
| 3 |
import torch
|
|
|
|
| 7 |
from typing import Tuple, Dict
|
| 8 |
|
| 9 |
# Setup class names
|
| 10 |
+
class_names = ['Fake', 'Real']
|
| 11 |
|
| 12 |
### 2. Model and transforms preparation ###
|
| 13 |
|
| 14 |
# Create model
|
| 15 |
+
model, transforms = create_model(
|
| 16 |
+
num_classes=2,
|
| 17 |
+
)
|
| 18 |
|
| 19 |
# Load saved weights
|
| 20 |
model.load_state_dict(
|
|
|
|
| 34 |
start_time = timer()
|
| 35 |
|
| 36 |
# Transform the target image and add a batch dimension
|
| 37 |
+
img = transforms(img).unsqueeze(0)
|
| 38 |
|
| 39 |
# Put model into evaluation mode and turn on inference mode
|
| 40 |
model.eval()
|
|
|
|
| 55 |
|
| 56 |
# Create title, description and article strings
|
| 57 |
title = "Reality Check"
|
| 58 |
+
description = """<h2>AI Image Classifier: Real vs. Fake Faces</h2>
|
| 59 |
+
<p>Our computer vision model is designed to classify images of faces as either real or AI-generated with a 95% accuracy rate. This model is specifically trained to analyze facial features, so please ensure that the images you upload prominently feature visible faces.</p>
|
| 60 |
+
<h3>Important Guidelines:</h3>
|
| 61 |
+
<ul>
|
| 62 |
+
<li><strong>Focus on Faces:</strong> Ensure the uploaded images clearly show faces. The model is optimized for facial recognition and classification.</li>
|
| 63 |
+
<li><strong>Image Examples:</strong> Refer to the examples below to understand the type of images suitable for classification.</li>
|
| 64 |
+
<li><strong>Avoid Other AI-Generated Content:</strong> Do not upload images of objects, landscapes, or any non-facial AI-generated content as the model is not trained to classify these correctly.</li>
|
| 65 |
+
</ul>
|
| 66 |
+
<h3>Usage Instructions:</h3>
|
| 67 |
+
<ol>
|
| 68 |
+
<li><strong>Prepare Your Image:</strong> Ensure the face is visible and prominent.</li>
|
| 69 |
+
<li><strong>Upload the Image:</strong> Use the provided interface to upload your image for classification.</li>
|
| 70 |
+
<li><strong>Receive Classification:</strong> The model will analyze the facial features and classify the image as either real or fake with 95% accuracy.</li>
|
| 71 |
+
</ol>
|
| 72 |
+
<p>Start using the model now to see the power of AI in distinguishing between real and AI-generated faces!</p>
|
| 73 |
+
"""
|
| 74 |
article = "Created at [Real Or Fake]"
|
| 75 |
|
| 76 |
# Create examples list from "examples/" directory
|
|
|
|
| 88 |
article=article)
|
| 89 |
|
| 90 |
# Launch the demo!
|
| 91 |
+
demo.launch()
|