Spaces:
Running
Running
File size: 1,420 Bytes
9ca0a51 743f73f 9ca0a51 8775ba7 9ca0a51 8775ba7 9ca0a51 8775ba7 9ca0a51 8775ba7 |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 |
# Transformers and its models
import transformers
# For Image Processing
from transformers import ViTImageProcessor
# For Model
from transformers import ViTModel, ViTConfig
# For data augmentation
from torchvision import transforms, datasets
# For GPU
from transformers import set_seed
from torch.optim import AdamW
from accelerate import Accelerator, notebook_launcher
# For Data Loaders
import datasets
from torch.utils.data import Dataset, DataLoader
# For Display
from tqdm.notebook import tqdm
# Other Generic Libraries
import torch
import PIL
import streamlit as st
import gc
from glob import glob
import shutil
import torch.nn.functional as F
# Initialse Globle Variables
MODEL_TRANSFORMER = 'google/vit-base-patch16-224'
BATCH_SIZE = 8
# Set the device (GPU or CPU)
device = torch.device("cuda" if torch.cuda.is_available() else "cpu")
pipeline = pipeline(task="image-classification", model="julien-c/hotdog-not-hotdog")
st.title("Hot Dog? Or Not?")
# Read images from directory
# Read image from Camera
enable = st.checkbox("Enable camera")
picture = st.camera_input("Take a picture", disabled=not enable)
if picture:
col1, col2 = st.columns(2)
image = PIL.Image.open(picture)
col1.image(image, use_column_width=True)
predictions = pipeline(image)
col2.header("Probabilities")
for p in predictions:
col2.subheader(f"{ p['label'] }: { round(p['score'] * 100, 1)}%") |