Spaces:
Sleeping
Sleeping
tonyliu404
commited on
Update app.py
Browse files
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 =
|
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
|
433 |
va='center', ha='right', color='white', fontweight='bold')
|
434 |
|
435 |
-
|
436 |
-
|
437 |
-
|
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(
|