JbIPS commited on
Commit
f6414bf
1 Parent(s): d149458

Initial commit

Browse files
.gitattributes CHANGED
@@ -26,3 +26,10 @@ saved_model/**/* filter=lfs diff=lfs merge=lfs -text
26
  *.zip filter=lfs diff=lfs merge=lfs -text
27
  *.zstandard filter=lfs diff=lfs merge=lfs -text
28
  *tfevents* filter=lfs diff=lfs merge=lfs -text
 
 
 
 
 
 
 
 
26
  *.zip filter=lfs diff=lfs merge=lfs -text
27
  *.zstandard filter=lfs diff=lfs merge=lfs -text
28
  *tfevents* filter=lfs diff=lfs merge=lfs -text
29
+ Images filter=lfs diff=lfs merge=lfs -text
30
+ Xception filter=lfs diff=lfs merge=lfs -text
31
+ InceptionV3 filter=lfs diff=lfs merge=lfs -text
32
+ ResNetV2 filter=lfs diff=lfs merge=lfs -text
33
+ VGG-16 filter=lfs diff=lfs merge=lfs -text
34
+ VGG-19 filter=lfs diff=lfs merge=lfs -text
35
+ app/backend/naive_model filter=lfs diff=lfs merge=lfs -text
.gitignore ADDED
@@ -0,0 +1,6 @@
 
 
 
 
 
 
 
1
+ Images
2
+ VGG*
3
+ Xception
4
+ InceptionV3
5
+ ResNetV2
6
+ app/backend/naive_model
P6_01_notebook.ipynb ADDED
The diff for this file is too large to render. See raw diff
 
app/backend/Dockerfile ADDED
@@ -0,0 +1,15 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ # backend/Dockerfile
2
+
3
+ FROM tensorflow/tensorflow:latest-gpu
4
+
5
+ COPY requirements.txt app/requirements.txt
6
+
7
+ WORKDIR /app
8
+
9
+ RUN pip install -r requirements.txt
10
+
11
+ COPY . /app
12
+
13
+ EXPOSE 8000
14
+
15
+ CMD ["uvicorn", "main:app", "--host", "0.0.0.0", "--port", "8000" , "--reload"]
app/backend/__pycache__/main.cpython-38.pyc ADDED
Binary file (1.2 kB). View file
 
