Docty commited on
Commit
33bc438
·
verified ·
1 Parent(s): 0a2908c

Create app.py

Browse files
Files changed (1) hide show
  1. app.py +34 -0
app.py ADDED
@@ -0,0 +1,34 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import gradio as gr
2
+ from PIL import Image
3
+ from transformers import pipeline
4
+
5
+
6
+ classifier = pipeline("image-classification", model="Docty/mango-samu")
7
+
8
+ def classify_image(img):
9
+ if not isinstance(img, Image.Image):
10
+ img = Image.fromarray(img)
11
+ results = classifier(img)
12
+ return {res["label"]: float(res["score"]) for res in results}
13
+
14
+
15
+ theme = gr.themes.Soft(
16
+ primary_hue="blue",
17
+ secondary_hue="lime",
18
+ neutral_hue="slate"
19
+ )
20
+
21
+
22
+ with gr.Blocks(theme=theme) as demo:
23
+ gr.Markdown("## Mango Image Classifier")
24
+ gr.Markdown("Upload an image of a mango to classify it using a fine-tuned model.")
25
+
26
+ with gr.Row():
27
+ image_input = gr.Image(type="pil", label="Upload Mango Image")
28
+ label_output = gr.Label(num_top_classes=3, label="Predictions")
29
+
30
+ classify_btn = gr.Button("Classify Image", variant="primary")
31
+
32
+ classify_btn.click(fn=classify_image, inputs=image_input, outputs=label_output)
33
+
34
+ demo.launch(share=True)