omarelsayeed commited on
Commit
679d3c5
1 Parent(s): 1f112f5

Create app.py

Browse files
Files changed (1) hide show
  1. app.py +44 -0
app.py ADDED
@@ -0,0 +1,44 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ # !pip install ultralytics
2
+ from ultralytics import ASSETS, YOLO, RTDETR
3
+ import gradio as gr
4
+ from huggingface_hub import snapshot_download
5
+ model_dir = snapshot_download("omarelsayeed/DETR-ARABIC-DOCUMENT-LAYOUT-ANALYSIS") + "/Model.pt"
6
+ model = RTDETR(model_dir)
7
+
8
+
9
+ def predict_image(img, conf_threshold, iou_threshold):
10
+ """Predicts objects in an image using a YOLO11 model with adjustable confidence and IOU thresholds."""
11
+ results = model.predict(
12
+ source=img,
13
+ conf=conf_threshold,
14
+ iou=iou_threshold,
15
+ show_labels=True,
16
+ show_conf=True,
17
+ imgsz=640,
18
+ )
19
+
20
+ for r in results:
21
+ im_array = r.plot()
22
+ im = Image.fromarray(im_array[..., ::-1])
23
+
24
+ return im
25
+
26
+
27
+ iface = gr.Interface(
28
+ fn=predict_image,
29
+ inputs=[
30
+ gr.Image(type="pil", label="Upload Image"),
31
+ gr.Slider(minimum=0, maximum=1, value=0.25, label="Confidence threshold"),
32
+ gr.Slider(minimum=0, maximum=1, value=0.45, label="IoU threshold"),
33
+ ],
34
+ outputs=gr.Image(type="pil", label="Result"),
35
+ title="Ultralytics Gradio",
36
+ description="Upload images for inference. The Ultralytics YOLO11n model is used by default.",
37
+ examples=[
38
+ [ASSETS / "bus.jpg", 0.25, 0.45],
39
+ [ASSETS / "zidane.jpg", 0.25, 0.45],
40
+ ],
41
+ )
42
+
43
+ if __name__ == "__main__":
44
+ iface.launch(share = True)