Spaces:
Sleeping
Sleeping
adding webcam feature
Browse files
app.py
CHANGED
|
@@ -1,17 +1,55 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
import streamlit as st
|
| 2 |
-
|
| 3 |
-
from
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 4 |
|
| 5 |
pipeline = pipeline(task="image-classification", model="julien-c/hotdog-not-hotdog")
|
| 6 |
|
| 7 |
st.title("Hot Dog? Or Not?")
|
| 8 |
|
| 9 |
-
|
| 10 |
|
| 11 |
-
if file_name is not None:
|
| 12 |
-
col1, col2 = st.columns(2)
|
| 13 |
|
| 14 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 15 |
col1.image(image, use_column_width=True)
|
| 16 |
predictions = pipeline(image)
|
| 17 |
|
|
|
|
| 1 |
+
# Transformers and its models
|
| 2 |
+
import transformers
|
| 3 |
+
|
| 4 |
+
# For Image Processing
|
| 5 |
+
from transformers import ViTImageProcessor
|
| 6 |
+
|
| 7 |
+
# For Model
|
| 8 |
+
from transformers import ViTModel, ViTConfig
|
| 9 |
+
|
| 10 |
+
# For data augmentation
|
| 11 |
+
from torchvision import transforms, datasets
|
| 12 |
+
|
| 13 |
+
# For GPU
|
| 14 |
+
from transformers import set_seed
|
| 15 |
+
from torch.optim import AdamW
|
| 16 |
+
from accelerate import Accelerator, notebook_launcher
|
| 17 |
+
|
| 18 |
+
# For Data Loaders
|
| 19 |
+
import datasets
|
| 20 |
+
from torch.utils.data import Dataset, DataLoader
|
| 21 |
+
|
| 22 |
+
# For Display
|
| 23 |
+
from tqdm.notebook import tqdm
|
| 24 |
+
|
| 25 |
+
# Other Generic Libraries
|
| 26 |
+
import PIL
|
| 27 |
import streamlit as st
|
| 28 |
+
import gc
|
| 29 |
+
from glob import glob
|
| 30 |
+
import shutil
|
| 31 |
+
import torch.nn.functional as F
|
| 32 |
+
|
| 33 |
+
# Initialse Globle Variables
|
| 34 |
+
MODEL_TRANSFORMER = 'google/vit-base-patch16-224'
|
| 35 |
+
BATCH_SIZE = 8
|
| 36 |
+
|
| 37 |
+
# Set the device (GPU or CPU)
|
| 38 |
+
device = torch.device("cuda" if torch.cuda.is_available() else "cpu")
|
| 39 |
|
| 40 |
pipeline = pipeline(task="image-classification", model="julien-c/hotdog-not-hotdog")
|
| 41 |
|
| 42 |
st.title("Hot Dog? Or Not?")
|
| 43 |
|
| 44 |
+
# Read images from directory
|
| 45 |
|
|
|
|
|
|
|
| 46 |
|
| 47 |
+
# Read image from Camera
|
| 48 |
+
enable = st.checkbox("Enable camera")
|
| 49 |
+
picture = st.camera_input("Take a picture", disabled=not enable)
|
| 50 |
+
if picture:
|
| 51 |
+
col1, col2 = st.columns(2)
|
| 52 |
+
image = PIL.Image.open(picture)
|
| 53 |
col1.image(image, use_column_width=True)
|
| 54 |
predictions = pipeline(image)
|
| 55 |
|