Spaces:
Running
Running
Update app.py
Browse files
app.py
CHANGED
|
@@ -61,39 +61,41 @@ async def process_inputs(class_names: List[str], image_url: str):
|
|
| 61 |
High level function that takes in the user inputs and returns the
|
| 62 |
classification results as panel objects.
|
| 63 |
"""
|
| 64 |
-
main.disabled = True
|
| 65 |
-
if not image_url:
|
| 66 |
-
yield "##### β οΈ Provide an image URL"
|
| 67 |
-
return
|
| 68 |
-
|
| 69 |
-
yield "##### β Fetching image and running model..."
|
| 70 |
try:
|
| 71 |
-
|
| 72 |
-
|
| 73 |
-
|
| 74 |
-
|
| 75 |
-
|
| 76 |
-
|
| 77 |
-
|
| 78 |
-
|
| 79 |
-
|
| 80 |
-
|
| 81 |
-
|
| 82 |
-
|
| 83 |
-
|
| 84 |
-
|
| 85 |
-
|
| 86 |
-
|
| 87 |
-
|
| 88 |
-
|
| 89 |
-
|
| 90 |
-
|
| 91 |
-
|
| 92 |
-
|
| 93 |
-
|
| 94 |
-
|
| 95 |
-
|
| 96 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 97 |
|
| 98 |
|
| 99 |
# create widgets
|
|
|
|
| 61 |
High level function that takes in the user inputs and returns the
|
| 62 |
classification results as panel objects.
|
| 63 |
"""
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 64 |
try:
|
| 65 |
+
if not image_url:
|
| 66 |
+
yield "##### β οΈ Provide an image URL"
|
| 67 |
+
return
|
| 68 |
+
|
| 69 |
+
yield "##### β Fetching image and running model..."
|
| 70 |
+
try:
|
| 71 |
+
pil_img = await open_image_url(image_url)
|
| 72 |
+
img = pn.pane.Image(pil_img, height=400, align="center")
|
| 73 |
+
except Exception as e:
|
| 74 |
+
yield f"##### π Something went wrong, please try a different URL!"
|
| 75 |
+
main.disabled = False
|
| 76 |
+
return
|
| 77 |
+
|
| 78 |
+
class_items = class_names.split(",")
|
| 79 |
+
class_likelihoods = get_similarity_scores(class_items, pil_img)
|
| 80 |
+
|
| 81 |
+
# build the results column
|
| 82 |
+
results = pn.Column("##### π Here are the results!", img)
|
| 83 |
+
|
| 84 |
+
for class_item, class_likelihood in zip(class_items, class_likelihoods):
|
| 85 |
+
row_label = pn.widgets.StaticText(
|
| 86 |
+
name=class_item.strip(), value=f"{class_likelihood:.2%}", align="center"
|
| 87 |
+
)
|
| 88 |
+
row_bar = pn.indicators.Progress(
|
| 89 |
+
value=int(class_likelihood * 100),
|
| 90 |
+
sizing_mode="stretch_width",
|
| 91 |
+
bar_color="secondary",
|
| 92 |
+
margin=(0, 10),
|
| 93 |
+
design=pn.theme.Material,
|
| 94 |
+
)
|
| 95 |
+
results.append(pn.Column(row_label, row_bar))
|
| 96 |
+
yield results
|
| 97 |
+
finally:
|
| 98 |
+
main.disabled = False
|
| 99 |
|
| 100 |
|
| 101 |
# create widgets
|