Spaces:
Runtime error
Runtime error
Update app.py
Browse files
app.py
CHANGED
|
@@ -86,7 +86,6 @@ def detect_objects2(model_name,url_input,image_input,threshold,type2):
|
|
| 86 |
model = DetrForObjectDetection.from_pretrained(model_name)
|
| 87 |
|
| 88 |
|
| 89 |
-
global xxresult
|
| 90 |
|
| 91 |
image = image_input
|
| 92 |
|
|
@@ -104,7 +103,7 @@ def detect_objects2(model_name,url_input,image_input,threshold,type2):
|
|
| 104 |
total_text="Trench is Detected \n Image is Not Blurry \n"
|
| 105 |
else:
|
| 106 |
total_text="Trench is NOT Detected \n Image is Blurry \n"
|
| 107 |
-
|
| 108 |
print(type2)
|
| 109 |
print(type(type2))
|
| 110 |
|
|
@@ -113,26 +112,51 @@ def detect_objects2(model_name,url_input,image_input,threshold,type2):
|
|
| 113 |
total_text+="Measuring Tape (Vertical) for measuring Depth is Detected \n"
|
| 114 |
else:
|
| 115 |
total_text+="Measuring Tape (Vertical) for measuring Depth is NOT Detected \n"
|
| 116 |
-
|
| 117 |
-
xxresult=1
|
| 118 |
|
| 119 |
if det_lab.count(5) > 0:
|
| 120 |
total_text+="Measuring Tape (Horizontal) for measuring Width is Detected \n"
|
| 121 |
else:
|
| 122 |
total_text+="Measuring Tape (Horizontal) for measuring Width is NOT Detected \n"
|
| 123 |
-
|
| 124 |
-
xxresult=1
|
| 125 |
|
| 126 |
return total_text
|
| 127 |
|
| 128 |
-
def tott():
|
| 129 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 130 |
if xxresult==0:
|
| 131 |
-
|
| 132 |
else:
|
| 133 |
-
|
| 134 |
-
|
| 135 |
-
return text2
|
| 136 |
|
| 137 |
def set_example_image(example: list) -> dict:
|
| 138 |
return gr.Image.update(value=example[0])
|
|
@@ -190,7 +214,7 @@ with demo:
|
|
| 190 |
output = gr.Textbox(label="Reason for the results")
|
| 191 |
greet_btn = gr.Button("Results")
|
| 192 |
greet_btn.click(fn=detect_objects2, inputs=[options,img_input,img_input,slider_input,options2], outputs=output, queue=True)
|
| 193 |
-
greet_btn.click(fn=tott, inputs=[], outputs=name, queue=True)
|
| 194 |
|
| 195 |
|
| 196 |
|
|
|
|
| 86 |
model = DetrForObjectDetection.from_pretrained(model_name)
|
| 87 |
|
| 88 |
|
|
|
|
| 89 |
|
| 90 |
image = image_input
|
| 91 |
|
|
|
|
| 103 |
total_text="Trench is Detected \n Image is Not Blurry \n"
|
| 104 |
else:
|
| 105 |
total_text="Trench is NOT Detected \n Image is Blurry \n"
|
| 106 |
+
|
| 107 |
print(type2)
|
| 108 |
print(type(type2))
|
| 109 |
|
|
|
|
| 112 |
total_text+="Measuring Tape (Vertical) for measuring Depth is Detected \n"
|
| 113 |
else:
|
| 114 |
total_text+="Measuring Tape (Vertical) for measuring Depth is NOT Detected \n"
|
| 115 |
+
|
|
|
|
| 116 |
|
| 117 |
if det_lab.count(5) > 0:
|
| 118 |
total_text+="Measuring Tape (Horizontal) for measuring Width is Detected \n"
|
| 119 |
else:
|
| 120 |
total_text+="Measuring Tape (Horizontal) for measuring Width is NOT Detected \n"
|
| 121 |
+
|
|
|
|
| 122 |
|
| 123 |
return total_text
|
| 124 |
|
| 125 |
+
def tott(model_name,url_input,image_input,threshold,type2):
|
| 126 |
+
|
| 127 |
+
#Extract model and feature extractor
|
| 128 |
+
feature_extractor = AutoFeatureExtractor.from_pretrained(model_name)
|
| 129 |
+
|
| 130 |
+
|
| 131 |
+
|
| 132 |
+
model = DetrForObjectDetection.from_pretrained(model_name)
|
| 133 |
+
|
| 134 |
+
|
| 135 |
+
|
| 136 |
+
image = image_input
|
| 137 |
+
|
| 138 |
+
#Make prediction
|
| 139 |
+
processed_outputs = make_prediction(image, feature_extractor, model)
|
| 140 |
+
keep = processed_outputs["scores"] > threshold
|
| 141 |
+
det_lab = processed_outputs["labels"][keep].tolist()
|
| 142 |
+
xxresult=0
|
| 143 |
+
if det_lab.count(1) > 0:
|
| 144 |
+
else:
|
| 145 |
+
xxresult=1
|
| 146 |
+
if det_lab.count(4) > 0:
|
| 147 |
+
else:
|
| 148 |
+
if type2=="Trench Depth Measurement":
|
| 149 |
+
xxresult=1
|
| 150 |
+
if det_lab.count(5) > 0:
|
| 151 |
+
else:
|
| 152 |
+
if type2=="Trench Width Measurement":
|
| 153 |
+
xxresult=1
|
| 154 |
+
|
| 155 |
if xxresult==0:
|
| 156 |
+
return "The photo is ACCEPTED"
|
| 157 |
else:
|
| 158 |
+
return "The photo is NOT ACCEPTED"
|
| 159 |
+
|
|
|
|
| 160 |
|
| 161 |
def set_example_image(example: list) -> dict:
|
| 162 |
return gr.Image.update(value=example[0])
|
|
|
|
| 214 |
output = gr.Textbox(label="Reason for the results")
|
| 215 |
greet_btn = gr.Button("Results")
|
| 216 |
greet_btn.click(fn=detect_objects2, inputs=[options,img_input,img_input,slider_input,options2], outputs=output, queue=True)
|
| 217 |
+
greet_btn.click(fn=tott, inputs=[options,img_input,img_input,slider_input,options2], outputs=name, queue=True)
|
| 218 |
|
| 219 |
|
| 220 |
|