Spaces:
Sleeping
Sleeping
Commit ·
2aaaaf9
1
Parent(s): 7619f82
Update app.py
Browse files
app.py
CHANGED
|
@@ -3,7 +3,6 @@ from transformers import pipeline
|
|
| 3 |
from rembg import remove
|
| 4 |
from PIL import Image
|
| 5 |
from io import BytesIO
|
| 6 |
-
import base64
|
| 7 |
from transformers import GPT2LMHeadModel, GPT2Tokenizer
|
| 8 |
import random
|
| 9 |
|
|
@@ -26,21 +25,33 @@ def convert_image(img):
|
|
| 26 |
|
| 27 |
def fix_image(upload):
|
| 28 |
image = Image.open(upload)
|
| 29 |
-
|
| 30 |
-
col1.image(image)
|
| 31 |
|
| 32 |
fixed = remove(image)
|
| 33 |
-
|
| 34 |
-
col2.image(fixed)
|
| 35 |
st.sidebar.markdown("\n")
|
| 36 |
st.sidebar.download_button("Download fixed image", convert_image(fixed), "fixed.png", "image/png")
|
| 37 |
|
| 38 |
def generate_recipe(title, max_length=200):
|
| 39 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 40 |
|
| 41 |
-
if
|
| 42 |
-
selected_entry =
|
| 43 |
-
title =
|
| 44 |
ingredients = selected_entry["ingredients"]
|
| 45 |
else:
|
| 46 |
title = "Default Recipe Title"
|
|
@@ -54,36 +65,10 @@ def generate_recipe(title, max_length=200):
|
|
| 54 |
generated_recipe = recipe_tokenizer.decode(output[0], skip_special_tokens=True)
|
| 55 |
return generated_recipe
|
| 56 |
|
| 57 |
-
# Your dataset of titles, ingredients, and recipes
|
| 58 |
-
dataset = [
|
| 59 |
-
{
|
| 60 |
-
"title": "Gulab Jamun",
|
| 61 |
-
"ingredients": ["milk powder", "ghee", "rose water", "saffron", "cardamom", "sugar syrup"],
|
| 62 |
-
"recipe": "Instructions for making Gulab Jamun..."
|
| 63 |
-
},
|
| 64 |
-
{
|
| 65 |
-
"title": "Jalebi",
|
| 66 |
-
"ingredients": ["all-purpose flour", "yogurt", "sugar", "water", "saffron strands", "cardamom powder", "ghee or oil for frying"],
|
| 67 |
-
"recipe": "Instructions for making Jalebi..."
|
| 68 |
-
},
|
| 69 |
-
{
|
| 70 |
-
"title": "Rasgulla",
|
| 71 |
-
"ingredients": ["milk", "sugar", "lemon juice", "rose water"],
|
| 72 |
-
"recipe": "Instructions for making Rasgulla..."
|
| 73 |
-
}
|
| 74 |
-
]
|
| 75 |
-
|
| 76 |
col1, col2 = st.columns(2)
|
| 77 |
my_upload = st.sidebar.file_uploader("Upload an image", type=["png", "jpg", "jpeg"])
|
| 78 |
|
| 79 |
-
|
| 80 |
-
st.markdown("""---""")
|
| 81 |
-
st.write()
|
| 82 |
-
|
| 83 |
-
# global label
|
| 84 |
-
# label = ""
|
| 85 |
-
|
| 86 |
-
if my_upload is not None:
|
| 87 |
st.image(my_upload, caption="Uploaded Image", use_column_width=True)
|
| 88 |
|
| 89 |
if st.sidebar.button("Classify"):
|
|
@@ -104,16 +89,12 @@ if my_upload is not None:
|
|
| 104 |
if my_upload.size > MAX_FILE_SIZE:
|
| 105 |
st.error("The uploaded file is too large. Please upload an image smaller than 5MB.")
|
| 106 |
else:
|
| 107 |
-
fix_image(
|
| 108 |
-
else:
|
| 109 |
-
fix_image("jalebi.jpg")
|
| 110 |
-
|
| 111 |
-
|
| 112 |
|
| 113 |
# Recipe generation based on selected item
|
| 114 |
st.write("## Recipe Generation")
|
| 115 |
|
| 116 |
-
selected_item = st.selectbox("Select a food item", [
|
| 117 |
if st.button("Generate Recipe"):
|
| 118 |
generated_recipe = generate_recipe(selected_item, max_length=200)
|
| 119 |
st.write(f"Recipe for {selected_item}:\n{generated_recipe}")
|
|
@@ -126,4 +107,5 @@ st.sidebar.markdown("3. Select a food item to generate a recipe.")
|
|
| 126 |
st.sidebar.markdown("4. Click the 'Generate Recipe' button to get the recipe.")
|
| 127 |
|
| 128 |
# Display a placeholder for the main content
|
| 129 |
-
st.write("Please upload an image and use the sidebar to classify it and generate a recipe.")
|
|
|
|
|
|
| 3 |
from rembg import remove
|
| 4 |
from PIL import Image
|
| 5 |
from io import BytesIO
|
|
|
|
| 6 |
from transformers import GPT2LMHeadModel, GPT2Tokenizer
|
| 7 |
import random
|
| 8 |
|
|
|
|
| 25 |
|
| 26 |
def fix_image(upload):
|
| 27 |
image = Image.open(upload)
|
| 28 |
+
st.image(image, caption="Original Image", use_column_width=True)
|
|
|
|
| 29 |
|
| 30 |
fixed = remove(image)
|
| 31 |
+
st.image(fixed, caption="Fixed Image", use_column_width=True)
|
|
|
|
| 32 |
st.sidebar.markdown("\n")
|
| 33 |
st.sidebar.download_button("Download fixed image", convert_image(fixed), "fixed.png", "image/png")
|
| 34 |
|
| 35 |
def generate_recipe(title, max_length=200):
|
| 36 |
+
# Replace this with your actual dataset
|
| 37 |
+
dataset = {
|
| 38 |
+
"Gulab Jamun": {
|
| 39 |
+
"ingredients": ["milk powder", "ghee", "rose water", "saffron", "cardamom", "sugar syrup"],
|
| 40 |
+
"recipe": "Instructions for making Gulab Jamun...",
|
| 41 |
+
},
|
| 42 |
+
"Jalebi": {
|
| 43 |
+
"ingredients": ["all-purpose flour", "yogurt", "sugar", "water", "saffron strands", "cardamom powder", "ghee or oil for frying"],
|
| 44 |
+
"recipe": "Instructions for making Jalebi...",
|
| 45 |
+
},
|
| 46 |
+
"Rasgulla": {
|
| 47 |
+
"ingredients": ["milk", "sugar", "lemon juice", "rose water"],
|
| 48 |
+
"recipe": "Instructions for making Rasgulla...",
|
| 49 |
+
}
|
| 50 |
+
}
|
| 51 |
|
| 52 |
+
if title in dataset:
|
| 53 |
+
selected_entry = dataset[title]
|
| 54 |
+
title = title
|
| 55 |
ingredients = selected_entry["ingredients"]
|
| 56 |
else:
|
| 57 |
title = "Default Recipe Title"
|
|
|
|
| 65 |
generated_recipe = recipe_tokenizer.decode(output[0], skip_special_tokens=True)
|
| 66 |
return generated_recipe
|
| 67 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 68 |
col1, col2 = st.columns(2)
|
| 69 |
my_upload = st.sidebar.file_uploader("Upload an image", type=["png", "jpg", "jpeg"])
|
| 70 |
|
| 71 |
+
if my_upload:
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 72 |
st.image(my_upload, caption="Uploaded Image", use_column_width=True)
|
| 73 |
|
| 74 |
if st.sidebar.button("Classify"):
|
|
|
|
| 89 |
if my_upload.size > MAX_FILE_SIZE:
|
| 90 |
st.error("The uploaded file is too large. Please upload an image smaller than 5MB.")
|
| 91 |
else:
|
| 92 |
+
fix_image(my_upload)
|
|
|
|
|
|
|
|
|
|
|
|
|
| 93 |
|
| 94 |
# Recipe generation based on selected item
|
| 95 |
st.write("## Recipe Generation")
|
| 96 |
|
| 97 |
+
selected_item = st.selectbox("Select a food item", ["Gulab Jamun", "Jalebi", "Rasgulla"])
|
| 98 |
if st.button("Generate Recipe"):
|
| 99 |
generated_recipe = generate_recipe(selected_item, max_length=200)
|
| 100 |
st.write(f"Recipe for {selected_item}:\n{generated_recipe}")
|
|
|
|
| 107 |
st.sidebar.markdown("4. Click the 'Generate Recipe' button to get the recipe.")
|
| 108 |
|
| 109 |
# Display a placeholder for the main content
|
| 110 |
+
st.write("Please upload an image and use the sidebar to classify it and generate a recipe.")
|
| 111 |
+
|