adarsh-007 commited on
Commit
d0233e6
·
verified ·
1 Parent(s): 1e65a33

Upload 4 files

Browse files
Files changed (4) hide show
  1. Dockerfile +25 -0
  2. app.py +25 -0
  3. export.pkl +3 -0
  4. requirements.txt +4 -0
Dockerfile ADDED
@@ -0,0 +1,25 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ FROM python:3.12.3
2
+
3
+ WORKDIR /app
4
+
5
+ COPY ./requirements.txt /app/requirements.txt
6
+
7
+ RUN pip install --no-cache-dir --upgrade -r /app/requirements.txt
8
+
9
+ # Set up a new user named "user" with user ID 1000
10
+ RUN useradd -m -u 1000 user
11
+
12
+ # Switch to the "user" user
13
+ USER user
14
+
15
+ # Set home to the user's home directory
16
+ ENV HOME=/home/user \
17
+ PATH=/home/user/.local/bin:$PATH
18
+
19
+ # Set the working directory to the user's home directory
20
+ WORKDIR $HOME/app
21
+
22
+ # Copy the current directory contents into the container at $HOME/app setting the owner to the user
23
+ COPY --chown=user ./export.pkl ./app.py ./
24
+
25
+ CMD ["python", "app.py"]
app.py ADDED
@@ -0,0 +1,25 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import gradio as gr
2
+ from fastai.vision.all import load_learner, PILImage
3
+
4
+ # Load your exported fastai model
5
+ model_path = "export.pkl" # your exported .pkl
6
+ learn = load_learner(model_path)
7
+
8
+ # Prediction function
9
+ def predict(image):
10
+ img = PILImage.create(image) # ensure it's a fastai PILImage
11
+ pred_class, pred_idx, outputs = learn.predict(img)
12
+
13
+ return (str(pred_class))
14
+
15
+ # Gradio interface
16
+ iface = gr.Interface(
17
+ fn=predict,
18
+ inputs=gr.Image(type="pil"),
19
+ outputs=gr.Textbox(label="Prediction"),
20
+ title="FastAI Image Classification",
21
+ description="Upload an image to get prediction from your exported fastai model."
22
+ )
23
+
24
+ if __name__ == "__main__":
25
+ iface.launch(server_name="0.0.0.0", server_port=7860)
export.pkl ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:0f94fddede2a9a570ea61a396703a9120c402cd5028e7317d9f98af2482d1db6
3
+ size 46986313
requirements.txt ADDED
@@ -0,0 +1,4 @@
 
 
 
 
 
1
+ fastai==2.8.6
2
+ gradio==6.2.0
3
+ torch==2.9.1
4
+ IPython