Spaces:
Build error
Build error
Update app.py
Browse files
app.py
CHANGED
|
@@ -20,17 +20,23 @@ def translator(Defect):
|
|
| 20 |
"Scratches": "Царапины"
|
| 21 |
}
|
| 22 |
return translation_dict.get(Defect)
|
| 23 |
-
def predict(
|
| 24 |
-
|
| 25 |
-
|
| 26 |
-
|
| 27 |
-
|
| 28 |
-
|
| 29 |
-
|
| 30 |
-
|
| 31 |
-
|
| 32 |
-
|
| 33 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 34 |
|
| 35 |
interface = gr.Interface(
|
| 36 |
fn=predict,
|
|
@@ -39,4 +45,4 @@ interface = gr.Interface(
|
|
| 39 |
title="Нейронная сеть для классификации брака на металлопрокате"
|
| 40 |
)
|
| 41 |
|
| 42 |
-
interface.launch(share=True)
|
|
|
|
| 20 |
"Scratches": "Царапины"
|
| 21 |
}
|
| 22 |
return translation_dict.get(Defect)
|
| 23 |
+
def predict(zip_bytes):
|
| 24 |
+
predictions = []
|
| 25 |
+
with zipfile.ZipFile(io.BytesIO(zip_bytes), 'r') as zip_ref:
|
| 26 |
+
for filename in zip_ref.namelist():
|
| 27 |
+
if filename.lower().endswith(('.png', '.jpg', '.jpeg', '.bmp')):
|
| 28 |
+
with zip_ref.open(filename) as file:
|
| 29 |
+
img_bytes = file.read()
|
| 30 |
+
img_np = np.frombuffer(img_bytes, np.uint8)
|
| 31 |
+
img = cv2.imdecode(img_np, cv2.IMREAD_COLOR)
|
| 32 |
+
img_resized = cv2.resize(img, (200, 200))
|
| 33 |
+
img_array = np.expand_dims(img_resized, axis=0)
|
| 34 |
+
prediction = loaded_model.predict(img_array)
|
| 35 |
+
predicted_class = np.argmax(prediction)
|
| 36 |
+
decoded_class = label_encoder.inverse_transform([predicted_class])[0]
|
| 37 |
+
predicted_class_translation = translator(decoded_class)
|
| 38 |
+
predictions.append((filename, predicted_class_translation))
|
| 39 |
+
return predictions
|
| 40 |
|
| 41 |
interface = gr.Interface(
|
| 42 |
fn=predict,
|
|
|
|
| 45 |
title="Нейронная сеть для классификации брака на металлопрокате"
|
| 46 |
)
|
| 47 |
|
| 48 |
+
interface.launch(share=True)
|