Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
|
@@ -68,16 +68,18 @@ def do_predict(pil_img: PIL.Image.Image):
|
|
| 68 |
df = pandas.DataFrame({"image": [str(img_path)]}) # For AutoGluon expected input format
|
| 69 |
|
| 70 |
try:
|
| 71 |
-
|
|
|
|
|
|
|
| 72 |
# For user-friendly column names
|
| 73 |
proba_df = proba_df.rename(columns={0: "♻️ Recycling (0)", 1: "🗑️ Trash (1)"})
|
| 74 |
row = proba_df.iloc[0]
|
|
|
|
| 75 |
# For pretty ranked dict expected by gr.Label
|
| 76 |
pretty_dict = {
|
| 77 |
"♻️ Recycling": float(row.get("♻️ Recycling (0)", 0.0)),
|
| 78 |
"🗑️ Trash": float(row.get("🗑️ Trash (1)", 0.0)),
|
| 79 |
}
|
| 80 |
-
pretty_dict = dict(sorted(pretty_dict.items(), key=lambda kv: kv[1], reverse=True))
|
| 81 |
except Exception:
|
| 82 |
pretty_dict = {}
|
| 83 |
|
|
@@ -87,11 +89,20 @@ def do_predict(pil_img: PIL.Image.Image):
|
|
| 87 |
EXAMPLES = [
|
| 88 |
["https://c8.alamy.com/comp/2AEA4K9/a-garbage-and-recycling-can-on-the-campus-of-carnegie-mellon-university-pittsburgh-pennsylvania-usa-2AEA4K9.jpg"],
|
| 89 |
["https://encrypted-tbn0.gstatic.com/images?q=tbn:ANd9GcSvid9M7DynMcoUsX0KBMxooLvrKQJwREiw6g&s"],
|
|
|
|
| 90 |
]
|
| 91 |
|
| 92 |
# Gradio UI
|
| 93 |
with gradio.Blocks() as demo:
|
| 94 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 95 |
# Interface for the incoming image
|
| 96 |
image_in = gradio.Image(type="pil", label="Input image", sources=["upload", "webcam"])
|
| 97 |
|
|
|
|
| 68 |
df = pandas.DataFrame({"image": [str(img_path)]}) # For AutoGluon expected input format
|
| 69 |
|
| 70 |
try:
|
| 71 |
+
# For class probabilities
|
| 72 |
+
proba_df = PREDICTOR.predict_proba(df)
|
| 73 |
+
|
| 74 |
# For user-friendly column names
|
| 75 |
proba_df = proba_df.rename(columns={0: "♻️ Recycling (0)", 1: "🗑️ Trash (1)"})
|
| 76 |
row = proba_df.iloc[0]
|
| 77 |
+
|
| 78 |
# For pretty ranked dict expected by gr.Label
|
| 79 |
pretty_dict = {
|
| 80 |
"♻️ Recycling": float(row.get("♻️ Recycling (0)", 0.0)),
|
| 81 |
"🗑️ Trash": float(row.get("🗑️ Trash (1)", 0.0)),
|
| 82 |
}
|
|
|
|
| 83 |
except Exception:
|
| 84 |
pretty_dict = {}
|
| 85 |
|
|
|
|
| 89 |
EXAMPLES = [
|
| 90 |
["https://c8.alamy.com/comp/2AEA4K9/a-garbage-and-recycling-can-on-the-campus-of-carnegie-mellon-university-pittsburgh-pennsylvania-usa-2AEA4K9.jpg"],
|
| 91 |
["https://encrypted-tbn0.gstatic.com/images?q=tbn:ANd9GcSvid9M7DynMcoUsX0KBMxooLvrKQJwREiw6g&s"],
|
| 92 |
+
["https://cmccomb.com/assets/images/headshot_optimized_square.jpg"]
|
| 93 |
]
|
| 94 |
|
| 95 |
# Gradio UI
|
| 96 |
with gradio.Blocks() as demo:
|
| 97 |
|
| 98 |
+
# Provide an introduction
|
| 99 |
+
gradio.Markdown("# Trash or Recycling?")
|
| 100 |
+
gradio.Markdown("""
|
| 101 |
+
This is a simple app that demonstrates how to use an autogluon multimodal
|
| 102 |
+
predictor in a gradio space to predict the contents of a picture. To use,
|
| 103 |
+
just upload a photo. The result should be generated automatically.
|
| 104 |
+
""")
|
| 105 |
+
|
| 106 |
# Interface for the incoming image
|
| 107 |
image_in = gradio.Image(type="pil", label="Input image", sources=["upload", "webcam"])
|
| 108 |
|