Update app.py
Browse files
app.py
CHANGED
|
@@ -1,20 +1,6 @@
|
|
| 1 |
import streamlit as st
|
| 2 |
-
from transformers import BertTokenizer, BertForTokenClassification, pipeline
|
| 3 |
import random
|
| 4 |
|
| 5 |
-
# Load the NER model and tokenizer
|
| 6 |
-
model_name = "DavidEB2/bert-large-NER-finetuned-Tasteset-spoonacular"
|
| 7 |
-
tokenizer = BertTokenizer.from_pretrained(model_name)
|
| 8 |
-
model = BertForTokenClassification.from_pretrained(model_name)
|
| 9 |
-
|
| 10 |
-
ner_pipeline = pipeline("ner", model=model, tokenizer=tokenizer)
|
| 11 |
-
|
| 12 |
-
# Function to extract ingredients
|
| 13 |
-
def extract_ingredients(text):
|
| 14 |
-
entities = ner_pipeline(text)
|
| 15 |
-
ingredients = [entity['word'] for entity in entities if entity['entity'] == 'B-ingredient']
|
| 16 |
-
return ingredients
|
| 17 |
-
|
| 18 |
# Sample dataset for dish suggestions and recipes
|
| 19 |
# Ideally, this would be a large dataset or database
|
| 20 |
recipe_data = {
|
|
@@ -57,17 +43,18 @@ def suggest_dishes(ingredients):
|
|
| 57 |
st.title("Cooking Suggestion App")
|
| 58 |
st.write("Enter 1 or 2 ingredients to get recipe suggestions:")
|
| 59 |
|
| 60 |
-
|
|
|
|
| 61 |
|
| 62 |
if st.button("Suggest Dishes"):
|
| 63 |
if ingredients_input:
|
| 64 |
-
#
|
| 65 |
-
|
| 66 |
-
st.write("
|
| 67 |
|
| 68 |
-
if
|
| 69 |
-
# Suggest dishes based on
|
| 70 |
-
suggested_dishes = suggest_dishes(
|
| 71 |
if suggested_dishes:
|
| 72 |
st.write("Suggested Dishes:")
|
| 73 |
selected_dish = st.selectbox("Choose a dish", suggested_dishes)
|
|
@@ -76,8 +63,8 @@ if st.button("Suggest Dishes"):
|
|
| 76 |
st.write(f"Recipe for {selected_dish}:")
|
| 77 |
st.write(recipe_data[selected_dish]["recipe"])
|
| 78 |
else:
|
| 79 |
-
st.write("No dishes found for the
|
| 80 |
else:
|
| 81 |
-
st.write("No ingredients
|
| 82 |
else:
|
| 83 |
st.write("Please enter some ingredients.")
|
|
|
|
| 1 |
import streamlit as st
|
|
|
|
| 2 |
import random
|
| 3 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 4 |
# Sample dataset for dish suggestions and recipes
|
| 5 |
# Ideally, this would be a large dataset or database
|
| 6 |
recipe_data = {
|
|
|
|
| 43 |
st.title("Cooking Suggestion App")
|
| 44 |
st.write("Enter 1 or 2 ingredients to get recipe suggestions:")
|
| 45 |
|
| 46 |
+
# Ingredients input
|
| 47 |
+
ingredients_input = st.text_input("Enter ingredients (comma separated):")
|
| 48 |
|
| 49 |
if st.button("Suggest Dishes"):
|
| 50 |
if ingredients_input:
|
| 51 |
+
# Split input into individual ingredients
|
| 52 |
+
ingredients = [ingredient.strip().lower() for ingredient in ingredients_input.split(',')]
|
| 53 |
+
st.write("Entered Ingredients:", ingredients)
|
| 54 |
|
| 55 |
+
if ingredients:
|
| 56 |
+
# Suggest dishes based on entered ingredients
|
| 57 |
+
suggested_dishes = suggest_dishes(ingredients)
|
| 58 |
if suggested_dishes:
|
| 59 |
st.write("Suggested Dishes:")
|
| 60 |
selected_dish = st.selectbox("Choose a dish", suggested_dishes)
|
|
|
|
| 63 |
st.write(f"Recipe for {selected_dish}:")
|
| 64 |
st.write(recipe_data[selected_dish]["recipe"])
|
| 65 |
else:
|
| 66 |
+
st.write("No dishes found for the entered ingredients.")
|
| 67 |
else:
|
| 68 |
+
st.write("No valid ingredients entered.")
|
| 69 |
else:
|
| 70 |
st.write("Please enter some ingredients.")
|