Spaces:
Runtime error
Runtime error
allow more photo uploads.
Browse files- app.py +35 -21
- wedding_themes.csv +2 -2
app.py
CHANGED
|
@@ -5,36 +5,50 @@ import numpy as np
|
|
| 5 |
import pandas as pd
|
| 6 |
|
| 7 |
USE_DESCRIPTION_AS_LABEL = False
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 8 |
smaller_model = "openai/clip-vit-base-patch32"
|
| 9 |
model = CLIPModel.from_pretrained(smaller_model)
|
| 10 |
processor = CLIPProcessor.from_pretrained(smaller_model)
|
| 11 |
themes = pd.read_csv("wedding_themes.csv")
|
|
|
|
| 12 |
st.title("What's your wedding personality?")
|
| 13 |
-
|
| 14 |
-
|
| 15 |
-
|
| 16 |
-
col1, col2 = st.columns(2)
|
| 17 |
-
|
| 18 |
-
image = Image.open(file_name)
|
| 19 |
-
col1.image(image, use_column_width=True)
|
| 20 |
|
|
|
|
| 21 |
labels = themes.theme.tolist()
|
| 22 |
descriptions = themes.description.tolist()
|
| 23 |
-
|
| 24 |
-
|
| 25 |
-
|
| 26 |
-
|
| 27 |
-
|
| 28 |
-
|
| 29 |
-
|
| 30 |
-
|
| 31 |
-
|
| 32 |
-
|
|
|
|
| 33 |
|
| 34 |
-
|
|
|
|
|
|
|
| 35 |
top_labels = np.array(labels)[sorted_args].tolist()
|
| 36 |
top_description = descriptions[sorted_args[0]]
|
|
|
|
|
|
|
| 37 |
|
| 38 |
-
|
| 39 |
-
|
| 40 |
-
|
|
|
|
|
|
| 5 |
import pandas as pd
|
| 6 |
|
| 7 |
USE_DESCRIPTION_AS_LABEL = False
|
| 8 |
+
NUM_OTHER_TYPES = 4
|
| 9 |
+
MAX_FILES = 3
|
| 10 |
+
|
| 11 |
+
def _get_probs(image, text):
|
| 12 |
+
inputs = processor(text=text, images=image, return_tensors="pt", padding=True)
|
| 13 |
+
outputs = model(**inputs)
|
| 14 |
+
logits_per_image = outputs.logits_per_image
|
| 15 |
+
probs = logits_per_image.softmax(dim=1).detach().numpy().flatten()
|
| 16 |
+
return probs
|
| 17 |
+
|
| 18 |
smaller_model = "openai/clip-vit-base-patch32"
|
| 19 |
model = CLIPModel.from_pretrained(smaller_model)
|
| 20 |
processor = CLIPProcessor.from_pretrained(smaller_model)
|
| 21 |
themes = pd.read_csv("wedding_themes.csv")
|
| 22 |
+
themes = themes.query("use=='Y'")
|
| 23 |
st.title("What's your wedding personality?")
|
| 24 |
+
filenames = st.file_uploader(f"Upload up to {MAX_FILES} wedding photos that you like.", accept_multiple_files=True)
|
| 25 |
+
if len(filenames) > MAX_FILES:
|
| 26 |
+
st.warning(f"Only 3 images are allowed!")
|
|
|
|
|
|
|
|
|
|
|
|
|
| 27 |
|
| 28 |
+
if 0 < len(filenames) <= MAX_FILES and st.button("Submit"):
|
| 29 |
labels = themes.theme.tolist()
|
| 30 |
descriptions = themes.description.tolist()
|
| 31 |
+
all_probs = []
|
| 32 |
+
images = []
|
| 33 |
+
for filename in filenames:
|
| 34 |
+
image = Image.open(filename)
|
| 35 |
+
if USE_DESCRIPTION_AS_LABEL:
|
| 36 |
+
probs = _get_probs(image, descriptions)
|
| 37 |
+
else:
|
| 38 |
+
labels_with_wedding = [(x + " wedding").lower() for x in labels]
|
| 39 |
+
probs = _get_probs(image, labels_with_wedding)
|
| 40 |
+
all_probs.append(probs)
|
| 41 |
+
images.append(image)
|
| 42 |
|
| 43 |
+
# Calculate the total probability and write results.
|
| 44 |
+
combined_probs = np.sum(all_probs, axis=0)
|
| 45 |
+
sorted_args = np.argsort(combined_probs)[::-1][:(1+NUM_OTHER_TYPES)].tolist()
|
| 46 |
top_labels = np.array(labels)[sorted_args].tolist()
|
| 47 |
top_description = descriptions[sorted_args[0]]
|
| 48 |
+
st.subheader(top_labels[0])
|
| 49 |
+
st.write(f"{top_description} \n\n Other personalities you might like: {', '.join(top_labels[1:])}")
|
| 50 |
|
| 51 |
+
# Display the uploaded images.
|
| 52 |
+
cols = st.columns(len(filenames))
|
| 53 |
+
for col, image in zip(cols, images):
|
| 54 |
+
col.image(image)
|
wedding_themes.csv
CHANGED
|
@@ -27,7 +27,7 @@ Beach,"If you’re dreaming of getting married barefoot, toes in the sand, then
|
|
| 27 |
Summer glamp,Go glamping for a laid-back camp-themed wedding with a touch of glamour. Elevate a barn or backyard venue with feminine furniture and festive food stations for a summer camp experience like no other.,,Y
|
| 28 |
Midsummer,Celebrate the Swedish Midsummer holiday with a summertime ceremony that is centered around florals. Host a daytime picnic where you and your guests relax in the sun while making flower crowns and wreaths.,,Y
|
| 29 |
Postmodern industrial,Revitalize a worn-down space such as an old factory or abandoned warehouse with a gritty and contemporary spin by using sharp lines and sleek accents. This theme looks to the future of design so have some fun picturing what your postmodern world looks like.,,Y
|
| 30 |
-
Geode,"This glittering gemstone wedding theme really rocks. Incorporate agate place cards, a geode cake design, and other stone accents to achieve this look.",,
|
| 31 |
Pop art,"If you’re looking for a loud wedding theme that always stays relevant, throw a pop art wedding. This style, made famous by artist Andy Warhol, mixes pop culture items with more traditional pieces for a look that’s anything but boring.",,Y
|
| 32 |
Feminine maximalist,More is more with this colorful and loud wedding theme that plays up dramatic displays and quirky touches. Make your maximalism pretty in pink with cascading florals and bright embellishments.,,Y
|
| 33 |
Royal wedding,"Channel the grace of Meghan Markle and the tradition of the British royal family with this romantic wedding theme. Myrtle flowers, London artwork, tiaras, and tea help make this look authentically chic.",,Y
|
|
@@ -71,4 +71,4 @@ Celestial,"If your love burns as bright as the stars in the galaxy, consider a c
|
|
| 71 |
Mountain,"If you’re a morning person and/or lover of the outdoors, how about a hike-themed wedding that has your guests up and active at dawn? Play up the hiking theme after your intimate, mountainside ceremony with a celebratory brunch reception.",,Y
|
| 72 |
Halloween,"If you’re getting married in the fall, take advantage of the spooky season’s deep color pallette and popular accessories such as pumpkins, smoke, and crystal balls.",,Y
|
| 73 |
Murder mystery,"While you have everyone all dressed up, why not throw a murder mystery (and some funky accents) into the mix? Perfect for couples who love games, this wedding theme can be incorporated into the decorations, entertainment, and menu.",,Y
|
| 74 |
-
Game of Thrones,"Winter is coming to your wedding with this theme straight from Winterfell. Let your wedding party get into character with faux fur, tiaras, and thick braids.",,Y
|
|
|
|
| 27 |
Summer glamp,Go glamping for a laid-back camp-themed wedding with a touch of glamour. Elevate a barn or backyard venue with feminine furniture and festive food stations for a summer camp experience like no other.,,Y
|
| 28 |
Midsummer,Celebrate the Swedish Midsummer holiday with a summertime ceremony that is centered around florals. Host a daytime picnic where you and your guests relax in the sun while making flower crowns and wreaths.,,Y
|
| 29 |
Postmodern industrial,Revitalize a worn-down space such as an old factory or abandoned warehouse with a gritty and contemporary spin by using sharp lines and sleek accents. This theme looks to the future of design so have some fun picturing what your postmodern world looks like.,,Y
|
| 30 |
+
Geode,"This glittering gemstone wedding theme really rocks. Incorporate agate place cards, a geode cake design, and other stone accents to achieve this look.",,N
|
| 31 |
Pop art,"If you’re looking for a loud wedding theme that always stays relevant, throw a pop art wedding. This style, made famous by artist Andy Warhol, mixes pop culture items with more traditional pieces for a look that’s anything but boring.",,Y
|
| 32 |
Feminine maximalist,More is more with this colorful and loud wedding theme that plays up dramatic displays and quirky touches. Make your maximalism pretty in pink with cascading florals and bright embellishments.,,Y
|
| 33 |
Royal wedding,"Channel the grace of Meghan Markle and the tradition of the British royal family with this romantic wedding theme. Myrtle flowers, London artwork, tiaras, and tea help make this look authentically chic.",,Y
|
|
|
|
| 71 |
Mountain,"If you’re a morning person and/or lover of the outdoors, how about a hike-themed wedding that has your guests up and active at dawn? Play up the hiking theme after your intimate, mountainside ceremony with a celebratory brunch reception.",,Y
|
| 72 |
Halloween,"If you’re getting married in the fall, take advantage of the spooky season’s deep color pallette and popular accessories such as pumpkins, smoke, and crystal balls.",,Y
|
| 73 |
Murder mystery,"While you have everyone all dressed up, why not throw a murder mystery (and some funky accents) into the mix? Perfect for couples who love games, this wedding theme can be incorporated into the decorations, entertainment, and menu.",,Y
|
| 74 |
+
Game of Thrones,"Winter is coming to your wedding with this theme straight from Winterfell. Let your wedding party get into character with faux fur, tiaras, and thick braids.",,Y
|