shivanis14 commited on
Commit
bf1ebc4
1 Parent(s): 7eb358f

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +14 -13
app.py CHANGED
@@ -397,20 +397,20 @@ def chatbot_response(image_urls_str, product_name_by_user, data_extractor_url, e
397
  image_urls = []
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
  print(f"similar_product_list_json : {similar_product_list_json}")
402
- similar_product_list = json.loads(similar_product_list_json)['product_list']
403
- return similar_product_list
404
 
405
  elif extract_info == True:
406
  with st.spinner("Analyzing the product... This may take a moment."):
407
  product_info_raw = get_product_data_from_db(product_name_by_user, data_extractor_url)
408
  print(f"DEBUG product_info_raw : {product_info_raw}")
409
  final_analysis = analyze_product(product_info_raw)
410
- return final_analysis
411
 
412
  else:
413
- return ""
414
 
415
  elif "http:/" in image_urls_str.lower() or "https:/" in image_urls_str.lower():
416
  # Extract image URL from user input
@@ -425,10 +425,10 @@ def chatbot_response(image_urls_str, product_name_by_user, data_extractor_url, e
425
  product_info_raw = extract_data_from_product_image(image_urls, data_extractor_url)
426
  print(f"DEBUG product_info_raw : {product_info_raw}")
427
  final_analysis = analyze_product(product_info_raw)
428
- return final_analysis
429
 
430
  else:
431
- return "I'm here to analyze food products. Please provide an image URL (Example : http://example.com/image.jpg) or product name (Example : Harvest Gold Bread)"
432
 
433
  # Streamlit app
434
  st.title("ConsumeWise")
@@ -460,13 +460,14 @@ if product_name_by_user != "":
460
  st.session_state["response_pending"] = True
461
 
462
  # Generate and display assistant response. Do not allow user to send prompts while chatbot is still generating a response
463
- similar_product_list = chatbot_response("", product_name_by_user, data_extractor_url, extract_info = False)
464
-
 
465
  if len(similar_product_list) > 0:
466
  choice = st.radio("Select a product:", similar_product_list.append("None of the above"))
467
  if choice != "None of the above":
468
- response = chatbot_response("", product_name_by_user, data_extractor_url, extract_info = True)
469
-
470
  if len(similar_product_list) == 0 or choice == "None of the above":
471
  image_urls_str = st.text_input("Enter image URLs separated by commas")
472
 
@@ -475,8 +476,8 @@ if product_name_by_user != "":
475
  with st.chat_message("user"):
476
  st.markdown(image_urls_str)
477
 
478
- response = chatbot_response(image_urls_str, "", data_extractor_url, extract_info = True)
479
-
480
  st.session_state.messages.append({"role": "assistant", "content": response})
481
  with st.chat_message("assistant"):
482
  st.markdown(response)
 
397
  image_urls = []
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
  print(f"similar_product_list_json : {similar_product_list_json}")
402
+ similar_product_list = similar_product_list_json['product_list']
403
+ return similar_product_list, "Product list found"
404
 
405
  elif extract_info == True:
406
  with st.spinner("Analyzing the product... This may take a moment."):
407
  product_info_raw = get_product_data_from_db(product_name_by_user, data_extractor_url)
408
  print(f"DEBUG product_info_raw : {product_info_raw}")
409
  final_analysis = analyze_product(product_info_raw)
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
 
425
  product_info_raw = extract_data_from_product_image(image_urls, data_extractor_url)
426
  print(f"DEBUG product_info_raw : {product_info_raw}")
427
  final_analysis = analyze_product(product_info_raw)
428
+ return [], final_analysis
429
 
430
  else:
431
+ return [], "I'm here to analyze food products. Please provide an image URL (Example : http://example.com/image.jpg) or product name (Example : Harvest Gold Bread)"
432
 
433
  # Streamlit app
434
  st.title("ConsumeWise")
 
460
  st.session_state["response_pending"] = True
461
 
462
  # Generate and display assistant response. Do not allow user to send prompts while chatbot is still generating a response
463
+ similar_product_list, msg = chatbot_response("", product_name_by_user, data_extractor_url, extract_info = False)
464
+
465
+ choice = ""
466
  if len(similar_product_list) > 0:
467
  choice = st.radio("Select a product:", similar_product_list.append("None of the above"))
468
  if choice != "None of the above":
469
+ _, response = chatbot_response("", product_name_by_user, data_extractor_url, extract_info = True)
470
+
471
  if len(similar_product_list) == 0 or choice == "None of the above":
472
  image_urls_str = st.text_input("Enter image URLs separated by commas")
473
 
 
476
  with st.chat_message("user"):
477
  st.markdown(image_urls_str)
478
 
479
+ _, response = chatbot_response(image_urls_str, "", data_extractor_url, extract_info = True)
480
+
481
  st.session_state.messages.append({"role": "assistant", "content": response})
482
  with st.chat_message("assistant"):
483
  st.markdown(response)