Spaces:
Runtime error
Runtime error
Commit
·
40047db
1
Parent(s):
d792706
ready for demo
Browse files
app.py
CHANGED
@@ -2,53 +2,91 @@ import streamlit as st
|
|
2 |
import requests
|
3 |
|
4 |
API_URL = 'https://pic-gai.up.railway.app'
|
5 |
-
API_URL = 'http://localhost:8000'
|
6 |
|
7 |
-
st.title('
|
8 |
|
9 |
# Input field for user prompt
|
10 |
-
user_prompt = st.
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
11 |
|
12 |
# Submit buttons for templates and stickers
|
13 |
-
st.
|
14 |
-
|
15 |
-
|
|
|
|
|
|
|
16 |
|
17 |
-
|
18 |
-
|
19 |
-
|
|
|
20 |
|
21 |
-
if
|
22 |
if user_prompt:
|
23 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
24 |
# Define the FastAPI server URL for templates
|
25 |
url = f"{API_URL}/api/templates"
|
26 |
|
27 |
-
|
28 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
29 |
url = f"{API_URL}/api/stickers"
|
30 |
|
31 |
-
|
32 |
-
|
33 |
-
|
34 |
-
|
35 |
-
|
36 |
-
|
37 |
-
|
38 |
-
|
39 |
-
|
40 |
-
|
41 |
-
|
42 |
-
|
43 |
-
|
44 |
-
|
45 |
-
|
46 |
-
|
47 |
-
|
48 |
-
output_container.image(image_url)
|
49 |
-
else:
|
50 |
-
st.warning('No images were generated. Please try again with a different prompt.')
|
51 |
-
else:
|
52 |
-
st.error(f"Error: {response.status_code}")
|
53 |
else:
|
54 |
st.warning('Please enter a prompt before submitting.')
|
|
|
2 |
import requests
|
3 |
|
4 |
API_URL = 'https://pic-gai.up.railway.app'
|
5 |
+
# API_URL = 'http://localhost:8000'
|
6 |
|
7 |
+
st.title('CollageAI')
|
8 |
|
9 |
# Input field for user prompt
|
10 |
+
user_prompt = st.text_area(
|
11 |
+
"Describe the design you'd like to create:",
|
12 |
+
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."
|
13 |
+
)
|
14 |
+
|
15 |
+
# pick number of photos
|
16 |
+
photos_count = st.number_input(
|
17 |
+
'How many photos would you like to use?',
|
18 |
+
min_value=0,
|
19 |
+
max_value=10,
|
20 |
+
)
|
21 |
|
22 |
# Submit buttons for templates and stickers
|
23 |
+
generate_button = st.button('Generate')
|
24 |
+
|
25 |
+
def gallery(column, images):
|
26 |
+
groups = []
|
27 |
+
for i in range(0, len(images), column):
|
28 |
+
groups.append(images[i:i+column])
|
29 |
|
30 |
+
for group in groups:
|
31 |
+
cols = st.columns(column)
|
32 |
+
for i, image in enumerate(group):
|
33 |
+
cols[i].image(image)
|
34 |
|
35 |
+
if generate_button:
|
36 |
if user_prompt:
|
37 |
+
# Prepare the params with the user prompt
|
38 |
+
params = {
|
39 |
+
'prompt': user_prompt,
|
40 |
+
'photos_count': photos_count
|
41 |
+
}
|
42 |
+
|
43 |
+
# remove empty params
|
44 |
+
params = {k: v for k, v in params.items() if v is not None}
|
45 |
+
|
46 |
+
print(params)
|
47 |
+
# Templates
|
48 |
+
with st.container():
|
49 |
# Define the FastAPI server URL for templates
|
50 |
url = f"{API_URL}/api/templates"
|
51 |
|
52 |
+
with st.spinner('Generating templates...'):
|
53 |
+
# Make a request to the FastAPI server
|
54 |
+
response = requests.get(url, params=params)
|
55 |
+
|
56 |
+
# Display the response in the appropriate output container
|
57 |
+
if response.status_code == 200:
|
58 |
+
templates = response.json().get('result', [])
|
59 |
+
image_urls = [template.get('image_medium') for template in templates]
|
60 |
+
|
61 |
+
if image_urls:
|
62 |
+
st.divider()
|
63 |
+
st.subheader('Generated templates:')
|
64 |
+
gallery(4, image_urls[:8])
|
65 |
+
else:
|
66 |
+
st.warning('No images were generated. Please try again with a different prompt.')
|
67 |
+
else:
|
68 |
+
st.error(f"Error: {response.status_code}")
|
69 |
+
|
70 |
+
with st.container():
|
71 |
+
# Define the FastAPI server URL for templates
|
72 |
url = f"{API_URL}/api/stickers"
|
73 |
|
74 |
+
with st.spinner('Generating stickers...'):
|
75 |
+
# Make a request to the FastAPI server
|
76 |
+
response = requests.get(url, params=params)
|
77 |
+
|
78 |
+
# Display the response in the appropriate output container
|
79 |
+
if response.status_code == 200:
|
80 |
+
stickers = response.json().get('result', [])
|
81 |
+
image_urls = [sticker.get('image_url') for sticker in stickers]
|
82 |
+
|
83 |
+
if image_urls:
|
84 |
+
st.divider()
|
85 |
+
st.subheader('Generated stickers:')
|
86 |
+
gallery(4, image_urls[:8])
|
87 |
+
else:
|
88 |
+
st.warning('No images were generated. Please try again with a different prompt.')
|
89 |
+
else:
|
90 |
+
st.error(f"Error: {response.status_code}")
|
|
|
|
|
|
|
|
|
|
|
91 |
else:
|
92 |
st.warning('Please enter a prompt before submitting.')
|