panditamey commited on
Commit
7990ed8
0 Parent(s):

Duplicate from panditamey/flowerClassification

Browse files
Files changed (5) hide show
  1. .gitattributes +34 -0
  2. Dockerfile +27 -0
  3. README.md +11 -0
  4. api.py +55 -0
  5. requirements.txt +10 -0
.gitattributes ADDED
@@ -0,0 +1,34 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ *.7z filter=lfs diff=lfs merge=lfs -text
2
+ *.arrow filter=lfs diff=lfs merge=lfs -text
3
+ *.bin filter=lfs diff=lfs merge=lfs -text
4
+ *.bz2 filter=lfs diff=lfs merge=lfs -text
5
+ *.ckpt filter=lfs diff=lfs merge=lfs -text
6
+ *.ftz filter=lfs diff=lfs merge=lfs -text
7
+ *.gz filter=lfs diff=lfs merge=lfs -text
8
+ *.h5 filter=lfs diff=lfs merge=lfs -text
9
+ *.joblib filter=lfs diff=lfs merge=lfs -text
10
+ *.lfs.* filter=lfs diff=lfs merge=lfs -text
11
+ *.mlmodel filter=lfs diff=lfs merge=lfs -text
12
+ *.model filter=lfs diff=lfs merge=lfs -text
13
+ *.msgpack filter=lfs diff=lfs merge=lfs -text
14
+ *.npy filter=lfs diff=lfs merge=lfs -text
15
+ *.npz filter=lfs diff=lfs merge=lfs -text
16
+ *.onnx filter=lfs diff=lfs merge=lfs -text
17
+ *.ot filter=lfs diff=lfs merge=lfs -text
18
+ *.parquet filter=lfs diff=lfs merge=lfs -text
19
+ *.pb filter=lfs diff=lfs merge=lfs -text
20
+ *.pickle filter=lfs diff=lfs merge=lfs -text
21
+ *.pkl filter=lfs diff=lfs merge=lfs -text
22
+ *.pt filter=lfs diff=lfs merge=lfs -text
23
+ *.pth filter=lfs diff=lfs merge=lfs -text
24
+ *.rar filter=lfs diff=lfs merge=lfs -text
25
+ *.safetensors filter=lfs diff=lfs merge=lfs -text
26
+ saved_model/**/* filter=lfs diff=lfs merge=lfs -text
27
+ *.tar.* filter=lfs diff=lfs merge=lfs -text
28
+ *.tflite filter=lfs diff=lfs merge=lfs -text
29
+ *.tgz filter=lfs diff=lfs merge=lfs -text
30
+ *.wasm filter=lfs diff=lfs merge=lfs -text
31
+ *.xz filter=lfs diff=lfs merge=lfs -text
32
+ *.zip filter=lfs diff=lfs merge=lfs -text
33
+ *.zst filter=lfs diff=lfs merge=lfs -text
34
+ *tfevents* filter=lfs diff=lfs merge=lfs -text
Dockerfile ADDED
@@ -0,0 +1,27 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ # Use the official Python 3.9 image
2
+ FROM python:3.9
3
+
4
+ # Set the working directory to /code
5
+ WORKDIR /code
6
+
7
+ # Copy the current directory contents into the container at /code
8
+ COPY ./requirements.txt /code/requirements.txt
9
+
10
+ # Install requirements.txt
11
+ RUN pip install --no-cache-dir --upgrade -r /code/requirements.txt
12
+
13
+ # Set up a new user named "user" with user ID 1000
14
+ RUN useradd -m -u 1000 user
15
+ # Switch to the "user" user
16
+ USER user
17
+ # Set home to the user's home directory
18
+ ENV HOME=/home/user \
19
+ PATH=/home/user/.local/bin:$PATH
20
+
21
+ # Set the working directory to the user's home directory
22
+ WORKDIR $HOME/app
23
+
24
+ # Copy the current directory contents into the container at $HOME/app setting the owner to the user
25
+ COPY --chown=user . $HOME/app
26
+
27
+ CMD ["uvicorn", "api:app", "--host", "0.0.0.0", "--port", "7860"]
README.md ADDED
@@ -0,0 +1,11 @@
 
 
 
 
 
 
 
 
 
 
 
 
1
+ ---
2
+ title: FlowerClassification
3
+ emoji: 📉
4
+ colorFrom: red
5
+ colorTo: blue
6
+ sdk: docker
7
+ pinned: false
8
+ duplicated_from: panditamey/flowerClassification
9
+ ---
10
+
11
+ Check out the configuration reference at https://huggingface.co/docs/hub/spaces-config-reference
api.py ADDED
@@ -0,0 +1,55 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ from fastapi import FastAPI,UploadFile,File
2
+ from pydantic import BaseModel
3
+ import pickle
4
+ import json
5
+ import pandas as pd
6
+ from tensorflow.keras.models import load_model
7
+ from tensorflow.keras.preprocessing import image
8
+ from tensorflow.keras.applications.inception_v3 import preprocess_input
9
+ import numpy as np
10
+ import os
11
+ import gdown
12
+ import lightgbm as lgb
13
+ from PIL import Image
14
+
15
+ CHUNK_SIZE = 1024
16
+
17
+ app = FastAPI(
18
+ title='Flower Classification API',
19
+ description='API for Flower Classification',
20
+ )
21
+
22
+ id = "1ry4L9L1-kyc79F1MnYMemJ5P81Gr_mHP"
23
+ output = "model_flowers_classification.h5"
24
+ gdown.download(id=id, output=output, quiet=False)
25
+ # from zipfile import ZipFile
26
+ # with ZipFile("modelcrops.zip", 'r') as zObject:
27
+ # zObject.extractall(
28
+ # path="")
29
+
30
+
31
+ predict_ml=load_model('model_flowers_classification.h5')
32
+
33
+
34
+ @app.post('/predict')
35
+ async def flowerpredict(file: UploadFile = File(...)):
36
+ try:
37
+ contents = file.file.read()
38
+ with open(file.filename, 'wb') as f:
39
+ f.write(contents)
40
+ except Exception:
41
+ return {"message": "There was an error uploading the file"}
42
+ finally:
43
+ file.file.close()
44
+ classes = ['Lilly','Lotus','Orchid','Sunflower', 'Tulip']
45
+ img=image.load_img(str(file.filename),target_size=(224,224))
46
+ x=image.img_to_array(img)
47
+ x=x/255
48
+ img_data=np.expand_dims(x,axis=0)
49
+ prediction = predict_ml.predict(img_data)
50
+ predictions = list(prediction[0])
51
+ max_num = max(predictions)
52
+ index = predictions.index(max_num)
53
+ print(classes[index])
54
+ os.remove(str(file.filename))
55
+ return {"output":classes[index]}
requirements.txt ADDED
@@ -0,0 +1,10 @@
 
 
 
 
 
 
 
 
 
 
 
1
+ fastapi
2
+ pydantic
3
+ pandas
4
+ tensorflow
5
+ numpy
6
+ uvicorn
7
+ lightgbm
8
+ gdown
9
+ python-multipart
10
+ Pillow