app/backend/main.py ADDED
@@ -0,0 +1,40 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import uvicorn
2
+ import json
3
+ import requests
4
+ import numpy as np
5
+ import tensorflow as tf
6
+ from io import BytesIO
7
+ from tensorflow import keras
8
+ from fastapi import FastAPI
9
+ from PIL import Image
10
+ from pydantic import BaseModel
11
+
12
+ race_file = open('race_names.json', 'r')
13
+ race_names = json.load(race_file)
14
+
15
+ image_size = (180, 180)
16
+
17
+ app = FastAPI()
18
+
19
+ model = keras.models.load_model('naive_model')
20
+
21
+
22
+ @app.get("/prediction")
23
+ def get_prediction(q: str):
24
+ response = requests.get(q)
25
+ img = Image.open(BytesIO(response.content)).resize((180, 180))
26
+ img_array = keras.preprocessing.image.img_to_array(img)
27
+ img_array = tf.expand_dims(img_array, 0) # Create batch axis
28
+
29
+ predictions = model.predict(img_array)
30
+
31
+ top4 = predictions.argsort()[0, -1:-5:-1]
32
+
33
+ breakdown = []
34
+ for race, acc in zip(np.array(race_names)[top4], predictions[0, top4]):
35
+ breakdown.append(f'{race} at {acc:.2%}')
36
+ return breakdown
37
+
38
+
39
+ if __name__ == "__main__":
40
+ uvicorn.run("fastapi:app")
app/backend/race_names.json ADDED
@@ -0,0 +1 @@
 
 
1
+ ["Chihuahua", "Japanese Spaniel", "Maltese Dog", "Pekinese", "Shih-Tzu", "Blenheim Spaniel", "Papillon", "Toy Terrier", "Rhodesian Ridgeback", "Afghan Hound", "Basset", "Beagle", "Bloodhound", "Bluetick", "Black-And-Tan Coonhound", "Walker Hound", "English Foxhound", "Redbone", "Borzoi", "Irish Wolfhound", "Italian Greyhound", "Whippet", "Ibizan Hound", "Norwegian Elkhound", "Otterhound", "Saluki", "Scottish Deerhound", "Weimaraner", "Staffordshire Bullterrier", "American Staffordshire Terrier", "Bedlington Terrier", "Border Terrier", "Kerry Blue Terrier", "Irish Terrier", "Norfolk Terrier", "Norwich Terrier", "Yorkshire Terrier", "Wire-Haired Fox Terrier", "Lakeland Terrier", "Sealyham Terrier", "Airedale", "Cairn", "Australian Terrier", "Dandie Dinmont", "Boston Bull", "Miniature Schnauzer", "Giant Schnauzer", "Standard Schnauzer", "Scotch Terrier", "Tibetan Terrier", "Silky Terrier", "Soft-Coated Wheaten Terrier", "West Highland White Terrier", "Lhasa", "Flat-Coated Retriever", "Curly-Coated Retriever", "Golden Retriever", "Labrador Retriever", "Chesapeake Bay Retriever", "German Short-Haired Pointer", "Vizsla", "English Setter", "Irish Setter", "Gordon Setter", "Brittany Spaniel", "Clumber", "English Springer", "Welsh Springer Spaniel", "Cocker Spaniel", "Sussex Spaniel", "Irish Water Spaniel", "Kuvasz", "Schipperke", "Groenendael", "Malinois", "Briard", "Kelpie", "Komondor", "Old English Sheepdog", "Shetland Sheepdog", "Collie", "Border Collie", "Bouvier Des Flandres", "Rottweiler", "German Shepherd", "Doberman", "Miniature Pinscher", "Greater Swiss Mountain Dog", "Bernese Mountain Dog", "Appenzeller", "Entlebucher", "Boxer", "Bull Mastiff", "Tibetan Mastiff", "French Bulldog", "Great Dane", "Saint Bernard", "Eskimo Dog", "Malamute", "Siberian Husky", "Affenpinscher", "Basenji", "Pug", "Leonberg", "Newfoundland", "Great Pyrenees", "Samoyed", "Pomeranian", "Chow", "Keeshond", "Brabancon Griffon", "Pembroke", "Cardigan", "Toy Poodle", "Miniature Poodle", "Standard Poodle", "Mexican Hairless", "Dingo", "Dhole", "African Hunting Dog"]
app/backend/requirements.txt ADDED
@@ -0,0 +1,5 @@
 
 
 
 
 
 
1
+ fastapi==0.74.1
2
+ uvicorn==0.17.5
3
+ pydantic==1.9.0
4
+ tensorflow==2.8.0
5
+ pillow==9.0.1
app/docker-compose.yml ADDED
@@ -0,0 +1,18 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ version: "3.7"
2
+
3
+ services:
4
+ frontend:
5
+ build: frontend
6
+ ports:
7
+ - 8501:8501
8
+ depends_on:
9
+ - backend
10
+ volumes:
11
+ - ./frontend:/app
12
+
13
+ backend:
14
+ build: backend
15
+ ports:
16
+ - 8000:8000
17
+ volumes:
18
+ - ./backend:/app
app/frontend/Dockerfile ADDED
@@ -0,0 +1,14 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ FROM python:3.10
2
+
3
+ COPY requirements.txt app/requirements.txt
4
+
5
+ WORKDIR /app
6
+
7
+ RUN pip install -r requirements.txt
8
+
9
+ COPY . /app
10
+
11
+ EXPOSE 8501
12
+
13
+ ENTRYPOINT ["streamlit","run"]
14
+ CMD ["app.py"]
app/frontend/app.py ADDED
@@ -0,0 +1,50 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import streamlit as st
2
+ import requests
3
+
4
+
5
+ def request_prediction(model_uri, data):
6
+ payload = {'q': data}
7
+ response = requests.get(url=model_uri, params=payload)
8
+
9
+ if response.status_code != 200:
10
+ raise Exception(
11
+ "Request failed with status {}, {}".format(
12
+ response.status_code, response.text))
13
+
14
+ return response.json()
15
+
16
+
17
+ def main():
18
+ API_URI = 'http://backend:8000/prediction'
19
+
20
+ st.set_page_config("Who let's the dogs out")
21
+ st.title('Quelle est ta race de chien totem ?')
22
+
23
+ st.text('''
24
+ Pour découvrir ta race de chien, colle l'adresse d'une photo.
25
+ ''')
26
+ url = st.text_input('URL de la photo')
27
+ predict_btn = st.button('Prédire')
28
+ if predict_btn:
29
+ pred = request_prediction(API_URI, url)
30
+ main_race = pred[0].split(' at')[0].lower()
31
+ main_race = '/'.join(reversed(main_race.replace('-', '').split(' ')))
32
+ if main_race.startswith('husky'):
33
+ main_race = main_race.split('/')[0]
34
+ col1, col2 = st.columns(2)
35
+ with col1:
36
+ st.image(url)
37
+ with col2:
38
+ response = requests.get(url=f'https://dog.ceo/api/breed/{main_race}/images/random').json()
39
+ if response['status'] == 'success':
40
+ st.image(response['message'])
41
+ else:
42
+ st.text(main_race)
43
+ st.text(response)
44
+ st.write('Les races qui te correspondent le plus sont :')
45
+ for race in pred:
46
+ st.write(race)
47
+
48
+
49
+ if __name__ == '__main__':
50
+ main()
app/frontend/requirements.txt ADDED
@@ -0,0 +1,2 @@
 
 
 
