shivanis14 commited on
Commit
ec20771
1 Parent(s): 134c5ca

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +39 -56
app.py CHANGED
@@ -281,64 +281,47 @@ Claims Analysis:
281
  def main():
282
  st.title("Food Product Analysis Chatbot")
283
 
284
- # Initialize session state
285
- if 'state' not in st.session_state:
286
- st.session_state.state = 'ingredients'
287
- st.session_state.ingredients = []
288
- st.session_state.claims = []
289
- st.session_state.product_info = {}
290
-
291
- # Input fields based on current state
292
- if st.session_state.state == 'ingredients':
293
- ingredients = st.text_input("Enter the list of ingredients (separated by commas):")
294
- if st.button("Submit Ingredients"):
295
- st.session_state.ingredients = [ingredient.strip() for ingredient in ingredients.split(',')]
296
- st.session_state.state = 'claims'
297
- st.rerun()
298
-
299
- elif st.session_state.state == 'claims':
300
- claims = st.text_input("Enter the list of product claims (separated by commas):")
301
- if st.button("Submit Claims"):
302
- st.session_state.claims = [claim.strip() for claim in claims.split(',')]
303
- st.session_state.state = 'product_info'
304
- st.rerun()
305
-
306
- elif st.session_state.state == 'product_info':
307
- brand_name = st.text_input("Enter the brand name:")
308
- product_name = st.text_input("Enter the product name:")
309
- if st.button("Submit Product Info"):
310
- st.session_state.product_info = {
311
- "brandName": brand_name,
312
- "productName": product_name
313
- }
314
- st.session_state.state = 'analysis'
315
- st.rerun()
316
-
317
- elif st.session_state.state == 'analysis':
318
- st.write("Analyzing the product... This may take a moment.")
319
-
320
- # Perform analysis
321
- processing_level = analyze_processing_level(st.session_state.ingredients, assistant1)
322
- harmful_ingredient_analysis = analyze_harmful_ingredients(st.session_state.ingredients, assistant2)
323
- claims_analysis = analyze_claims(st.session_state.claims, assistant3)
324
-
325
- # Generate final analysis
326
- final_analysis = generate_final_analysis(
327
- st.session_state.product_info,
328
- processing_level,
329
- harmful_ingredient_analysis,
330
- claims_analysis
331
- )
332
-
333
- st.write("Analysis complete!")
334
- st.write("Final Analysis:")
335
  st.write(final_analysis)
336
-
 
337
  if st.button("Analyze Another Product"):
338
- st.session_state.state = 'ingredients'
339
- st.session_state.ingredients = []
340
- st.session_state.claims = []
341
- st.session_state.product_info = {}
342
  st.rerun()
343
 
344
  if __name__ == "__main__":
 
281
  def main():
282
  st.title("Food Product Analysis Chatbot")
283
 
284
+ # Create a form for all inputs
285
+ with st.form("product_analysis_form"):
286
+ st.write("Please enter the following information about the product:")
287
+ brand_name = st.text_input("Brand Name")
288
+ product_name = st.text_input("Product Name")
289
+ ingredients = st.text_area("Ingredients (separated by commas)")
290
+ claims = st.text_area("Product Claims (separated by commas)")
291
+
292
+ submitted = st.form_submit_button("Analyze Product")
293
+
294
+ if submitted:
295
+ # Process inputs
296
+ ingredients_list = [ingredient.strip() for ingredient in ingredients.split(',')]
297
+ claims_list = [claim.strip() for claim in claims.split(',')]
298
+ product_info = {
299
+ "brandName": brand_name,
300
+ "productName": product_name
301
+ }
302
+
303
+ # Display a message while analyzing
304
+ with st.spinner("Analyzing the product... This may take a moment."):
305
+ # Perform analysis
306
+ processing_level = analyze_processing_level(ingredients_list, assistant1.id)
307
+ harmful_ingredient_analysis = analyze_harmful_ingredients(ingredients_list, assistant2.id)
308
+ claims_analysis = analyze_claims(claims_list, assistant3.id)
309
+
310
+ # Generate final analysis
311
+ final_analysis = generate_final_analysis(
312
+ product_info,
313
+ processing_level,
314
+ harmful_ingredient_analysis,
315
+ claims_analysis
316
+ )
317
+
318
+ # Display results
319
+ st.success("Analysis complete!")
320
+ st.subheader("Final Analysis:")
 
 
 
 
 
 
 
 
 
 
 
 
 
 
321
  st.write(final_analysis)
322
+
323
+ # Option to start over
324
  if st.button("Analyze Another Product"):
 
 
 
 
325
  st.rerun()
326
 
327
  if __name__ == "__main__":