rinogeek commited on
Commit
5f0462b
·
verified ·
1 Parent(s): 38fb74c

Create app.py

Browse files
Files changed (1) hide show
  1. app.py +59 -0
app.py ADDED
@@ -0,0 +1,59 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import gradio as gr
2
+ from ultralytics import YOLO
3
+ from huggingface_hub import hf_hub_download
4
+ import tempfile
5
+
6
+ # Charger le modèle depuis ton repo Hugging Face
7
+ # Remplace par ton repo_id
8
+ REPO_ID = "rinogeek/FoodDetection"
9
+ MODEL_FILE = "best.pt"
10
+
11
+ model_path = hf_hub_download(repo_id=REPO_ID, filename=MODEL_FILE)
12
+ model = YOLO(model_path)
13
+
14
+
15
+ # --- Fonctions de détection ---
16
+ def detect_image(image):
17
+ results = model(image)
18
+ save_path = tempfile.NamedTemporaryFile(suffix=".jpg", delete=False).name
19
+ results[0].plot(save_path)
20
+ return save_path
21
+
22
+
23
+ def detect_video(video):
24
+ results = model(video, save=True, project=tempfile.gettempdir(), name="yolov8_gradio")
25
+ return results[0].path
26
+
27
+
28
+ # --- Interface ---
29
+ with gr.Blocks() as demo:
30
+ gr.Markdown("""
31
+ # FoodDetection - Détection en temps réel
32
+ Bienvenue sur **FoodDetection**, une IA développé par **BlackBenAI**.
33
+ Ce modèle de computer vision identifie en direct le nom de votre nourriture
34
+ """)
35
+
36
+ with gr.Tab("Image"):
37
+ with gr.Row():
38
+ inp_img = gr.Image(type="pil")
39
+ out_img = gr.Image(type="filepath")
40
+ btn_img = gr.Button("Détecter")
41
+ btn_img.click(fn=detect_image, inputs=inp_img, outputs=out_img)
42
+
43
+ with gr.Tab("Vidéo"):
44
+ with gr.Row():
45
+ inp_vid = gr.Video()
46
+ out_vid = gr.Video()
47
+ btn_vid = gr.Button("Analyser Vidéo")
48
+ btn_vid.click(fn=detect_video, inputs=inp_vid, outputs=out_vid)
49
+
50
+ with gr.Tab("Caméra"):
51
+ with gr.Row():
52
+ inp_cam = gr.Image(type="pil", sources=["webcam"])
53
+ out_cam = gr.Image(type="filepath")
54
+ btn_cam = gr.Button("Détecter (Caméra)")
55
+ btn_cam.click(fn=detect_image, inputs=inp_cam, outputs=out_cam)
56
+
57
+
58
+ if __name__ == "__main__":
59
+ demo.launch()