Upload 4 files
Browse files- app.py +39 -0
- deepfake_model_best.h5 +3 -0
- dockerfile.txt +8 -0
- requirements.txt +6 -0
app.py
ADDED
@@ -0,0 +1,39 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
from fastapi import FastAPI, File, UploadFile
|
2 |
+
import uvicorn
|
3 |
+
import numpy as np
|
4 |
+
import tensorflow as tf
|
5 |
+
from PIL import Image
|
6 |
+
import io
|
7 |
+
|
8 |
+
# Load the Keras model (assuming model.h5 is in the same directory)
|
9 |
+
model = tf.keras.models.load_model("deepfake_model_best.h5")
|
10 |
+
|
11 |
+
app = FastAPI()
|
12 |
+
|
13 |
+
# Preprocessing function
|
14 |
+
def preprocess_image(image: Image.Image):
|
15 |
+
image = image.resize((224, 224)) # Resize to model's expected input size
|
16 |
+
image = np.array(image) / 255.0 # Normalize pixel values
|
17 |
+
image = np.expand_dims(image, axis=0) # Add batch dimension
|
18 |
+
return image
|
19 |
+
|
20 |
+
@app.post("/predict")
|
21 |
+
async def predict(file: UploadFile = File(...)):
|
22 |
+
try:
|
23 |
+
# Read image file
|
24 |
+
contents = await file.read()
|
25 |
+
image = Image.open(io.BytesIO(contents)).convert("RGB")
|
26 |
+
|
27 |
+
# Preprocess image
|
28 |
+
image = preprocess_image(image)
|
29 |
+
|
30 |
+
# Make prediction
|
31 |
+
prediction = model.predict(image)
|
32 |
+
|
33 |
+
# Return result
|
34 |
+
return {"prediction": prediction.tolist()}
|
35 |
+
except Exception as e:
|
36 |
+
return {"error": str(e)}
|
37 |
+
|
38 |
+
if __name__ == "__main__":
|
39 |
+
uvicorn.run(app, host="0.0.0.0", port=7860)
|
deepfake_model_best.h5
ADDED
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
1 |
+
version https://git-lfs.github.com/spec/v1
|
2 |
+
oid sha256:190e9b2ec24a7c0945ce2e695f74331939c39bba9979404b29e563741f2062af
|
3 |
+
size 23186048
|
dockerfile.txt
ADDED
@@ -0,0 +1,8 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
FROM python:3.9
|
2 |
+
|
3 |
+
WORKDIR /app
|
4 |
+
COPY . /app
|
5 |
+
|
6 |
+
RUN pip install --no-cache-dir -r requirements.txt
|
7 |
+
|
8 |
+
CMD ["uvicorn", "app:app", "--host", "0.0.0.0", "--port", "7860"]
|
requirements.txt
ADDED
@@ -0,0 +1,6 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
fastapi
|
2 |
+
torch
|
3 |
+
torchvision
|
4 |
+
opencv-python
|
5 |
+
pillow
|
6 |
+
uvicorn
|