Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
|
@@ -279,6 +279,50 @@ def display_dishes_in_grid(dishes, cols=3):
|
|
| 279 |
for col, dish in zip(cols_list, cols_data):
|
| 280 |
with col:
|
| 281 |
st.sidebar.write(dish.replace("_", " ").capitalize())
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 282 |
# #Streamlit
|
| 283 |
|
| 284 |
#Left sidebar title
|
|
@@ -425,48 +469,8 @@ if recipe_submit and uploaded_image:
|
|
| 425 |
confidences.append(confidence)
|
| 426 |
|
| 427 |
print(fpredictions)
|
| 428 |
-
|
| 429 |
-
#reversing them so graph displays highest predictions at the top
|
| 430 |
-
confidences.reverse()
|
| 431 |
-
class_names.reverse()
|
| 432 |
-
|
| 433 |
-
#display as a graph
|
| 434 |
-
norm = plt.Normalize(min(confidences), max(confidences))
|
| 435 |
-
cmap = LinearSegmentedColormap.from_list("grey_orange", ["#808080", "#FFA500"]) #color map grey to orange
|
| 436 |
-
|
| 437 |
-
fig, ax = plt.subplots(figsize=(12, 6))
|
| 438 |
-
bars = ax.barh(class_names, confidences, color=cmap(norm(confidences)))
|
| 439 |
-
|
| 440 |
-
fig.patch.set_alpha(0) # Transparent background
|
| 441 |
-
ax.set_facecolor('none')
|
| 442 |
-
|
| 443 |
-
min_width = 0.07 * ax.get_xlim()[1] # 7% of the x-axis range
|
| 444 |
-
# Add labels inside the bars, aligned to the right
|
| 445 |
-
for bar in bars:
|
| 446 |
-
original_width = bar.get_width()
|
| 447 |
-
width = original_width
|
| 448 |
-
if width < min_width:
|
| 449 |
-
width = min_width
|
| 450 |
-
ax.text(width - 0.02, bar.get_y() + bar.get_height()/2, f'{original_width:.1f}%',
|
| 451 |
-
va='center', ha='right', color='white', fontweight='bold', fontsize=16)
|
| 452 |
-
|
| 453 |
-
ax.set_xticklabels([]) #remove x label
|
| 454 |
-
|
| 455 |
-
|
| 456 |
-
|
| 457 |
-
# Wrapping labels
|
| 458 |
-
max_label_width = 10
|
| 459 |
-
labels = ax.get_yticklabels()
|
| 460 |
-
wrapped_labels = [textwrap.fill(label.get_text(), width=max_label_width) for label in labels] # Wrap the labels if they exceed the max width
|
| 461 |
-
ax.set_yticklabels(wrapped_labels, fontsize=16, color='white')
|
| 462 |
-
|
| 463 |
-
#no borders
|
| 464 |
-
for spine in ax.spines.values():
|
| 465 |
-
spine.set_visible(False)
|
| 466 |
-
|
| 467 |
-
ax.set_title(class_names[-1], color='white', fontsize=24, fontweight='bold', ha='left')
|
| 468 |
|
| 469 |
-
st.pyplot(fig) # Display the plot
|
| 470 |
|
| 471 |
# call openai to pick the best classification result based on query
|
| 472 |
openAICall = [
|
|
|
|
| 279 |
for col, dish in zip(cols_list, cols_data):
|
| 280 |
with col:
|
| 281 |
st.sidebar.write(dish.replace("_", " ").capitalize())
|
| 282 |
+
|
| 283 |
+
def display_prediction_graph(class_names, confidences):
|
| 284 |
+
print("CLASS NAMES: ", class_names)
|
| 285 |
+
print("CONFIDENCES", confidences)
|
| 286 |
+
#reversing them so graph displays highest predictions at the top
|
| 287 |
+
confidences.reverse()
|
| 288 |
+
class_names.reverse()
|
| 289 |
+
|
| 290 |
+
#display as a graph
|
| 291 |
+
norm = plt.Normalize(min(confidences), max(confidences))
|
| 292 |
+
cmap = LinearSegmentedColormap.from_list("grey_orange", ["#808080", "#FFA500"]) #color map grey to orange
|
| 293 |
+
|
| 294 |
+
fig, ax = plt.subplots(figsize=(12, 6))
|
| 295 |
+
bars = ax.barh(class_names, confidences, color=cmap(norm(confidences)))
|
| 296 |
+
|
| 297 |
+
fig.patch.set_alpha(0) # Transparent background
|
| 298 |
+
ax.set_facecolor('none')
|
| 299 |
+
|
| 300 |
+
min_width = 0.07 * ax.get_xlim()[1] # 7% of the x-axis range
|
| 301 |
+
# Add labels inside the bars, aligned to the right
|
| 302 |
+
for bar in bars:
|
| 303 |
+
original_width = bar.get_width()
|
| 304 |
+
width = original_width
|
| 305 |
+
if width < min_width:
|
| 306 |
+
width = min_width
|
| 307 |
+
ax.text(width - 0.02, bar.get_y() + bar.get_height()/2, f'{original_width:.1f}%',
|
| 308 |
+
va='center', ha='right', color='white', fontweight='bold', fontsize=16)
|
| 309 |
+
|
| 310 |
+
ax.set_xticklabels([]) #remove x label
|
| 311 |
+
|
| 312 |
+
# Wrapping labels
|
| 313 |
+
max_label_width = 10
|
| 314 |
+
labels = ax.get_yticklabels()
|
| 315 |
+
wrapped_labels = [textwrap.fill(label.get_text(), width=max_label_width) for label in labels] # Wrap the labels if they exceed the max width
|
| 316 |
+
ax.set_yticklabels(wrapped_labels, fontsize=16, color='white')
|
| 317 |
+
|
| 318 |
+
#no borders
|
| 319 |
+
for spine in ax.spines.values():
|
| 320 |
+
spine.set_visible(False)
|
| 321 |
+
|
| 322 |
+
ax.set_title(class_names[-1], color='white', fontsize=24, fontweight='bold', ha='left')
|
| 323 |
+
|
| 324 |
+
st.pyplot(fig) # Display the plot
|
| 325 |
+
|
| 326 |
# #Streamlit
|
| 327 |
|
| 328 |
#Left sidebar title
|
|
|
|
| 469 |
confidences.append(confidence)
|
| 470 |
|
| 471 |
print(fpredictions)
|
| 472 |
+
display_prediction_graph(class_names, confidences)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 473 |
|
|
|
|
| 474 |
|
| 475 |
# call openai to pick the best classification result based on query
|
| 476 |
openAICall = [
|