| |
| |
| |
| import huggingface_hub |
| if not hasattr(huggingface_hub, 'HfFolder'): |
| class HfFolder: |
| _token = None |
| @staticmethod |
| def get_token(): |
| return HfFolder._token |
| @staticmethod |
| def save_token(token): |
| HfFolder._token = token |
| huggingface_hub.HfFolder = HfFolder |
|
|
| |
| |
| |
| |
| import gradio_client.utils |
|
|
| original_get_type = gradio_client.utils.get_type |
|
|
| def patched_get_type(schema): |
| if isinstance(schema, bool): |
| return "boolean" |
| return original_get_type(schema) |
|
|
| gradio_client.utils.get_type = patched_get_type |
|
|
| |
| |
| |
| import gradio as gr |
| import numpy as np |
| from PIL import Image |
| from ultralytics import YOLO |
|
|
| |
| |
| |
| MODEL_PATH = "best.pt" |
| model = YOLO(MODEL_PATH) |
|
|
| |
| |
| |
| def predict(image): |
| """ |
| Prend une image PIL, retourne un dictionnaire {classe: probabilité} |
| """ |
| |
| image = image.resize((224, 224)) |
| |
| img_np = np.array(image) |
| |
| results = model.predict(img_np, verbose=False) |
| probs = results[0].probs |
| |
| prob_weed = float(probs.data[1].cpu().numpy()) |
| prob_crop = float(probs.data[0].cpu().numpy()) |
| return {"crop": prob_crop, "weed": prob_weed} |
|
|
| |
| |
| |
| iface = gr.Interface( |
| fn=predict, |
| inputs=gr.Image(type="pil", label="Chargez une image de champ"), |
| outputs=gr.Label(num_top_classes=2, label="Prédiction"), |
| title="🌾 Classification Culture / Mauvaise Herbe (YOLOv8)", |
| description="Modèle YOLOv8-cls entraîné sur le dataset DeepWeeds pour distinguer les cultures des mauvaises herbes." |
| ) |
|
|
| if __name__ == "__main__": |
| iface.launch(share=True) |