GiGi2k5 commited on
Commit
fafcaff
·
1 Parent(s): f806792

Add application file

Browse files
Files changed (1) hide show
  1. app.py +54 -0
app.py ADDED
@@ -0,0 +1,54 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import gradio as gr
2
+ import cv2
3
+ import numpy as np
4
+ import matplotlib.pyplot as plt
5
+ from sklearn.cluster import MeanShift
6
+ import io
7
+ from PIL import Image
8
+
9
+
10
+ def segment_image(image):
11
+
12
+ img = np.array(image)
13
+
14
+ twoDim = img.reshape((-1, 3))
15
+
16
+ twoDim = np.float32(twoDim)
17
+
18
+ mean_shift = MeanShift(bandwidth=30, bin_seeding=True)
19
+ mean_shift.fit(twoDim)
20
+
21
+ labels = mean_shift.labels_
22
+
23
+ segmented_image = mean_shift.cluster_centers_[labels].astype(np.uint8)
24
+
25
+ segmented_image = segmented_image.reshape(img.shape)
26
+
27
+ segmented_image_pil = Image.fromarray(segmented_image)
28
+ return segmented_image_pil
29
+
30
+ def analyze_health(image):
31
+
32
+ return "Plante en bonne santé, pas de signes de stress ou de maladie."
33
+
34
+ # Interface Gradio
35
+ def plant_diagnosis(image):
36
+
37
+ segmented = segment_image(image)
38
+
39
+ diagnosis = analyze_health(segmented)
40
+
41
+ return segmented, diagnosis
42
+
43
+ # Créer l'interface Gradio
44
+ iface = gr.Interface(
45
+ fn=plant_diagnosis,
46
+ inputs=gr.Image(type="pil", label="Téléchargez une image de votre plante"),
47
+ outputs=[gr.Image(label="Image Segmentée"), gr.Textbox(label="Diagnostic")],
48
+ title="AppleHealth",
49
+ description="Téléchargez une image de votre plante pour effectuer une analyse de segmentation et obtenir un diagnostic de sa santé.",
50
+ live=True
51
+ )
52
+
53
+ # Lancer l'application Gradio
54
+ iface.launch()