1
+ streamlit==1.5.1
2
+ requests==2.27.1
race_names.json ADDED
@@ -0,0 +1 @@
 
 
1
+ ["Chihuahua", "Japanese Spaniel", "Maltese Dog", "Pekinese", "Shih-Tzu", "Blenheim Spaniel", "Papillon", "Toy Terrier", "Rhodesian Ridgeback", "Afghan Hound", "Basset", "Beagle", "Bloodhound", "Bluetick", "Black-And-Tan Coonhound", "Walker Hound", "English Foxhound", "Redbone", "Borzoi", "Irish Wolfhound", "Italian Greyhound", "Whippet", "Ibizan Hound", "Norwegian Elkhound", "Otterhound", "Saluki", "Scottish Deerhound", "Weimaraner", "Staffordshire Bullterrier", "American Staffordshire Terrier", "Bedlington Terrier", "Border Terrier", "Kerry Blue Terrier", "Irish Terrier", "Norfolk Terrier", "Norwich Terrier", "Yorkshire Terrier", "Wire-Haired Fox Terrier", "Lakeland Terrier", "Sealyham Terrier", "Airedale", "Cairn", "Australian Terrier", "Dandie Dinmont", "Boston Bull", "Miniature Schnauzer", "Giant Schnauzer", "Standard Schnauzer", "Scotch Terrier", "Tibetan Terrier", "Silky Terrier", "Soft-Coated Wheaten Terrier", "West Highland White Terrier", "Lhasa", "Flat-Coated Retriever", "Curly-Coated Retriever", "Golden Retriever", "Labrador Retriever", "Chesapeake Bay Retriever", "German Short-Haired Pointer", "Vizsla", "English Setter", "Irish Setter", "Gordon Setter", "Brittany Spaniel", "Clumber", "English Springer", "Welsh Springer Spaniel", "Cocker Spaniel", "Sussex Spaniel", "Irish Water Spaniel", "Kuvasz", "Schipperke", "Groenendael", "Malinois", "Briard", "Kelpie", "Komondor", "Old English Sheepdog", "Shetland Sheepdog", "Collie", "Border Collie", "Bouvier Des Flandres", "Rottweiler", "German Shepherd", "Doberman", "Miniature Pinscher", "Greater Swiss Mountain Dog", "Bernese Mountain Dog", "Appenzeller", "Entlebucher", "Boxer", "Bull Mastiff", "Tibetan Mastiff", "French Bulldog", "Great Dane", "Saint Bernard", "Eskimo Dog", "Malamute", "Siberian Husky", "Affenpinscher", "Basenji", "Pug", "Leonberg", "Newfoundland", "Great Pyrenees", "Samoyed", "Pomeranian", "Chow", "Keeshond", "Brabancon Griffon", "Pembroke", "Cardigan", "Toy Poodle", "Miniature Poodle", "Standard Poodle", "Mexican Hairless", "Dingo", "Dhole", "African Hunting Dog"]