Spaces:
Sleeping
Sleeping
tonyliu404
commited on
Update app.py
Browse files
app.py
CHANGED
@@ -404,7 +404,8 @@ if recipe_submit and uploaded_image:
|
|
404 |
predictions = classifyImage(input_image)
|
405 |
print("Predictions: ", predictions)
|
406 |
fpredictions = ""
|
407 |
-
|
|
|
408 |
|
409 |
# Show the top predictions with percentages
|
410 |
st.write("Top Predictions:")
|
@@ -412,26 +413,32 @@ if recipe_submit and uploaded_image:
|
|
412 |
fpredictions += f"{class_name}: {confidence:.2f}%,"
|
413 |
class_name = class_name.replace("_", " ")
|
414 |
class_name = class_name.title()
|
415 |
-
predictions_data.append({"class_name": class_name, "confidence": confidence})
|
416 |
st.markdown(f"*{class_name}*: {confidence:.2f}%")
|
|
|
|
|
417 |
print(fpredictions)
|
418 |
|
419 |
#display as a graph
|
420 |
-
|
421 |
-
|
422 |
-
x='confidence:Q', # Quantitative axis for confidence
|
423 |
-
y='class_name:N', # Nominal axis for class names
|
424 |
-
color=alt.Color('confidence:Q', scale=alt.Scale(domain=[0, 1], range=['gray', 'orange'])), # Color scale from gray to orange
|
425 |
-
tooltip=['class_name:N', 'confidence:Q'] # Tooltip shows class name and confidence
|
426 |
-
).properties(
|
427 |
-
width=500, # Adjust the width of the chart
|
428 |
-
height=300 # Adjust the height of the chart
|
429 |
-
)
|
430 |
-
|
431 |
-
# Display the bar chart in the app
|
432 |
-
st.altair_chart(bar_chart, use_container_width=True)
|
433 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
434 |
|
|
|
|
|
|
|
|
|
435 |
# call openai to pick the best classification result based on query
|
436 |
openAICall = [
|
437 |
SystemMessage(
|
@@ -476,8 +483,7 @@ if recipe_submit and uploaded_image:
|
|
476 |
RAGresponse = get_response(predictions[0][0])
|
477 |
print("RAGresponse: ", RAGresponse)
|
478 |
display_response(RAGresponse)
|
479 |
-
|
480 |
-
st.warning("Please upload an image before submitting.", icon=':material/no_meals:')
|
481 |
# elif uploaded_image is not None:
|
482 |
# with col1:
|
483 |
# # Open the image
|
|
|
404 |
predictions = classifyImage(input_image)
|
405 |
print("Predictions: ", predictions)
|
406 |
fpredictions = ""
|
407 |
+
class_names = []
|
408 |
+
confidences = []
|
409 |
|
410 |
# Show the top predictions with percentages
|
411 |
st.write("Top Predictions:")
|
|
|
413 |
fpredictions += f"{class_name}: {confidence:.2f}%,"
|
414 |
class_name = class_name.replace("_", " ")
|
415 |
class_name = class_name.title()
|
|
|
416 |
st.markdown(f"*{class_name}*: {confidence:.2f}%")
|
417 |
+
class_names.append(class_name)
|
418 |
+
confidences.append(confidence)
|
419 |
print(fpredictions)
|
420 |
|
421 |
#display as a graph
|
422 |
+
norm = plt.Normalize(min(confidences), max(confidences))
|
423 |
+
cmap = plt.get_cmap('Oranges')
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
424 |
|
425 |
+
fig, ax = plt.subplots(figsize=(8, 6))
|
426 |
+
bars = ax.barh(class_names, confidences, color=cmap(norm(confidences)))
|
427 |
+
|
428 |
+
# Add labels inside the bars, aligned to the right
|
429 |
+
for bar in bars:
|
430 |
+
width = bar.get_width()
|
431 |
+
ax.text(width - 0.02, bar.get_y() + bar.get_height()/2, f'{width*100:.2f}%',
|
432 |
+
va='center', ha='right', color='white', fontweight='bold')
|
433 |
+
|
434 |
+
|
435 |
+
ax.set_xlabel('Confidence (%)')
|
436 |
+
ax.set_title('Top Predictions')
|
437 |
|
438 |
+
plt.colorbar(plt.cm.ScalarMappable(norm=norm, cmap=cmap), ax=ax, orientation='vertical', label='Confidence')
|
439 |
+
|
440 |
+
# Display the plot in the Streamlit app
|
441 |
+
st.pyplot(fig)
|
442 |
# call openai to pick the best classification result based on query
|
443 |
openAICall = [
|
444 |
SystemMessage(
|
|
|
483 |
RAGresponse = get_response(predictions[0][0])
|
484 |
print("RAGresponse: ", RAGresponse)
|
485 |
display_response(RAGresponse)
|
486 |
+
|
|
|
487 |
# elif uploaded_image is not None:
|
488 |
# with col1:
|
489 |
# # Open the image
|