Pashtetuum commited on
Commit
47ed2bd
·
verified ·
1 Parent(s): aa9d0f7

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +18 -12
app.py CHANGED
@@ -20,17 +20,23 @@ def translator(Defect):
20
  "Scratches": "Царапины"
21
  }
22
  return translation_dict.get(Defect)
23
- def predict(loaded_img):
24
- # Изменение размера изображения
25
- img = cv2.resize(loaded_img, (200, 200))
26
- # Добавление измерения пакета
27
- img_array = np.expand_dims(img, axis=0)
28
- # Предсказание класса
29
- prediction = loaded_model.predict(img_array)
30
- predicted_class = np.argmax(prediction)
31
- decoded_class = label_encoder.inverse_transform([predicted_class])[0]
32
- prediction=translator(decoded_class)
33
- return prediction
 
 
 
 
 
 
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)