jdmartinev commited on
Commit
015a9ca
·
1 Parent(s): 249d03b
Files changed (2) hide show
  1. app.py +9 -13
  2. requirements.txt +1 -1
app.py CHANGED
@@ -1,22 +1,18 @@
1
- import streamlit as st
2
  from fastai.learner import load_learner
3
  from fastai.vision.core import PILImage
4
  from huggingface_hub import hf_hub_download
5
 
6
 
7
- st.title("Fastai Image Classifier")
8
-
9
  learner = load_learner(hf_hub_download("jdmartinev/intel_image_classification_fastai","model.pkl"))
10
 
11
- uploaded_img = st.file_uploader("Upload an image", type=["png", "jpg", "jpeg"])
12
-
13
-
14
- if uploaded_img:
15
- st.image(uploaded_img, caption="Uploaded Image", use_column_width=True)
16
- img = PILImage.create(uploaded_img)
17
-
18
- # Make predictions
19
- pred_class, pred_idx, outputs = learner.predict(img)
20
- st.write(f"Predicted class: {pred_class}")
21
 
 
 
 
22
 
 
 
1
+ import gradio as gr
2
  from fastai.learner import load_learner
3
  from fastai.vision.core import PILImage
4
  from huggingface_hub import hf_hub_download
5
 
6
 
 
 
7
  learner = load_learner(hf_hub_download("jdmartinev/intel_image_classification_fastai","model.pkl"))
8
 
9
+ def classify_image(image):
10
+ img = PILImage.create(image)
11
+ pred_class, pred_idx, outputs = learn.predict(img)
12
+ return f"Predicted class: {pred_class}"
 
 
 
 
 
 
13
 
14
+ interface = gr.Interface(fn=classify_image,
15
+ inputs=gr.inputs.Image(type="file", label="Upload an Image"),
16
+ outputs="text")
17
 
18
+ interface.launch()
requirements.txt CHANGED
@@ -1,2 +1,2 @@
1
- streamlit
2
  fastai
 
1
+ gradio
2
  fastai