simonlee-cb commited on
Commit
40047db
·
1 Parent(s): d792706

ready for demo

Browse files
Files changed (1) hide show
  1. app.py +73 -35
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('Design Generator UI')
8
 
9
  # Input field for user prompt
10
- user_prompt = st.text_input('Enter a prompt describing the scenario:')
 
 
 
 
 
 
 
 
 
 
11
 
12
  # Submit buttons for templates and stickers
13
- st.write('Select an action:')
14
- generate_templates_button = st.button('Generate Templates')
15
- generate_stickers_button = st.button('Generate Stickers')
 
 
 
16
 
17
- # Containers for templates and stickers
18
- templates_container = st.container()
19
- stickers_container = st.container()
 
20
 
21
- if generate_templates_button or generate_stickers_button:
22
  if user_prompt:
23
- if generate_templates_button:
 
 
 
 
 
 
 
 
 
 
 
24
  # Define the FastAPI server URL for templates
25
  url = f"{API_URL}/api/templates"
26
 
27
- if generate_stickers_button:
28
- # Define the FastAPI server URL for stickers
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
29
  url = f"{API_URL}/api/stickers"
30
 
31
- # Prepare the payload with the user prompt
32
- payload = {'user_prompt': user_prompt}
33
-
34
- # Make a request to the FastAPI server
35
- response = requests.get(url, json=payload)
36
-
37
- # Display the response in the appropriate output container
38
- if response.status_code == 200:
39
- result = response.json()
40
- image_urls = result.get('generated_images', [])
41
-
42
- if image_urls:
43
- output_text = 'Generated templates:' if generate_templates_button else 'Generated stickers:'
44
- output_container = templates_container if generate_templates_button else stickers_container
45
- output_container.write(output_text)
46
-
47
- for image_url in image_urls:
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.')