Spaces:
Runtime error
Runtime error
Commit
·
1c74bd7
1
Parent(s):
6f710fc
feat: use captions for sticker/template suggestion
Browse files- app.py +22 -16
- internal/__pycache__/__init__.cpython-311.pyc +0 -0
- internal/__pycache__/api.cpython-311.pyc +0 -0
- internal/api.py +6 -8
app.py
CHANGED
@@ -3,6 +3,7 @@ from PIL import Image, ImageOps
|
|
3 |
from internal.api import APIClient
|
4 |
|
5 |
client = APIClient("https://collage-ai.onrender.com")
|
|
|
6 |
|
7 |
def gallery(column, images):
|
8 |
groups = []
|
@@ -18,12 +19,16 @@ st.title('CollageAI')
|
|
18 |
|
19 |
user_images = None
|
20 |
user_prompt = None
|
21 |
-
uploaded_images =
|
22 |
-
|
|
|
23 |
submitted = False
|
24 |
|
25 |
with st.form("user_input_form"):
|
26 |
-
user_images = st.file_uploader(
|
|
|
|
|
|
|
27 |
user_prompt = st.text_area(
|
28 |
"Describe the design you'd like to create:",
|
29 |
placeholder="For our anniversary, I want to write a card to my partner to celebrate our love and share all the things I adore about them."
|
@@ -69,11 +74,24 @@ if submitted:
|
|
69 |
except Exception as e:
|
70 |
st.error(f"Error analyzing prompt: {e}")
|
71 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
72 |
# Templates
|
73 |
with st.container():
|
74 |
with st.spinner('Generating templates...'):
|
75 |
try:
|
76 |
-
template_image_urls = client.suggest_templates(user_prompt,
|
77 |
if template_image_urls:
|
78 |
st.subheader('Template suggestions')
|
79 |
gallery(4, template_image_urls[:8])
|
@@ -82,17 +100,5 @@ if submitted:
|
|
82 |
except Exception as e:
|
83 |
st.error(f"Error generating templates: {e}")
|
84 |
|
85 |
-
# Stickers
|
86 |
-
with st.container():
|
87 |
-
with st.spinner('Generating stickers...'):
|
88 |
-
try:
|
89 |
-
sticker_image_urls = client.suggest_stickers(user_prompt, uploaded_images)
|
90 |
-
if sticker_image_urls:
|
91 |
-
st.subheader('Stickers suggestions')
|
92 |
-
gallery(4, sticker_image_urls[:8])
|
93 |
-
else:
|
94 |
-
st.warning('No images were generated. Please try again with a different prompt.')
|
95 |
-
except Exception as e:
|
96 |
-
st.error(f"Error generating stickers: {e}")
|
97 |
else:
|
98 |
st.warning('Please enter a prompt before submitting.')
|
|
|
3 |
from internal.api import APIClient
|
4 |
|
5 |
client = APIClient("https://collage-ai.onrender.com")
|
6 |
+
# client = APIClient("http://localhost:3000")
|
7 |
|
8 |
def gallery(column, images):
|
9 |
groups = []
|
|
|
19 |
|
20 |
user_images = None
|
21 |
user_prompt = None
|
22 |
+
uploaded_images = None
|
23 |
+
captions = []
|
24 |
+
keywords = []
|
25 |
submitted = False
|
26 |
|
27 |
with st.form("user_input_form"):
|
28 |
+
user_images = st.file_uploader(
|
29 |
+
"Choose your photos",
|
30 |
+
accept_multiple_files=True
|
31 |
+
)
|
32 |
user_prompt = st.text_area(
|
33 |
"Describe the design you'd like to create:",
|
34 |
placeholder="For our anniversary, I want to write a card to my partner to celebrate our love and share all the things I adore about them."
|
|
|
74 |
except Exception as e:
|
75 |
st.error(f"Error analyzing prompt: {e}")
|
76 |
|
77 |
+
# Stickers
|
78 |
+
with st.container():
|
79 |
+
with st.spinner('Generating stickers...'):
|
80 |
+
try:
|
81 |
+
sticker_image_urls = client.suggest_stickers(user_prompt, captions)
|
82 |
+
if sticker_image_urls:
|
83 |
+
st.subheader('Stickers suggestions')
|
84 |
+
gallery(4, sticker_image_urls[:8])
|
85 |
+
else:
|
86 |
+
st.warning('No images were generated. Please try again with a different prompt.')
|
87 |
+
except Exception as e:
|
88 |
+
st.error(f"Error generating stickers: {e}")
|
89 |
+
|
90 |
# Templates
|
91 |
with st.container():
|
92 |
with st.spinner('Generating templates...'):
|
93 |
try:
|
94 |
+
template_image_urls = client.suggest_templates(user_prompt, captions)
|
95 |
if template_image_urls:
|
96 |
st.subheader('Template suggestions')
|
97 |
gallery(4, template_image_urls[:8])
|
|
|
100 |
except Exception as e:
|
101 |
st.error(f"Error generating templates: {e}")
|
102 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
103 |
else:
|
104 |
st.warning('Please enter a prompt before submitting.')
|
internal/__pycache__/__init__.cpython-311.pyc
CHANGED
Binary files a/internal/__pycache__/__init__.cpython-311.pyc and b/internal/__pycache__/__init__.cpython-311.pyc differ
|
|
internal/__pycache__/api.cpython-311.pyc
CHANGED
Binary files a/internal/__pycache__/api.cpython-311.pyc and b/internal/__pycache__/api.cpython-311.pyc differ
|
|
internal/api.py
CHANGED
@@ -18,20 +18,18 @@ class APIClient():
|
|
18 |
uploaded_images = response.json().get('result', [])
|
19 |
return uploaded_images
|
20 |
|
21 |
-
def suggest_templates(self, prompt,
|
|
|
22 |
url = self.url_with_path("/api/templates")
|
23 |
-
|
24 |
-
|
25 |
-
response = requests.get(url, json={'prompt': prompt, 'image_urls': image_urls})
|
26 |
templates = response.json().get('result', [])
|
27 |
template_image_urls = [template.get('image_medium') for template in templates]
|
28 |
return template_image_urls
|
29 |
|
30 |
-
def suggest_stickers(self, prompt,
|
|
|
31 |
url = self.url_with_path("/api/stickers")
|
32 |
-
|
33 |
-
|
34 |
-
response = requests.get(url, json={'prompt': prompt, 'image_urls': image_urls})
|
35 |
stickers = response.json().get('result', [])
|
36 |
sticker_image_urls = [sticker.get('image_url') for sticker in stickers]
|
37 |
return sticker_image_urls
|
|
|
18 |
uploaded_images = response.json().get('result', [])
|
19 |
return uploaded_images
|
20 |
|
21 |
+
def suggest_templates(self, prompt, captions):
|
22 |
+
print(f"GET /api/templates with prompt: {prompt} and captions: {captions}")
|
23 |
url = self.url_with_path("/api/templates")
|
24 |
+
response = requests.get(url, json={'prompt': prompt, 'captions': captions})
|
|
|
|
|
25 |
templates = response.json().get('result', [])
|
26 |
template_image_urls = [template.get('image_medium') for template in templates]
|
27 |
return template_image_urls
|
28 |
|
29 |
+
def suggest_stickers(self, prompt, captions):
|
30 |
+
print(f"GET /api/stickers with prompt: {prompt} and captions: {captions}")
|
31 |
url = self.url_with_path("/api/stickers")
|
32 |
+
response = requests.get(url, json={'prompt': prompt, 'captions': captions})
|
|
|
|
|
33 |
stickers = response.json().get('result', [])
|
34 |
sticker_image_urls = [sticker.get('image_url') for sticker in stickers]
|
35 |
return sticker_image_urls
|