shivanis14
commited on
Commit
•
452874e
1
Parent(s):
20e4640
Update app.py
Browse files
app.py
CHANGED
@@ -398,9 +398,10 @@ def chatbot_response(image_urls_str, product_name_by_user, data_extractor_url, e
|
|
398 |
if product_name_by_user != "":
|
399 |
similar_product_list_json = get_product_list(product_name_by_user, data_extractor_url)
|
400 |
if similar_product_list_json != {} and extract_info == False:
|
401 |
-
|
402 |
-
|
403 |
-
|
|
|
404 |
|
405 |
elif extract_info == True:
|
406 |
with st.spinner("Analyzing the product... This may take a moment."):
|
@@ -410,7 +411,7 @@ def chatbot_response(image_urls_str, product_name_by_user, data_extractor_url, e
|
|
410 |
return [], final_analysis
|
411 |
|
412 |
else:
|
413 |
-
return [], "Product not found"
|
414 |
|
415 |
elif "http:/" in image_urls_str.lower() or "https:/" in image_urls_str.lower():
|
416 |
# Extract image URL from user input
|
@@ -456,10 +457,12 @@ if prompt := st.chat_input("What product would you like to analyze?"):
|
|
456 |
full_response = ""
|
457 |
|
458 |
# Simulate stream of response with milliseconds delay
|
459 |
-
similar_products,
|
460 |
for product in similar_products:
|
461 |
full_response += product + " "
|
462 |
message_placeholder.markdown(full_response + "▌")
|
|
|
|
|
463 |
message_placeholder.markdown(full_response)
|
464 |
|
465 |
# Add assistant response to chat history
|
@@ -476,14 +479,14 @@ if prompt := st.chat_input("What product would you like to analyze?"):
|
|
476 |
|
477 |
# Generate detailed response for selected product
|
478 |
with st.chat_message("assistant"):
|
479 |
-
detailed_response = chatbot_response("", choice, data_extractor_url, extract_info=True)
|
480 |
st.markdown(detailed_response)
|
481 |
st.session_state.messages.append({"role": "assistant", "content": detailed_response})
|
482 |
elif choice == "None of the above":
|
483 |
st.text_input("Please provide image URLs separated by commas:")
|
484 |
|
485 |
# Option to clear chat history
|
486 |
-
if st.button("Clear Chat History"):
|
487 |
-
st.session_state.messages = []
|
488 |
-
st.session_state.product_selected = False
|
489 |
-
st.rerun()
|
|
|
398 |
if product_name_by_user != "":
|
399 |
similar_product_list_json = get_product_list(product_name_by_user, data_extractor_url)
|
400 |
if similar_product_list_json != {} and extract_info == False:
|
401 |
+
with st.spinner("Fetching product information from our database... This may take a moment."):
|
402 |
+
print(f"similar_product_list_json : {similar_product_list_json}")
|
403 |
+
similar_product_list = similar_product_list_json['product_list']
|
404 |
+
return similar_product_list, "Product list found from our database"
|
405 |
|
406 |
elif extract_info == True:
|
407 |
with st.spinner("Analyzing the product... This may take a moment."):
|
|
|
411 |
return [], final_analysis
|
412 |
|
413 |
else:
|
414 |
+
return [], "Product not found in our database. Please provide an image URL (Example : http://example.com/image.jpg)"
|
415 |
|
416 |
elif "http:/" in image_urls_str.lower() or "https:/" in image_urls_str.lower():
|
417 |
# Extract image URL from user input
|
|
|
457 |
full_response = ""
|
458 |
|
459 |
# Simulate stream of response with milliseconds delay
|
460 |
+
similar_products, msg = chatbot_response(prompt, "", data_extractor_url, extract_info=False)
|
461 |
for product in similar_products:
|
462 |
full_response += product + " "
|
463 |
message_placeholder.markdown(full_response + "▌")
|
464 |
+
if len(similar_products) == 0:
|
465 |
+
full_response = msg
|
466 |
message_placeholder.markdown(full_response)
|
467 |
|
468 |
# Add assistant response to chat history
|
|
|
479 |
|
480 |
# Generate detailed response for selected product
|
481 |
with st.chat_message("assistant"):
|
482 |
+
_, detailed_response = chatbot_response("", choice, data_extractor_url, extract_info=True)
|
483 |
st.markdown(detailed_response)
|
484 |
st.session_state.messages.append({"role": "assistant", "content": detailed_response})
|
485 |
elif choice == "None of the above":
|
486 |
st.text_input("Please provide image URLs separated by commas:")
|
487 |
|
488 |
# Option to clear chat history
|
489 |
+
#if st.button("Clear Chat History"):
|
490 |
+
# st.session_state.messages = []
|
491 |
+
# st.session_state.product_selected = False
|
492 |
+
# st.rerun()
|