File size: 2,562 Bytes
ac69d4a
 
1a0c7f8
ac69d4a
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
import streamlit as st
import pandas as pd
import json
from urllib.request import urlopen
from bs4 import BeautifulSoup
  

# import the dataset
df = pd.read_json('recipes.json')
df['liststring'] = [','.join(map(str, l)) for l in df['Ingredients']]

st.write("#### Was koche ich heute?")

## Sidebar
def user_input_features():
    ingre1 = st.sidebar.text_input("Zutat 1")
    ingre2 = st.sidebar.text_input("Zutat 2", key = "zutat2")
    ingre3 = st.sidebar.text_input("Zutat 3", key = "zutat3")
    list_ingre = [ingre1, ingre2, ingre3]
    return list_ingre
st.sidebar.write("Was hast du schon im Kühlschrank?")
ingre = user_input_features()
results_ingredients = st.sidebar.button("Suchen")
st.sidebar.write("oder")
results = st.sidebar.button("Überrasch mich!")


# Sort the dataset
#create a dataframe "new" with all the ingredients that are in the list ingre
new = df[df['liststring'].apply(lambda x: ingre[0] in x)]
if ingre[1]:
    new = new[new['liststring'].apply(lambda x: ingre[1] in x)]
if ingre[2]:
    new = new[new['liststring'].apply(lambda x: ingre[2] in x)]
#new = df[df['liststring'].apply(lambda x: ingre in x)]

col1, col2 = st.columns(2)

if not new.empty:
    if results_ingredients:
        bla = new.sample(1)
       
       #Opening header images
        url = str(bla["Url"].iloc[0])
        htmldata = urlopen(url)
        soup = BeautifulSoup(htmldata, 'html.parser')
        images = soup.find_all('img')
        image = images[2]['src']

        #Opening the Rest
        zutaten = bla["Ingredients"].iloc[0]
        instructions = str(bla["Instructions"].iloc[0])
        name = str(bla["Name"].iloc[0])
        with col1:
            st.write("# " + name)
            for i in zutaten:
                st.write("* "+i)
            
        with col2:
            st.image(image)
            st.text_area("Anleitung", instructions, height=300)
else:
    st.write("###  Sorry, nichts gefunden...")

# Next
if results:
    new_sample = df.sample(1)

    #Opening header images
    url = str(new_sample["Url"].iloc[0])
    htmldata = urlopen(url)
    soup = BeautifulSoup(htmldata, 'html.parser')
    images = soup.find_all('img')
    image = images[2]['src']

    # Rest
    zutaten = new_sample["Ingredients"].iloc[0]
    instructions = str(new_sample["Instructions"].iloc[0])
    name = str(new_sample["Name"].iloc[0])
    with col1:
        st.write("# " + name)
        for i in zutaten:
            st.write("* "+i)
    with col2:
        st.image(image)
        st.text_area("Anleitung", instructions, height=300)