simonlee-cb commited on
Commit
38fcee7
·
1 Parent(s): a9fb110

fix: image rotation

Browse files
Files changed (1) hide show
  1. app.py +25 -7
app.py CHANGED
@@ -1,4 +1,6 @@
1
  import streamlit as st
 
 
2
  import requests
3
 
4
  API_URL = 'https://pic-gai.up.railway.app'
@@ -24,8 +26,9 @@ user_prompt = st.text_area(
24
 
25
  uploaded_images = st.file_uploader("Choose photos", accept_multiple_files=True)
26
  if uploaded_images:
27
- st.subheader('Uploaded photos:')
28
- gallery(4, uploaded_images)
 
29
 
30
  # pick number of photos
31
  photos_count = len(uploaded_images)
@@ -44,7 +47,8 @@ if generate_button:
44
  # remove empty params
45
  params = {k: v for k, v in params.items() if v is not None}
46
 
47
- print(params)
 
48
  # Templates
49
  with st.container():
50
  # Define the FastAPI server URL for templates
@@ -60,8 +64,7 @@ if generate_button:
60
  image_urls = [template.get('image_medium') for template in templates]
61
 
62
  if image_urls:
63
- st.markdown("---")
64
- st.subheader('Generated templates:')
65
  gallery(4, image_urls[:8])
66
  else:
67
  st.warning('No images were generated. Please try again with a different prompt.')
@@ -82,12 +85,27 @@ if generate_button:
82
  image_urls = [sticker.get('image_url') for sticker in stickers]
83
 
84
  if image_urls:
85
- st.markdown("---")
86
- st.subheader('Generated stickers:')
87
  gallery(4, image_urls[:8])
88
  else:
89
  st.warning('No images were generated. Please try again with a different prompt.')
90
  else:
91
  st.error(f"Error: {response.status_code}")
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
92
  else:
93
  st.warning('Please enter a prompt before submitting.')
 
1
  import streamlit as st
2
+ from PIL import Image, ImageOps
3
+
4
  import requests
5
 
6
  API_URL = 'https://pic-gai.up.railway.app'
 
26
 
27
  uploaded_images = st.file_uploader("Choose photos", accept_multiple_files=True)
28
  if uploaded_images:
29
+ images = [Image.open(image) for image in uploaded_images]
30
+ images = [ImageOps.exif_transpose(image) for image in images]
31
+ gallery(4, images)
32
 
33
  # pick number of photos
34
  photos_count = len(uploaded_images)
 
47
  # remove empty params
48
  params = {k: v for k, v in params.items() if v is not None}
49
 
50
+ st.markdown("---")
51
+
52
  # Templates
53
  with st.container():
54
  # Define the FastAPI server URL for templates
 
64
  image_urls = [template.get('image_medium') for template in templates]
65
 
66
  if image_urls:
67
+ st.subheader('Generated templates')
 
68
  gallery(4, image_urls[:8])
69
  else:
70
  st.warning('No images were generated. Please try again with a different prompt.')
 
85
  image_urls = [sticker.get('image_url') for sticker in stickers]
86
 
87
  if image_urls:
88
+ st.subheader('Generated stickers')
 
89
  gallery(4, image_urls[:8])
90
  else:
91
  st.warning('No images were generated. Please try again with a different prompt.')
92
  else:
93
  st.error(f"Error: {response.status_code}")
94
+
95
+ # Keywords
96
+ with st.container():
97
+ # Define the FastAPI server URL for keywords
98
+ url = f"{API_URL}/api/analyze_prompt"
99
+
100
+ # Make a request to the FastAPI server
101
+ response = requests.get(url, params=params)
102
+
103
+ # Display the response in the appropriate output container
104
+ if response.status_code == 200:
105
+ st.subheader('Keywords based on prompt')
106
+ keywords = response.json().get('keywords', [])
107
+ st.write(keywords)
108
+ else:
109
+ st.error(f"Error: {response.status_code}")
110
  else:
111
  st.warning('Please enter a prompt before submitting.')