devdata commited on
Commit
8f9f98b
·
1 Parent(s): 3d0818e

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +20 -28
app.py CHANGED
@@ -1,28 +1,20 @@
1
- from transformers import MobileNetV2FeatureExtractor, MobileNetV2ForImageClassification, MobileNetV2Config
2
- from PIL import Image
3
-
4
- # Replace with the path to the directory containing the model files
5
- model_folder = "mobilnetV2_ftprecmodelshuf.weights.best.hdf5"
6
-
7
- # Load the configuration
8
- config = MobileNetV2Config.from_pretrained(model_folder)
9
-
10
- # Create the feature extractor using the loaded configuration
11
- feature_extractor = MobileNetV2FeatureExtractor(config)
12
-
13
- # Load the model
14
- model = MobileNetV2ForImageClassification.from_pretrained(model_folder)
15
-
16
- # Load the image
17
- image = Image.open("test_image.png")
18
-
19
- # Preprocess the image
20
- inputs = feature_extractor(images=image, return_tensors="pt")
21
-
22
- # Make predictions
23
- outputs = model(**inputs)
24
- logits = outputs.logits
25
-
26
- # Model predicts one of the 1000 ImageNet classes
27
- predicted_class_idx = logits.argmax(-1).item()
28
- print("Predicted class:", model.config.id2label[predicted_class_idx])
 
1
+ import gradio as gr
2
+ from fastai.vision.all import *
3
+ import skimage
4
+
5
+ learn = load_learner('export.pkl')
6
+
7
+ labels = learn.dls.vocab
8
+ def predict(img):
9
+ img = PILImage.create(img)
10
+ pred,pred_idx,probs = learn.predict(img)
11
+ return {labels[i]: float(probs[i]) for i in range(len(labels))}
12
+
13
+ title = "Kapu"
14
+ description = "An app for Chicken Disease Classisfication"
15
+ article="<p style='text-align: center'>The app identifies and classifies three chicken diseases: Coccidiosis, Salmonella, and Newcastle, aiding in effective disease management for poultry farming.</p>"
16
+ examples = ['test_image.jpg']
17
+ interpretation='default'
18
+ enable_queue=True
19
+
20
+ gr.Interface(fn=predict,inputs=gr.inputs.Image(shape=(512, 512)),outputs=gr.outputs.Label(num_top_classes=3),title=title,description=description,article=article,examples=examples,interpretation=interpretation,enable_queue=enable_queue).launch()