Mirikram commited on
Commit
10a92b6
·
verified ·
1 Parent(s): 19d9da6

All files are added

Browse files
Files changed (5) hide show
  1. Dockerfile +15 -0
  2. frontend.py +33 -0
  3. main.py +61 -0
  4. model.pkl +3 -0
  5. requirements.txt +0 -0
Dockerfile ADDED
@@ -0,0 +1,15 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ FROM python:3.10-slim
2
+
3
+ WORKDIR /app
4
+ COPY requirements.txt .
5
+ RUN pip install --no-cache-dir -r requirements.txt
6
+
7
+ COPY . .
8
+
9
+ # expose FastAPI on port 8000
10
+ EXPOSE 8000
11
+ # expose Streamlit on port 8501
12
+ EXPOSE 8501
13
+
14
+ # run both in parallel
15
+ CMD ["sh", "-c", "uvicorn main:app --host 0.0.0.0 --port 8000 & streamlit run frontend.py --server.port=8501 --server.address=0.0.0.0"]
frontend.py ADDED
@@ -0,0 +1,33 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import streamlit as st
2
+ import requests
3
+
4
+ API_URL='http://127.0.0.1:8000/prediction'
5
+
6
+ st.title("Iris Flower Predictor")
7
+ st.markdown("Enter the flower samples below")
8
+
9
+ sepal_length = st.number_input('Sepal_length',min_value=0.1,max_value=10.0,value=4.0)
10
+ sepal_width =st.number_input('sepal_width',min_value=0.1,max_value=10.1,value=5.0)
11
+ petal_length = st.number_input('Petal_legth',max_value=10.1,min_value=0.1,value=5.0)
12
+ petal_width = st.number_input('petal_width',max_value=10.1,min_value=0.1,value=4.0)
13
+
14
+ if st.button('predict Flower class'):
15
+ input_data ={
16
+ 'sepal_length':sepal_length,
17
+ 'sepal_width': sepal_width,
18
+ 'petal_length': petal_length,
19
+ 'petal_width': petal_width
20
+ }
21
+
22
+ try:
23
+ response = requests.post(API_URL,json=input_data)
24
+ if response.status_code==200:
25
+ predicition =response.json()
26
+ st.success(f"prediction: {predicition['Predicted Class']}")
27
+
28
+ else:
29
+ st.error(f"Error: {response.status_code}-{response.txt}")
30
+
31
+
32
+ except Exception as e:
33
+ st.error(f'An error occcurred:{e}')
main.py ADDED
@@ -0,0 +1,61 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ from fastapi import FastAPI
2
+ import pickle
3
+ from pydantic import BaseModel ,Field
4
+ from typing import Annotated
5
+ from fastapi.responses import JSONResponse
6
+
7
+ with open('model.pkl','rb') as f :
8
+ model = pickle.load(f)
9
+
10
+
11
+ class data_validation(BaseModel):
12
+ sepal_length : Annotated[float,Field(...,description='Enter the sepal length',examples=['0.1 to 10'],gt=0,le=10)]
13
+ sepal_width : Annotated[float,Field(...,description='Enter the sepal width',examples=['0.1 to 10'],gt=0 ,le=10)]
14
+ petal_length : Annotated[float,Field(...,description='Enter the petal legth',examples=['0.1 to 10'],gt=0,le=10)]
15
+ petal_width : Annotated[float,Field(...,description='Enter the petal width',examples=['0.1 to 10'],gt=0,le=10)]
16
+
17
+
18
+
19
+
20
+ app = FastAPI()
21
+
22
+
23
+ @app.get("/")
24
+ def start():
25
+ return {'message':'Welcome to iris classifier'}
26
+
27
+
28
+
29
+ @app.post("/prediction")
30
+ def prediction_by_model(data:data_validation):
31
+
32
+ input_data = [[
33
+ data.sepal_length,
34
+ data.sepal_width,
35
+ data.petal_length,
36
+ data.petal_width
37
+ ]]
38
+
39
+ prediction = model.predict(input_data)[0]
40
+ def prediction_class(prediction:prediction):
41
+
42
+ if int(prediction)==0:
43
+ return 'ris setosa'
44
+
45
+ elif int(prediction)==1:
46
+ return 'Iris virginica'
47
+
48
+ elif int(prediction)==2:
49
+ return 'Iris versicolo'
50
+
51
+ else:
52
+ return "unknow"
53
+
54
+
55
+
56
+ return JSONResponse(status_code=200,content={'Predicted Class':prediction_class(prediction)})
57
+
58
+
59
+
60
+
61
+
model.pkl ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:62ab9d2eab2b83e6afce108e988f275671ad9e3696aa351bb01b036db60dfef6
3
+ size 178269
requirements.txt ADDED
Binary file (332 Bytes). View file