Spaces:
Sleeping
Sleeping
Pashtetuum
commited on
Commit
•
544f6e3
1
Parent(s):
22ea818
Update app.py
Browse files
app.py
CHANGED
@@ -24,7 +24,7 @@ def translator(Defect):
|
|
24 |
}
|
25 |
return translation_dict.get(Defect)
|
26 |
def predict(zip_bytes):
|
27 |
-
|
28 |
with zipfile.ZipFile(zip_bytes, 'r') as zip_ref:
|
29 |
for filename in zip_ref.namelist():
|
30 |
if filename.lower().endswith(('.png', '.jpg', '.jpeg','.bmp')):
|
@@ -38,17 +38,15 @@ def predict(zip_bytes):
|
|
38 |
predicted_class = np.argmax(prediction)
|
39 |
decoded_class = label_encoder.inverse_transform([predicted_class])[0]
|
40 |
predicted_class_translation = translator(decoded_class)
|
41 |
-
|
42 |
-
|
43 |
-
|
|
|
44 |
interface = gr.Interface(
|
45 |
fn=predict,
|
46 |
inputs=gr.File(label="Выберите zip-файл (только с изображениями)"),
|
47 |
-
outputs=gr.
|
48 |
-
columns=["Файл", "Класс"],
|
49 |
-
label="Предсказания"
|
50 |
-
),
|
51 |
title="Нейронная сеть для классификации брака на металлопрокате"
|
52 |
)
|
53 |
|
54 |
-
interface.launch(share=True)
|
|
|
24 |
}
|
25 |
return translation_dict.get(Defect)
|
26 |
def predict(zip_bytes):
|
27 |
+
predictions_html = "<table><tr><th>Файл</th><th>Класс</th><th>Точность предсказания</th></tr>"
|
28 |
with zipfile.ZipFile(zip_bytes, 'r') as zip_ref:
|
29 |
for filename in zip_ref.namelist():
|
30 |
if filename.lower().endswith(('.png', '.jpg', '.jpeg','.bmp')):
|
|
|
38 |
predicted_class = np.argmax(prediction)
|
39 |
decoded_class = label_encoder.inverse_transform([predicted_class])[0]
|
40 |
predicted_class_translation = translator(decoded_class)
|
41 |
+
accuracy = round(((np.max(prediction).item())*100),2)
|
42 |
+
predictions_html += f"<tr><th>{filename}</th><th>{predicted_class_translation}</th><th>{accuracy}%</th></tr>"
|
43 |
+
predictions_html += "</table>"
|
44 |
+
return predictions_html
|
45 |
interface = gr.Interface(
|
46 |
fn=predict,
|
47 |
inputs=gr.File(label="Выберите zip-файл (только с изображениями)"),
|
48 |
+
outputs=gr.HTML(label="Предсказанные классы в таблице"),
|
|
|
|
|
|
|
49 |
title="Нейронная сеть для классификации брака на металлопрокате"
|
50 |
)
|
51 |
|
52 |
+
interface.launch(share=True)
|