Spaces:
Sleeping
Sleeping
Add Gradio app
Browse files
app.py
CHANGED
@@ -77,9 +77,10 @@ class_to_tonne = {
|
|
77 |
"Mülltüten_aus_Kunststoff": "Restmüll"
|
78 |
}
|
79 |
|
80 |
-
# Gradio
|
81 |
with gr.Blocks(title="Abfallerkennung mit KI 🗑️") as demo:
|
82 |
gr.Markdown("### Lade ein Bild hoch und erfahre, in welche Tonne der Abfall gehört.")
|
|
|
83 |
image_input = gr.Image(type="pil", label="Bild hochladen")
|
84 |
output_label = gr.Textbox(label="Vorhersage")
|
85 |
output_tonne = gr.Textbox(label="Richtiger Abfallbehälter")
|
@@ -88,17 +89,15 @@ with gr.Blocks(title="Abfallerkennung mit KI 🗑️") as demo:
|
|
88 |
def analyze(image):
|
89 |
if image.mode != "RGB":
|
90 |
image = image.convert("RGB")
|
91 |
-
input_tensor = transform(image).unsqueeze(0).to(
|
92 |
with torch.no_grad():
|
93 |
outputs = model(input_tensor)
|
94 |
_, predicted = torch.max(outputs, 1)
|
95 |
label = class_labels[predicted.item()]
|
96 |
tonne = class_to_tonne.get(label, "Unbekannt")
|
97 |
-
|
98 |
-
return label_1, tonne
|
99 |
|
100 |
button.click(fn=analyze, inputs=image_input, outputs=[output_label, output_tonne])
|
101 |
|
102 |
demo.launch(share=True)
|
103 |
-
|
104 |
|
|
|
77 |
"Mülltüten_aus_Kunststoff": "Restmüll"
|
78 |
}
|
79 |
|
80 |
+
# Gradio Blocks UI
|
81 |
with gr.Blocks(title="Abfallerkennung mit KI 🗑️") as demo:
|
82 |
gr.Markdown("### Lade ein Bild hoch und erfahre, in welche Tonne der Abfall gehört.")
|
83 |
+
|
84 |
image_input = gr.Image(type="pil", label="Bild hochladen")
|
85 |
output_label = gr.Textbox(label="Vorhersage")
|
86 |
output_tonne = gr.Textbox(label="Richtiger Abfallbehälter")
|
|
|
89 |
def analyze(image):
|
90 |
if image.mode != "RGB":
|
91 |
image = image.convert("RGB")
|
92 |
+
input_tensor = transform(image).unsqueeze(0).to(device)
|
93 |
with torch.no_grad():
|
94 |
outputs = model(input_tensor)
|
95 |
_, predicted = torch.max(outputs, 1)
|
96 |
label = class_labels[predicted.item()]
|
97 |
tonne = class_to_tonne.get(label, "Unbekannt")
|
98 |
+
return label.replace("_", " ").capitalize(), tonne
|
|
|
99 |
|
100 |
button.click(fn=analyze, inputs=image_input, outputs=[output_label, output_tonne])
|
101 |
|
102 |
demo.launch(share=True)
|
|
|
103 |
|