ahuang11 commited on
Commit
ef9ded4
β€’
1 Parent(s): 8ca62d2

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +34 -32
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
- 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
- return
76
-
77
- class_items = class_names.split(",")
78
- class_likelihoods = get_similarity_scores(class_items, pil_img)
79
-
80
- # build the results column
81
- results = pn.Column("##### πŸŽ‰ Here are the results!", img)
82
-
83
- for class_item, class_likelihood in zip(class_items, class_likelihoods):
84
- row_label = pn.widgets.StaticText(
85
- name=class_item.strip(), value=f"{class_likelihood:.2%}", align="center"
86
- )
87
- row_bar = pn.indicators.Progress(
88
- value=int(class_likelihood * 100),
89
- sizing_mode="stretch_width",
90
- bar_color="secondary",
91
- margin=(0, 10),
92
- design=pn.theme.Material,
93
- )
94
- results.append(pn.Column(row_label, row_bar))
95
- main.disabled = False
96
- yield results
 
 
 
 
 
 
 
 
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