Spaces:
Sleeping
Sleeping
tonyliu404
commited on
Update app.py
Browse files
app.py
CHANGED
@@ -378,7 +378,7 @@ sample_RAG = {
|
|
378 |
|
379 |
col1, col2 = st.columns(2)
|
380 |
with col1:
|
381 |
-
st.title("Image Classification
|
382 |
if not uploaded_image and not recipe_submit:
|
383 |
placeholder = Image.open("dish-placeholder.jpg")
|
384 |
st.image(placeholder, caption="Placeholder Image.", use_container_width=True)
|
@@ -392,10 +392,11 @@ with col1:
|
|
392 |
# Display the image
|
393 |
st.image(input_image, caption="Uploaded Image.", use_container_width=True)
|
394 |
with col2:
|
395 |
-
st.title('RAG Recipe
|
396 |
if not query and not uploaded_image and not recipe_submit:
|
397 |
display_response(sample_RAG)
|
398 |
-
|
|
|
399 |
|
400 |
# Image Classification Section
|
401 |
if recipe_submit and uploaded_image:
|
@@ -403,18 +404,34 @@ if recipe_submit and uploaded_image:
|
|
403 |
predictions = classifyImage(input_image)
|
404 |
print("Predictions: ", predictions)
|
405 |
fpredictions = ""
|
|
|
406 |
|
407 |
# Show the top predictions with percentages
|
408 |
st.write("Top Predictions:")
|
409 |
for class_name, confidence in predictions:
|
410 |
-
|
411 |
-
|
412 |
-
|
413 |
-
|
414 |
-
|
415 |
-
st.markdown(f"*{class_name}*: {confidence:.2f}%")
|
416 |
print(fpredictions)
|
417 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
418 |
# call openai to pick the best classification result based on query
|
419 |
openAICall = [
|
420 |
SystemMessage(
|
|
|
378 |
|
379 |
col1, col2 = st.columns(2)
|
380 |
with col1:
|
381 |
+
st.title("Image Classification")
|
382 |
if not uploaded_image and not recipe_submit:
|
383 |
placeholder = Image.open("dish-placeholder.jpg")
|
384 |
st.image(placeholder, caption="Placeholder Image.", use_container_width=True)
|
|
|
392 |
# Display the image
|
393 |
st.image(input_image, caption="Uploaded Image.", use_container_width=True)
|
394 |
with col2:
|
395 |
+
st.title('RAG Recipe')
|
396 |
if not query and not uploaded_image and not recipe_submit:
|
397 |
display_response(sample_RAG)
|
398 |
+
if uploaded_image and not recipe_submit:
|
399 |
+
st.warning("Please click 'Chain Recipe' to generate a recipe from your uploaded image!", icon=':material/no_meals:')
|
400 |
|
401 |
# Image Classification Section
|
402 |
if recipe_submit and uploaded_image:
|
|
|
404 |
predictions = classifyImage(input_image)
|
405 |
print("Predictions: ", predictions)
|
406 |
fpredictions = ""
|
407 |
+
predictions_data = []
|
408 |
|
409 |
# Show the top predictions with percentages
|
410 |
st.write("Top Predictions:")
|
411 |
for class_name, confidence in predictions:
|
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 |
+
df = pd.DataFrame(predictions_data)
|
421 |
+
bar_chart = alt.Chart(df).mark_bar().encode(
|
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(
|