Spaces:
Sleeping
Sleeping
graph method changes
Browse files
app.py
CHANGED
@@ -14,9 +14,8 @@ from langchain.schema.output_parser import StrOutputParser
|
|
14 |
from langchain_core.messages import HumanMessage, SystemMessage
|
15 |
from PIL import Image
|
16 |
import json
|
17 |
-
import
|
18 |
-
|
19 |
-
import textwrap
|
20 |
|
21 |
st.set_page_config(
|
22 |
page_title="Food Chain",
|
@@ -281,45 +280,34 @@ def display_dishes_in_grid(dishes, cols=3):
|
|
281 |
st.sidebar.write(dish.replace("_", " ").capitalize())
|
282 |
|
283 |
def display_prediction_graph(class_names, confidences):
|
284 |
-
|
285 |
-
|
286 |
-
|
287 |
-
|
288 |
-
|
289 |
-
|
290 |
-
|
291 |
-
|
292 |
-
|
293 |
-
|
294 |
-
|
295 |
-
|
296 |
-
|
297 |
-
|
298 |
-
|
299 |
-
|
300 |
-
|
301 |
-
|
302 |
-
|
303 |
-
|
304 |
-
|
305 |
-
|
306 |
-
|
307 |
-
|
308 |
-
|
309 |
-
|
310 |
-
# Wrapping labels
|
311 |
-
max_label_width = 10
|
312 |
-
labels = ax.get_yticklabels()
|
313 |
-
wrapped_labels = [textwrap.fill(label.get_text(), width=max_label_width) for label in labels] # Wrap the labels if they exceed the max width
|
314 |
-
ax.set_yticklabels(wrapped_labels, fontsize=16, color='white')
|
315 |
-
|
316 |
-
#no borders
|
317 |
-
for spine in ax.spines.values():
|
318 |
-
spine.set_visible(False)
|
319 |
|
320 |
-
|
321 |
-
|
322 |
-
st.pyplot(fig) # Display the plot
|
323 |
|
324 |
# #Streamlit
|
325 |
|
|
|
14 |
from langchain_core.messages import HumanMessage, SystemMessage
|
15 |
from PIL import Image
|
16 |
import json
|
17 |
+
import plotly.graph_objects as go
|
18 |
+
|
|
|
19 |
|
20 |
st.set_page_config(
|
21 |
page_title="Food Chain",
|
|
|
280 |
st.sidebar.write(dish.replace("_", " ").capitalize())
|
281 |
|
282 |
def display_prediction_graph(class_names, confidences):
|
283 |
+
values = [round(value, 2) for value in confidences]
|
284 |
+
|
285 |
+
# Create a horizontal bar chart
|
286 |
+
fig = go.Figure(go.Bar(
|
287 |
+
x=values,
|
288 |
+
y=class_names,
|
289 |
+
orientation='h',
|
290 |
+
marker=dict(color='orange'),
|
291 |
+
text=values, # Display values on the bars
|
292 |
+
textposition='outside' # Position the text outside the bars
|
293 |
+
))
|
294 |
+
|
295 |
+
# Update layout for better appearance
|
296 |
+
fig.update_layout(
|
297 |
+
title="Prediction Graph",
|
298 |
+
title_font=dict(color="black"),
|
299 |
+
xaxis_title="Probability",
|
300 |
+
yaxis_title="Categories",
|
301 |
+
margin=dict(l=20, r=20, t=60, b=20),
|
302 |
+
xaxis=dict(title_font=dict(color="black"), tickfont=dict(color="black")), # Ensure x-axis labels and title are black
|
303 |
+
yaxis=dict(autorange="reversed", title_font=dict(color="black"), tickfont=dict(color="black")), # Ensure y-axis labels and title are black
|
304 |
+
plot_bgcolor='rgba(230, 230, 230, 1)', # Classic gray background for the plot area
|
305 |
+
paper_bgcolor='rgba(240, 240, 240, 1)', # Lighter gray background for the paper area
|
306 |
+
font=dict(color="black") # Set font color to black for better contrast
|
307 |
+
)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
308 |
|
309 |
+
# Display the chart in Streamlit
|
310 |
+
st.plotly_chart(fig)
|
|
|
311 |
|
312 |
# #Streamlit
|
313 |
|