app.py
Browse files
app.py
CHANGED
|
@@ -3,12 +3,10 @@ import gradio as gr
|
|
| 3 |
from transformers import AutoModelForImageClassification, AutoImageProcessor
|
| 4 |
from PIL import Image
|
| 5 |
import torch
|
| 6 |
-
from collections import Counter
|
| 7 |
|
| 8 |
MODEL_LIST = [
|
| 9 |
"prithivMLmods/Trash-Net",
|
| 10 |
-
"yangy50/garbage-classification"
|
| 11 |
-
"eunoiawiira/vgg-realwaste-classification"
|
| 12 |
]
|
| 13 |
|
| 14 |
models = []
|
|
@@ -46,26 +44,24 @@ def classify_image(image: Image.Image):
|
|
| 46 |
except Exception as e:
|
| 47 |
results[model_name] = f"error:{e}"
|
| 48 |
|
| 49 |
-
#
|
| 50 |
results_text = "\n".join([f"{name}: {label}" for name, label in results.items()])
|
| 51 |
|
| 52 |
-
#
|
| 53 |
-
|
| 54 |
-
|
| 55 |
-
results_text += f"\n\nFinal Label (voting): {final_label}"
|
| 56 |
return results_text
|
| 57 |
|
| 58 |
iface = gr.Interface(
|
| 59 |
fn=classify_image,
|
| 60 |
inputs=gr.Image(type="pil", label="Upload Image"),
|
| 61 |
outputs=[gr.Textbox(label="Model Predictions")],
|
| 62 |
-
title="
|
| 63 |
description=(
|
| 64 |
"Upload an image, and the following models will classify it:\n"
|
| 65 |
"1. prithivMLmods/Trash-Net\n"
|
| 66 |
"2. yangy50/garbage-classification\n"
|
| 67 |
-
"
|
| 68 |
-
"The final label is determined by majority vote."
|
| 69 |
)
|
| 70 |
)
|
| 71 |
|
|
|
|
| 3 |
from transformers import AutoModelForImageClassification, AutoImageProcessor
|
| 4 |
from PIL import Image
|
| 5 |
import torch
|
|
|
|
| 6 |
|
| 7 |
MODEL_LIST = [
|
| 8 |
"prithivMLmods/Trash-Net",
|
| 9 |
+
"yangy50/garbage-classification"
|
|
|
|
| 10 |
]
|
| 11 |
|
| 12 |
models = []
|
|
|
|
| 44 |
except Exception as e:
|
| 45 |
results[model_name] = f"error:{e}"
|
| 46 |
|
| 47 |
+
# 输出每个模型的结果
|
| 48 |
results_text = "\n".join([f"{name}: {label}" for name, label in results.items()])
|
| 49 |
|
| 50 |
+
# 以 yangy50/garbage-classification 为最终结果
|
| 51 |
+
final_label = results.get("yangy50/garbage-classification", "Unknown")
|
| 52 |
+
results_text += f"\n\nFinal Label (base yangy50): {final_label}"
|
|
|
|
| 53 |
return results_text
|
| 54 |
|
| 55 |
iface = gr.Interface(
|
| 56 |
fn=classify_image,
|
| 57 |
inputs=gr.Image(type="pil", label="Upload Image"),
|
| 58 |
outputs=[gr.Textbox(label="Model Predictions")],
|
| 59 |
+
title="Trash Classification",
|
| 60 |
description=(
|
| 61 |
"Upload an image, and the following models will classify it:\n"
|
| 62 |
"1. prithivMLmods/Trash-Net\n"
|
| 63 |
"2. yangy50/garbage-classification\n"
|
| 64 |
+
"The final label is based on yangy50/garbage-classification."
|
|
|
|
| 65 |
)
|
| 66 |
)
|
| 67 |
|