Spaces:
Sleeping
Sleeping
adiciona novo script
Browse files- app1.py +85 -0
- checkYoloxv7.sh +16 -0
- telegramCrise.sh +1 -0
app1.py
ADDED
@@ -0,0 +1,85 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
import gradio as gr
|
2 |
+
import torch
|
3 |
+
import json
|
4 |
+
import yolov7
|
5 |
+
|
6 |
+
|
7 |
+
# Images
|
8 |
+
#torch.hub.download_url_to_file('https://github.com/ultralytics/yolov5/raw/master/data/images/zidane.jpg', 'zidane.jpg')
|
9 |
+
#torch.hub.download_url_to_file('https://raw.githubusercontent.com/obss/sahi/main/tests/data/small-vehicles1.jpeg', 'small-vehicles1.jpeg')
|
10 |
+
|
11 |
+
model_path = "kadirnar/yolov7-tiny-v0.1" #"kadirnar/yolov7-v0.1" #
|
12 |
+
image_size = 640
|
13 |
+
conf_threshold = 0.25
|
14 |
+
iou_threshold = 0.45
|
15 |
+
|
16 |
+
def yolov7_inference(
|
17 |
+
image: gr.inputs.Image = None,
|
18 |
+
#model_path: gr.inputs.Dropdown = None,
|
19 |
+
#image_size: gr.inputs.Slider = 640,
|
20 |
+
#conf_threshold: gr.inputs.Slider = 0.25,
|
21 |
+
#iou_threshold: gr.inputs.Slider = 0.45,
|
22 |
+
):
|
23 |
+
"""
|
24 |
+
YOLOv7 inference function
|
25 |
+
Args:
|
26 |
+
image: Input image
|
27 |
+
model_path: Path to the model
|
28 |
+
image_size: Image size
|
29 |
+
conf_threshold: Confidence threshold
|
30 |
+
iou_threshold: IOU threshold
|
31 |
+
Returns:
|
32 |
+
Rendered image
|
33 |
+
"""
|
34 |
+
|
35 |
+
model = yolov7.load(model_path, device="cpu", hf_model=True, trace=False)
|
36 |
+
model.conf = conf_threshold
|
37 |
+
model.iou = iou_threshold
|
38 |
+
results = model([image], size=image_size)
|
39 |
+
tensor = {
|
40 |
+
"tensorflow": [
|
41 |
+
]
|
42 |
+
}
|
43 |
+
|
44 |
+
if results.pred is not None:
|
45 |
+
for i, element in enumerate(results.pred[0]):
|
46 |
+
object = {}
|
47 |
+
#print (element[0])
|
48 |
+
itemclass = round(element[5].item())
|
49 |
+
object["classe"] = itemclass
|
50 |
+
object["nome"] = results.names[itemclass]
|
51 |
+
object["score"] = element[4].item()
|
52 |
+
object["x"] = element[0].item()
|
53 |
+
object["y"] = element[1].item()
|
54 |
+
object["w"] = element[2].item()
|
55 |
+
object["h"] = element[3].item()
|
56 |
+
tensor["tensorflow"].append(object)
|
57 |
+
|
58 |
+
|
59 |
+
|
60 |
+
text = json.dumps(tensor)
|
61 |
+
#print (text)
|
62 |
+
return text #results.render()[0]
|
63 |
+
|
64 |
+
|
65 |
+
inputs = [
|
66 |
+
gr.inputs.Image(type="pil", label="Input Image"),
|
67 |
+
]
|
68 |
+
|
69 |
+
#outputs = gr.outputs.Image(type="filepath", label="Output Image")
|
70 |
+
title = "Yolov7: Trainable bag-of-freebies sets new state-of-the-art for real-time object detectors"
|
71 |
+
|
72 |
+
examples = [['small-vehicles1.jpeg'], ['zidane.jpg']]
|
73 |
+
demo_app = gr.Interface(
|
74 |
+
fn=yolov7_inference,
|
75 |
+
inputs=inputs,
|
76 |
+
outputs=["text"],
|
77 |
+
title=title,
|
78 |
+
examples=examples,
|
79 |
+
#cache_examples=True,
|
80 |
+
#theme='huggingface',
|
81 |
+
)
|
82 |
+
demo_app.launch(debug=False, server_name="192.168.0.153", server_port=8081, enable_queue=True)
|
83 |
+
#demo_app.launch(debug=True, server_port=8083, enable_queue=True)
|
84 |
+
#demo_app.launch(debug=True, enable_queue=True)
|
85 |
+
|
checkYoloxv7.sh
ADDED
@@ -0,0 +1,16 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
#!/bin/sh
|
2 |
+
export path=/home/atualli/.local/lib/python3.8/site-packages:$PATH
|
3 |
+
cd ~/Projetos/huggingface/yolov7
|
4 |
+
SERVER=192.168.0.153
|
5 |
+
PORT=8081
|
6 |
+
|
7 |
+
if lsof -Pi :$PORT -sTCP:LISTEN -t >/dev/null ; then
|
8 |
+
echo "running"
|
9 |
+
else
|
10 |
+
./telegramCrise.sh "reiniciando_yolox_V7_linux_192.168.0.153:8081"
|
11 |
+
pkill -f app1.py
|
12 |
+
python app1.py &
|
13 |
+
echo "not running"
|
14 |
+
fi
|
15 |
+
|
16 |
+
|
telegramCrise.sh
ADDED
@@ -0,0 +1 @@
|
|
|
|
|
1 |
+
curl -X POST "https://api.telegram.org/bot766543741:AAE0oO_ni_QYkfS8tZxC-VZt0RJztFiZNHc/sendMessage?chat_id=-927074982&text=$1"
|