alialghawi commited on
Commit
6d2e81e
1 Parent(s): 87c39e4

Upload ex.py

Browse files
Files changed (1) hide show
  1. ex.py +46 -0
ex.py ADDED
@@ -0,0 +1,46 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ from PIL import Image
2
+ from prediction import prediction
3
+ from prediction import pre_image
4
+ from prediction import load_model
5
+ from prediction import predict
6
+ from prediction import annotate
7
+
8
+ import gradio as gr
9
+ import cv2
10
+ import onnxruntime
11
+ import matplotlib.pyplot as plt
12
+ import fire
13
+
14
+ model = load_model(model_path="best_re_final.onnx")
15
+
16
+ # def greet(temperature):
17
+ # # salutation = "Good morning" if is_morning else "Good evening"
18
+ # # greeting = f"{salutation} {name}. It is {temperature} degrees today"
19
+ # celsius = (temperature - 32) * 5 / 9
20
+ # return round(celsius, 2)
21
+
22
+
23
+
24
+
25
+ def predict_gradio(image,Confidence,IOU):
26
+
27
+ conf = Confidence /100
28
+ iou= IOU/100
29
+ input_I= pre_image(image, model[1]) #path and input shape is passed
30
+ predictions = predict(image, model[0], input_I, conf) #image, ort_session, and input tensor is passed
31
+ annotatedImage = annotate(image, predictions[0], predictions[1], predictions[2],iou) #boxes, and scores are passed
32
+ annotatedImage = cv2.cvtColor(annotatedImage, cv2.COLOR_BGR2RGB)
33
+
34
+ return annotatedImage
35
+
36
+
37
+
38
+ demo = gr.Interface( fn=predict_gradio,
39
+ inputs=[
40
+ "image",gr.Slider(0, 100),gr.Slider(0, 100)
41
+ ],
42
+ outputs="image",
43
+ title="Head Detection",
44
+ css=".gradio-container { background-color: grey; }"
45
+ )
46
+ demo.launch()