File size: 1,409 Bytes
fafcaff
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
import gradio as gr
import cv2
import numpy as np
import matplotlib.pyplot as plt
from sklearn.cluster import MeanShift
import io
from PIL import Image


def segment_image(image):
    
    img = np.array(image)
    
    twoDim = img.reshape((-1, 3))
    
    twoDim = np.float32(twoDim)
    
    mean_shift = MeanShift(bandwidth=30, bin_seeding=True)  
    mean_shift.fit(twoDim)
    
    labels = mean_shift.labels_
  
    segmented_image = mean_shift.cluster_centers_[labels].astype(np.uint8)
    
    segmented_image = segmented_image.reshape(img.shape)
    
    segmented_image_pil = Image.fromarray(segmented_image)
    return segmented_image_pil

def analyze_health(image):
    
    return "Plante en bonne santé, pas de signes de stress ou de maladie."

# Interface Gradio
def plant_diagnosis(image):
    
    segmented = segment_image(image)
    
    diagnosis = analyze_health(segmented)
    
    return segmented, diagnosis

# Créer l'interface Gradio
iface = gr.Interface(
    fn=plant_diagnosis, 
    inputs=gr.Image(type="pil", label="Téléchargez une image de votre plante"),  
    outputs=[gr.Image(label="Image Segmentée"), gr.Textbox(label="Diagnostic")],  
    title="AppleHealth",
    description="Téléchargez une image de votre plante pour effectuer une analyse de segmentation et obtenir un diagnostic de sa santé.",
    live=True  
)

# Lancer l'application Gradio
iface.launch()