File size: 2,568 Bytes
851add9
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
import streamlit as st

def generate_recommendations(party_on_weekends, flavor_preference, texture_dislike, price_range):
    # Define the list of ingredients
    ingredients = ["oranges", "apples", "pears", "grapes", "watermelon", "lemon", "lime"]

    # Apply the rules based on user answers
    allowed_fruits = ingredients.copy()

    if party_on_weekends == "yes":
        allowed_fruits = list(set(allowed_fruits) & set(["apples", "pears", "grapes", "watermelon"]))

    if flavor_preference == "cider":
        allowed_fruits = list(set(allowed_fruits) & set(["apples", "oranges", "lemon", "lime"]))

    elif flavor_preference == "sweet":
        allowed_fruits = list(set(allowed_fruits) & set(["watermelon", "oranges"]))

    elif flavor_preference == "waterlike":
        allowed_fruits = list(set(allowed_fruits) & set(["watermelon"]))

    if "grapes" in allowed_fruits:
        allowed_fruits.remove("watermelon")

    if texture_dislike == "smooth":
        if "pears" in allowed_fruits:
            allowed_fruits.remove("pears")

    elif texture_dislike == "slimy":
        slimy_fruits = ["watermelon", "lime", "grapes"]
        allowed_fruits = list(set(allowed_fruits) - set(slimy_fruits))

    elif texture_dislike == "waterlike":
        if "watermelon" in allowed_fruits:
            allowed_fruits.remove("watermelon")

    if price_range < 3:
        if "lime" in allowed_fruits:
            allowed_fruits.remove("lime")
        if "watermelon" in allowed_fruits:
            allowed_fruits.remove("watermelon")

    elif 4 < price_range < 7:
        if "pears" in allowed_fruits:
            allowed_fruits.remove("pears")
        if "apples" in allowed_fruits:
            allowed_fruits.remove("apples")

    return allowed_fruits

# Streamlit UI
st.title("Fruit Recommendations App")

# Take user input for each question
party_answer = st.radio("Do you go out to party on weekends?", options=["Yes", "No"])
flavor_answer = st.radio("What flavors do you like?", options=["Cider", "Sweet", "Waterlike"])
texture_answer = st.radio("What texture do you dislike?", options=["Smooth", "Slimy", "Waterlike"])
price_answer = st.slider("What price range will you buy a drink for? ($1-$10)", min_value=1, max_value=10, value=5)

# Call the function with user inputs
party_on_weekends = "yes" if party_answer.lower() == "yes" else "no"
recommendations = generate_recommendations(party_on_weekends, flavor_answer.lower(), texture_answer.lower(), price_answer)

# Display recommendations
st.subheader("Recommended Fruits:")
st.write(recommendations)