tonyliu404 commited on
Commit
f70ff88
·
verified ·
1 Parent(s): a18c061

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +10 -9
app.py CHANGED
@@ -15,6 +15,7 @@ from langchain_core.messages import HumanMessage, SystemMessage
15
  from PIL import Image
16
  import json
17
  import matplotlib.pyplot as plt
 
18
 
19
  st.set_page_config(
20
  page_title="Food Chain",
@@ -419,9 +420,13 @@ if recipe_submit and uploaded_image:
419
  confidences.append(confidence)
420
  print(fpredictions)
421
 
 
 
 
 
422
  #display as a graph
423
  norm = plt.Normalize(min(confidences), max(confidences))
424
- cmap = plt.get_cmap('Oranges')
425
 
426
  fig, ax = plt.subplots(figsize=(8, 6))
427
  bars = ax.barh(class_names, confidences, color=cmap(norm(confidences)))
@@ -429,17 +434,13 @@ if recipe_submit and uploaded_image:
429
  # Add labels inside the bars, aligned to the right
430
  for bar in bars:
431
  width = bar.get_width()
432
- ax.text(width - 0.02, bar.get_y() + bar.get_height()/2, f'{width*100:.2f}%',
433
  va='center', ha='right', color='white', fontweight='bold')
434
 
435
-
436
- ax.set_xlabel('Confidence (%)')
437
- ax.set_title('Top Predictions')
438
-
439
- plt.colorbar(plt.cm.ScalarMappable(norm=norm, cmap=cmap), ax=ax, orientation='vertical', label='Confidence')
440
 
441
- # Display the plot in the Streamlit app
442
- st.pyplot(fig)
443
  # call openai to pick the best classification result based on query
444
  openAICall = [
445
  SystemMessage(
 
15
  from PIL import Image
16
  import json
17
  import matplotlib.pyplot as plt
18
+ from matplotlib.colors import LinearSegmentedColormap
19
 
20
  st.set_page_config(
21
  page_title="Food Chain",
 
420
  confidences.append(confidence)
421
  print(fpredictions)
422
 
423
+ #reversing them so graph displays highest predictions at the top
424
+ confidences.reverse()
425
+ class_names.reverse()
426
+
427
  #display as a graph
428
  norm = plt.Normalize(min(confidences), max(confidences))
429
+ cmap = LinearSegmentedColormap.from_list("grey_orange", ["#808080", "#FFA500"]) #color map grey to orange
430
 
431
  fig, ax = plt.subplots(figsize=(8, 6))
432
  bars = ax.barh(class_names, confidences, color=cmap(norm(confidences)))
 
434
  # Add labels inside the bars, aligned to the right
435
  for bar in bars:
436
  width = bar.get_width()
437
+ ax.text(width - 0.02, bar.get_y() + bar.get_height()/2, f'{width:.2f}%',
438
  va='center', ha='right', color='white', fontweight='bold')
439
 
440
+ ax.set_xticklabels([]) #remove x label
441
+
442
+ st.pyplot(fig) # Display the plot in the Streamlit app
 
 
443
 
 
 
444
  # call openai to pick the best classification result based on query
445
  openAICall = [
446
  SystemMessage(