Spaces:
Sleeping
Sleeping
ignore temp files
Browse files- .gitignore +2 -0
- Dockerfile +9 -0
- docker-compose.yml +14 -0
- main.py +15 -11
.gitignore
CHANGED
@@ -158,3 +158,5 @@ cython_debug/
|
|
158 |
# and can be added to the global gitignore or merged into this file. For a more nuclear
|
159 |
# option (not recommended) you can uncomment the following to ignore the entire idea folder.
|
160 |
#.idea/
|
|
|
|
|
|
158 |
# and can be added to the global gitignore or merged into this file. For a more nuclear
|
159 |
# option (not recommended) you can uncomment the following to ignore the entire idea folder.
|
160 |
#.idea/
|
161 |
+
|
162 |
+
models/
|
Dockerfile
CHANGED
@@ -15,6 +15,15 @@ RUN apt-get update && apt-get install -y \
|
|
15 |
# Copy the current directory contents into the container at /app
|
16 |
COPY . /app
|
17 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
18 |
# Install any needed packages specified in requirements.txt
|
19 |
RUN pip install --no-cache-dir -r requirements.txt
|
20 |
|
|
|
15 |
# Copy the current directory contents into the container at /app
|
16 |
COPY . /app
|
17 |
|
18 |
+
# RUN useradd -m -u 1000 user
|
19 |
+
# USER user
|
20 |
+
# ENV HOME=/home/user \
|
21 |
+
# PATH=/home/user/.local/bin:$PATH
|
22 |
+
|
23 |
+
# WORKDIR $HOME/app
|
24 |
+
|
25 |
+
# COPY --chown=user . $HOME/app
|
26 |
+
|
27 |
# Install any needed packages specified in requirements.txt
|
28 |
RUN pip install --no-cache-dir -r requirements.txt
|
29 |
|
docker-compose.yml
ADDED
@@ -0,0 +1,14 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
version: "1.0"
|
2 |
+
|
3 |
+
services:
|
4 |
+
backend:
|
5 |
+
container_name: backend
|
6 |
+
build: .
|
7 |
+
working_dir: /app
|
8 |
+
command: uvicorn main:app --host 0.0.0.0 --port 7680 --reload
|
9 |
+
environment:
|
10 |
+
- WATCHFILES_FORCE_POLLING=true
|
11 |
+
ports:
|
12 |
+
- "80:7680"
|
13 |
+
restart: on-failure
|
14 |
+
|
main.py
CHANGED
@@ -6,12 +6,18 @@ from fastapi import FastAPI, File, UploadFile, HTTPException
|
|
6 |
from fastapi.responses import JSONResponse
|
7 |
|
8 |
import os
|
9 |
-
|
10 |
-
|
11 |
-
os.environ[
|
12 |
-
os.environ[
|
13 |
-
|
14 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
15 |
|
16 |
from transformers import AutoImageProcessor, ViTForImageClassification
|
17 |
from PIL import Image
|
@@ -34,7 +40,9 @@ cache = Cache(maxsize=1000)
|
|
34 |
|
35 |
# Load the model using the transformers pipeline
|
36 |
# model = pipeline("image-classification", model="Wvolf/ViT_Deepfake_Detection")
|
37 |
-
|
|
|
|
|
38 |
# Detect the device used by TensorFlow
|
39 |
# DEVICE = "GPU" if tf.config.list_physical_devices("GPU") else "CPU"
|
40 |
# logging.info("TensorFlow version: %s", tf.__version__)
|
@@ -87,8 +95,6 @@ async def classify_image(file: UploadFile = File(None)):
|
|
87 |
|
88 |
image = Image.open(io.BytesIO(image_data))
|
89 |
|
90 |
-
image_processor = AutoImageProcessor.from_pretrained("Wvolf/ViT_Deepfake_Detection")
|
91 |
-
model = ViTForImageClassification.from_pretrained("Wvolf/ViT_Deepfake_Detection")
|
92 |
inputs = image_processor(image, return_tensors="pt")
|
93 |
|
94 |
with torch.no_grad():
|
@@ -174,8 +180,6 @@ async def classify_images(request: ImageUrlsRequest):
|
|
174 |
continue
|
175 |
|
176 |
image = Image.open(io.BytesIO(image_data))
|
177 |
-
image_processor = AutoImageProcessor.from_pretrained("Wvolf/ViT_Deepfake_Detection")
|
178 |
-
model = ViTForImageClassification.from_pretrained("Wvolf/ViT_Deepfake_Detection")
|
179 |
inputs = image_processor(image, return_tensors="pt")
|
180 |
|
181 |
with torch.no_grad():
|
|
|
6 |
from fastapi.responses import JSONResponse
|
7 |
|
8 |
import os
|
9 |
+
from os import path
|
10 |
+
cache_path = path.join(path.dirname(path.abspath(__file__)), "models")
|
11 |
+
os.environ["HF_HUB_CACHE"] = cache_path
|
12 |
+
os.environ["HF_HOME"] = cache_path
|
13 |
+
|
14 |
+
# PATH = 'huggingface'
|
15 |
+
# DATASETPATH = '/home/ahmadzen/.cache/huggingface/datasets'
|
16 |
+
# MODEL_PATH = '/home/ahmadzen/ViT_Deepfake_Detection/SavedModel'
|
17 |
+
# os.environ['HF_HOME'] = PATH
|
18 |
+
# os.environ['HF_DATASETS_CACHE'] = DATASETPATH
|
19 |
+
# os.environ['TORCH_HOME'] = PATH
|
20 |
+
# os.environ['HF_HUB_CACHE'] = '/home/ahmadzen/.cache/huggingface'
|
21 |
|
22 |
from transformers import AutoImageProcessor, ViTForImageClassification
|
23 |
from PIL import Image
|
|
|
40 |
|
41 |
# Load the model using the transformers pipeline
|
42 |
# model = pipeline("image-classification", model="Wvolf/ViT_Deepfake_Detection")
|
43 |
+
image_processor = AutoImageProcessor.from_pretrained("Wvolf/ViT_Deepfake_Detection")
|
44 |
+
model = ViTForImageClassification.from_pretrained("Wvolf/ViT_Deepfake_Detection")
|
45 |
+
|
46 |
# Detect the device used by TensorFlow
|
47 |
# DEVICE = "GPU" if tf.config.list_physical_devices("GPU") else "CPU"
|
48 |
# logging.info("TensorFlow version: %s", tf.__version__)
|
|
|
95 |
|
96 |
image = Image.open(io.BytesIO(image_data))
|
97 |
|
|
|
|
|
98 |
inputs = image_processor(image, return_tensors="pt")
|
99 |
|
100 |
with torch.no_grad():
|
|
|
180 |
continue
|
181 |
|
182 |
image = Image.open(io.BytesIO(image_data))
|
|
|
|
|
183 |
inputs = image_processor(image, return_tensors="pt")
|
184 |
|
185 |
with torch.no_grad():
|