Skip to content

Instantly share code, notes, and snippets.

@churnikov
Last active November 6, 2024 13:31
Show Gist options
  • Save churnikov/bded7ea61d5154ff506ae5cd1a7014e6 to your computer and use it in GitHub Desktop.
Save churnikov/bded7ea61d5154ff506ae5cd1a7014e6 to your computer and use it in GitHub Desktop.
# Select base image (can be ubuntu, python, shiny etc)
FROM python:3.11-slim
# Create user name and home directory variables.
# The variables are later used as $USER and $HOME.
ENV USER=username
ENV HOME=/home/$USER
# Add user to system
RUN useradd -m -u 1000 $USER
# Set working directory (this is where the code should go)
WORKDIR $HOME/app
# Update system and install dependencies.
RUN apt-get update && apt-get install --no-install-recommends -y \
build-essential \
software-properties-common
# Copy code and start script (this will place the files in home/username/)
COPY requirements.txt $HOME/app/requirements.txt
RUN pip install --no-cache-dir -r requirements.txt
COPY main.py $HOME/app/main.py
# copy any other files that are needed for your app with the directory structure as your files expect
COPY start-script.sh $HOME/app/start-script.sh
COPY data/ $HOME/app/data
RUN chmod +x start-script.sh \
&& chown -R $USER:$USER $HOME \
&& rm -rf /var/lib/apt/lists/*
RUN python3 -m pip install torch torchvision torchaudio --index-url https://download.pytorch.org/whl/cpu
USER $USER
EXPOSE 7860
ENTRYPOINT ["./start-script.sh"]
'pink primrose'
'hard-leaved pocket orchid'
'canterbury bells'
'sweet pea'
'english marigold'
'tiger lily'
'moon orchid'
'bird of paradise'
'monkshood'
'globe thistle'
'snapdragon'
"colt's foot"
'king protea'
'spear thistle'
'yellow iris'
'globe-flower'
'purple coneflower'
'peruvian lily'
'balloon flower'
'giant white arum lily'
'fire lily'
'pincushion flower'
'fritillary'
'red ginger'
'grape hyacinth'
'corn poppy'
'prince of wales feathers'
'stemless gentian'
'artichoke'
'sweet william'
'carnation'
'garden phlox'
'love in the mist'
'mexican aster'
'alpine sea holly'
'ruby-lipped cattleya'
'cape flower'
'great masterwort'
'siam tulip'
'lenten rose'
'barbeton daisy'
'daffodil'
'sword lily'
'poinsettia'
'bolero deep blue'
'wallflower'
'marigold'
'buttercup'
'oxeye daisy'
'common dandelion'
'petunia'
'wild pansy'
'primula'
'sunflower'
'pelargonium'
'bishop of llandaff'
'gaura'
'geranium'
'orange dahlia'
'pink-yellow dahlia?'
'cautleya spicata'
'japanese anemone'
'black-eyed susan'
'silverbush'
'californian poppy'
'osteospermum'
'spring crocus'
'bearded iris'
'windflower'
'tree poppy'
'gazania'
'azalea'
'water lily'
'rose'
'thorn apple'
'morning glory'
'passion flower'
'lotus'
'toad lily'
'anthurium'
'frangipani'
'clematis'
'hibiscus'
'columbine'
'desert-rose'
'tree mallow'
'magnolia'
'cyclamen '
'watercress'
'canna lily'
'hippeastrum '
'bee balm'
'ball moss'
'foxglove'
'bougainvillea'
'camellia'
'mallow'
'mexican petunia'
'bromelia'
'blanket flower'
'trumpet creeper'
'blackberry lily'
import gradio as gr
import torch
from PIL import Image
from torchvision import transforms
import torchvision.models as models
model = torch.load('data/flower_model_vgg19.pth')
model.eval()
# Download human-readable labels for ImageNet.
with open('data/flower_dataset_labels.txt', 'r') as f:
labels=f.readlines()
def predict(inp):
inp = transforms.ToTensor()(inp).unsqueeze(0)
with torch.no_grad():
prediction = torch.nn.functional.softmax(model(inp)[0], dim=0)
confidences = {labels[i]: float(prediction[i]) for i in range(102)}
return confidences
interface = gr.Interface(fn=predict,
inputs=gr.Image(type="pil"),
outputs=gr.Label(num_top_classes=3))
interface.launch(server_name="0.0.0.0", server_port=7860)
gradio==5.1
httpx==0.24.1
#!/bin/bash
python main.py
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment