Spaces:
Sleeping
Sleeping
tonyliu404
commited on
Update app.py
Browse files
app.py
CHANGED
@@ -320,38 +320,38 @@ with st.expander("**What is FOOD CHAIN?**"):
|
|
320 |
|
321 |
col1, col2 = st.columns(2)
|
322 |
with col1:
|
|
|
323 |
if not uploaded_image:
|
324 |
placeholder = Image.open("dish-placeholder.jpg")
|
325 |
st.image(placeholder, caption="Placeholder Image.", use_container_width=True)
|
326 |
st.write("Top Predictions:")
|
327 |
st.markdown(f"*Donuts*: 98.11%")
|
328 |
-
|
|
|
|
|
329 |
# Image Classification Section
|
330 |
if uploaded_image and recipe_submit:
|
331 |
-
with
|
332 |
-
|
333 |
-
|
334 |
-
|
335 |
-
|
336 |
-
|
337 |
-
|
338 |
-
|
339 |
-
|
340 |
-
|
341 |
-
|
342 |
-
|
343 |
-
|
344 |
-
|
345 |
-
|
346 |
-
|
347 |
-
|
348 |
-
|
349 |
-
|
350 |
-
|
351 |
-
|
352 |
-
class_name = class_name.title()
|
353 |
-
st.markdown(f"*{class_name}*: {confidence:.2f}%")
|
354 |
-
print(fpredictions)
|
355 |
|
356 |
# call openai to pick the best classification result based on query
|
357 |
openAICall = [
|
@@ -396,42 +396,35 @@ if uploaded_image and recipe_submit:
|
|
396 |
else:
|
397 |
RAGresponse = get_response(predictions[0][0])
|
398 |
print("RAGresponse: ", RAGresponse)
|
399 |
-
|
400 |
-
with st.expander("Recipe Generation", expanded=True, icon=':material/menu_book:'):
|
401 |
-
st.title('Results: RAG')
|
402 |
-
display_response(RAGresponse)
|
403 |
elif uploaded_image is not None:
|
404 |
with col1:
|
405 |
-
|
406 |
-
|
407 |
-
|
408 |
-
|
409 |
-
|
410 |
-
|
411 |
-
|
412 |
-
|
413 |
-
|
414 |
-
|
415 |
-
|
416 |
-
|
417 |
-
|
418 |
-
|
419 |
-
|
420 |
-
|
421 |
-
|
422 |
-
|
423 |
-
|
424 |
-
|
425 |
-
st.markdown(f"*{class_name}*: {confidence:.2f}%")
|
426 |
-
print(fpredictions)
|
427 |
|
428 |
elif recipe_submit:
|
429 |
with col2:
|
430 |
response = get_response(query)
|
431 |
print(response)
|
432 |
-
|
433 |
-
st.title("Results: RAG")
|
434 |
-
display_response(response)
|
435 |
else:
|
436 |
st.warning("Please input an image and/or a prompt.", icon=':material/no_meals:')
|
437 |
|
|
|
320 |
|
321 |
col1, col2 = st.columns(2)
|
322 |
with col1:
|
323 |
+
st.title("Image Classification Result")
|
324 |
if not uploaded_image:
|
325 |
placeholder = Image.open("dish-placeholder.jpg")
|
326 |
st.image(placeholder, caption="Placeholder Image.", use_container_width=True)
|
327 |
st.write("Top Predictions:")
|
328 |
st.markdown(f"*Donuts*: 98.11%")
|
329 |
+
with col2:
|
330 |
+
st.title('Results: RAG')
|
331 |
+
|
332 |
# Image Classification Section
|
333 |
if uploaded_image and recipe_submit:
|
334 |
+
with col1:
|
335 |
+
# Open the image
|
336 |
+
input_image = Image.open(uploaded_image)
|
337 |
+
|
338 |
+
# Display the image
|
339 |
+
st.image(input_image, caption="Uploaded Image.", use_container_width=True)
|
340 |
+
|
341 |
+
predictions = classifyImage(input_image)
|
342 |
+
print("Predictions: ", predictions)
|
343 |
+
fpredictions = ""
|
344 |
+
|
345 |
+
# Show the top predictions with percentages
|
346 |
+
st.write("Top Predictions:")
|
347 |
+
for class_name, confidence in predictions:
|
348 |
+
if int(confidence) > 0.05:
|
349 |
+
fpredictions += f"{class_name}: {confidence:.2f}%,"
|
350 |
+
if int(confidence) > 5:
|
351 |
+
class_name = class_name.replace("_", " ")
|
352 |
+
class_name = class_name.title()
|
353 |
+
st.markdown(f"*{class_name}*: {confidence:.2f}%")
|
354 |
+
print(fpredictions)
|
|
|
|
|
|
|
355 |
|
356 |
# call openai to pick the best classification result based on query
|
357 |
openAICall = [
|
|
|
396 |
else:
|
397 |
RAGresponse = get_response(predictions[0][0])
|
398 |
print("RAGresponse: ", RAGresponse)
|
399 |
+
display_response(RAGresponse)
|
|
|
|
|
|
|
400 |
elif uploaded_image is not None:
|
401 |
with col1:
|
402 |
+
# Open the image
|
403 |
+
input_image = Image.open(uploaded_image)
|
404 |
+
|
405 |
+
# Display the image
|
406 |
+
st.image(input_image, caption="Uploaded Image.", use_container_width=True)
|
407 |
+
|
408 |
+
# Classify the image and display the result
|
409 |
+
predictions = classifyImage(input_image)
|
410 |
+
fpredictions = ""
|
411 |
+
|
412 |
+
# Show the top predictions with percentages
|
413 |
+
st.write("Top Predictions:")
|
414 |
+
for class_name, confidence in predictions:
|
415 |
+
if int(confidence) > 0.05:
|
416 |
+
fpredictions += f"{class_name}: {confidence:.2f}%,"
|
417 |
+
if int(confidence) > 5:
|
418 |
+
class_name = class_name.replace("_", " ")
|
419 |
+
class_name = class_name.title()
|
420 |
+
st.markdown(f"*{class_name}*: {confidence:.2f}%")
|
421 |
+
print(fpredictions)
|
|
|
|
|
422 |
|
423 |
elif recipe_submit:
|
424 |
with col2:
|
425 |
response = get_response(query)
|
426 |
print(response)
|
427 |
+
display_response(response)
|
|
|
|
|
428 |
else:
|
429 |
st.warning("Please input an image and/or a prompt.", icon=':material/no_meals:')
|
430 |
|