-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathmain.py
More file actions
224 lines (214 loc) · 15.3 KB
/
main.py
File metadata and controls
224 lines (214 loc) · 15.3 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
import streamlit as st
from cloudinary.uploader import upload
from cloudinary.utils import cloudinary_url
import cloudinary
import random
import string
import requests
cloudinary.config(
cloud_name = st.secrets['cloud_name'],
api_key = st.secrets['api_key'],
api_secret = st.secrets['api_secret'],
secure = True
)
r_id = []
my_upload = None
st.set_page_config(layout="wide", page_title="Expresso")
if "first_time" not in st.session_state:
st.session_state.first_time = False
if not st.session_state.first_time:
st.balloons()
st.session_state.first_time = True
# main page
st.write("<h1 style='text-align: center;'>Expresso</h1>", unsafe_allow_html=True)
st.write("<h3 style='text-align: center;'>All in one tool to Experiment with your images :)</h3>", unsafe_allow_html=True)
st.write("Choose Input Method:")
input_method = st.selectbox('Select an input method:', ('Select an option', 'Upload An Image', 'Take Input From Camera'))
if input_method is not None:
if input_method == 'Upload An Image':
my_upload = st.file_uploader("Upload an image", type=["png", "jpg", "jpeg"])
elif input_method == 'Take Input From Camera':
my_upload = st.camera_input("Take a picture")
if my_upload is not None:
operations = st.selectbox('Select an operation to try:', ('Select an option', 'Resize Operations', 'Effects', 'Layer Effects', 'Enhancing Tools'))
if operations is not None:
if operations == 'Resize Operations':
sub_operations = st.selectbox('What opreation would you like to perform from Resize Opreations available:', ('Select an operation', 'Scale', 'Limit Fit', 'Fill', 'Fit', 'Crop', 'Minimum Fit'))
if sub_operations is not None:
if sub_operations == 'Scale':
st.info("Resize the asset exactly to the specified width and height. All the orginal asset parts are visible, but might be streched or shrunk if the dimension you request have a different aspect ratio than the original.")
col1, col2 = st.columns(2)
with col1:
width = st.number_input("Width", min_value=1, max_value=1000, value=100)
with col2:
height = st.number_input("Height", min_value=1, max_value=1000, value=100)
r = ''.join(random.choices(string.ascii_letters + string.digits, k=6))
while r in r_id:
r = ''.join(random.choices(string.ascii_letters + string.digits, k=6))
r_id.append(r)
image = upload(my_upload, public_id=f"test_{r}", width=width, height=height, crop="scale")
st.write("<h3>Output Image:</h3>", unsafe_allow_html=True)
response = requests.get(image['url'])
img_data = response.content
st.download_button(label="Download Image", data=img_data, file_name="image.jpg", mime="image/jpg")
st.image(image['url'])
elif sub_operations == 'Limit Fit':
st.info("Same as the fit mode but only if the original asset is larger than the specified limit(width and height), in which case the asset is scaled down so that it takes up as much space as possible within a bounding box defined by the specified width and height parameters. The original aspect ratio is retained(by default) and all of the original asset is visible. This mode doesn't scale up the asset if your requested dimension are larger than the original image size.")
col1, col2 = st.columns(2)
with col1:
width = st.number_input("Width", min_value=1, max_value=1000, value=100)
with col2:
height = st.number_input("Height", min_value=1, max_value=1000, value=100)
r = ''.join(random.choices(string.ascii_letters + string.digits, k=6))
while r in r_id:
r = ''.join(random.choices(string.ascii_letters + string.digits, k=6))
r_id.append(r)
image = upload(my_upload, public_id=f"test_{r}", width=width, height=height, crop="limit")
st.write("<h3>Output Image:</h3>", unsafe_allow_html=True)
response = requests.get(image['url'])
img_data = response.content
st.download_button(label="Download Image", data=img_data, file_name="image.jpg", mime="image/jpg")
st.image(image['url'])
elif sub_operations == 'Fill':
st.info("Creates an asset with exact specified width and height without distorting the asset.")
col1, col2 = st.columns(2)
with col1:
width = st.number_input("Width", min_value=1, max_value=1000, value=100)
with col2:
height = st.number_input("Height", min_value=1, max_value=1000, value=100)
r = ''.join(random.choices(string.ascii_letters + string.digits, k=6))
while r in r_id:
r = ''.join(random.choices(string.ascii_letters + string.digits, k=6))
r_id.append(r)
image = upload(my_upload, public_id=f"test_{r}", width=width, height=height, crop="fill")
st.write("<h3>Output Image:</h3>", unsafe_allow_html=True)
response = requests.get(image['url'])
img_data = response.content
st.download_button(label="Download Image", data=img_data, file_name="image.jpg", mime="image/jpg")
st.image(image['url'])
elif sub_operations == 'Fit':
st.info("Scales the asset up or down so that it takes up as much space as possible")
col1, col2 = st.columns(2)
with col1:
width = st.number_input("Width", min_value=1, max_value=1000, value=100)
with col2:
height = st.number_input("Height", min_value=1, max_value=1000, value=100)
r = ''.join(random.choices(string.ascii_letters + string.digits, k=6))
while r in r_id:
r = ''.join(random.choices(string.ascii_letters + string.digits, k=6))
r_id.append(r)
image = upload(my_upload, public_id=f"test_{r}", width=width, height=height, crop="fit")
st.write("<h3>Output Image:</h3>", unsafe_allow_html=True)
response = requests.get(image['url'])
img_data = response.content
st.download_button(label="Download Image", data=img_data, file_name="image.jpg", mime="image/jpg")
st.image(image['url'])
elif sub_operations == 'Crop':
st.info("Extracts the specified size from the original image without distorting or scaling the delivered asset.")
col1, col2 = st.columns(2)
with col1:
width = st.number_input("Width", min_value=1, max_value=1000, value=100)
direction = st.selectbox("Select Direction:", ("Center", "North", "South", "East", "West", "North West", "North East", "South East", "South West"))
dict = {"Center": "center", "North":"north", "South": "south", "East": "east", "West": "west", "North West": "north_west", "South West": "south_west", "North East": "north_east", "SouthEast": "south_east"}
with col2:
height = st.number_input("Height", min_value=1, max_value=1000, value=100)
r = ''.join(random.choices(string.ascii_letters + string.digits, k=6))
while r in r_id:
r = ''.join(random.choices(string.ascii_letters + string.digits, k=6))
r_id.append(r)
image = upload(my_upload, public_id=f"test_{r}", width=width, height=height, crop="crop", gravity=dict[direction])
st.write("<h3>Output Image:</h3>", unsafe_allow_html=True)
response = requests.get(image['url'])
img_data = response.content
st.download_button(label="Download Image", data=img_data, file_name="image.jpg", mime="image/jpg")
st.image(image['url'])
elif sub_operations == 'Minimum Fit':
st.info("The minimum fit mode is the same as the fit mode but only if the original image is smaller than than the specified minimum(width and height), in which case the image is scaled up so that it takes up as much space as possible within a bounding box defined by the specified width and height parameters. The original aspect ratio is retained by default and all of the original image is visible. This mode doesn't scale down the image if your requested dimensions are smaller thant the original image's.")
col1, col2 = st.columns(2)
with col1:
width = st.number_input("Width", min_value=1, max_value=1000, value=100)
with col2:
height = st.number_input("Height", min_value=1, max_value=1000, value=100)
r = ''.join(random.choices(string.ascii_letters + string.digits, k=6))
while r in r_id:
r = ''.join(random.choices(string.ascii_letters + string.digits, k=6))
r_id.append(r)
image = upload(my_upload, public_id=f"test_{r}", width=width, height=height, crop="mfit")
st.write("<h3>Output Image:</h3>", unsafe_allow_html=True)
response = requests.get(image['url'])
img_data = response.content
st.download_button(label="Download Image", data=img_data, file_name="image.jpg", mime="image/jpg")
st.image(image['url'])
elif operations == 'Effects':
sub_operations = st.selectbox("What opreation would you like to perform from Effects available:", ('Select an Effect', 'Blur Face', 'Pixelate Portion', 'Convert to Grayscale'))
if sub_operations is not None:
if sub_operations == 'Blur Face':
r = ''.join(random.choices(string.ascii_letters + string.digits, k=6))
while r in r_id:
r = ''.join(random.choices(string.ascii_letters + string.digits, k=6))
r_id.append(r)
image = upload(my_upload, public_id=f"test_{r}", effect="blur_faces:2000")
st.write("<h3>Output Image:</h3>", unsafe_allow_html=True)
response = requests.get(image['url'])
img_data = response.content
st.download_button(label="Download Image", data=img_data, file_name="image.jpg", mime="image/jpg")
st.image(image['url'])
elif sub_operations == 'Pixelate Portion':
col1, col2 = st.columns(2)
with col1:
width = st.number_input("Width", min_value=1, max_value=1000, value=100)
x = st.number_input("X", min_value=1, max_value=1000, value=100)
with col2:
height = st.number_input("Height", min_value=1, max_value=1000, value=100)
y = st.number_input("Y", min_value=1, max_value=1000, value=100)
r = ''.join(random.choices(string.ascii_letters + string.digits, k=6))
while r in r_id:
r = ''.join(random.choices(string.ascii_letters + string.digits, k=6))
r_id.append(r)
image = upload(my_upload, public_id=f"test_{r}", width=width, height=height, x=x, y=y, crop="fill", effect="pixelate_region")
st.write("<h3>Output Image:</h3>", unsafe_allow_html=True)
response = requests.get(image['url'])
img_data = response.content
st.download_button(label="Download Image", data=img_data, file_name="image.jpg", mime="image/jpg")
st.image(image['url'])
elif sub_operations == 'Convert to Grayscale':
r = ''.join(random.choices(string.ascii_letters + string.digits, k=6))
while r in r_id:
r = ''.join(random.choices(string.ascii_letters + string.digits, k=6))
r_id.append(r)
image = upload(my_upload, public_id=f"test_{r}", effect="grayscale")
st.write("<h3>Output Image:</h3>", unsafe_allow_html=True)
response = requests.get(image['url'])
img_data = response.content
st.download_button(label="Download Image", data=img_data, file_name="image.jpg", mime="image/jpg")
st.image(image['url'])
elif operations == 'Layer Effects':
sub_operations = st.selectbox("What opreation would you like to perform from Layers Effects available:", ('Select an Effect', 'Text Layer'))
if sub_operations is not None:
if sub_operations == 'Text Layer':
col1, col2 = st.columns(2)
with col1:
font_family = st.selectbox('Select Font Family:', ("Arial", "Georgia", "Roboto", "Times New Roman", "Helvetica", "Open Sans", "Verdana", "Trebuchet Ms", "Courier New"))
font_size = st.number_input("Font Size", min_value=1, max_value=1000, value=100)
color_code = st.color_picker('Pick Font Color', '#000000')
st.write('The current color is', color_code)
with col2:
position = st.selectbox("Placement Position", ("Center", "North", "South", "East", "West", "North West", "North East", "South East", "South West"))
dict = {"Center": "center", "North":"north", "South": "south", "East": "east", "West": "west", "North West": "north_west", "South West": "south_west", "North East": "north_east", "SouthEast": "south_east"}
text = st.text_input("Text", "Hello World")
r = ''.join(random.choices(string.ascii_letters + string.digits, k=6))
while r in r_id:
r = ''.join(random.choices(string.ascii_letters + string.digits, k=6))
r_id.append(r)
image = upload(my_upload, public_id=f"test_{r}", color=color_code, overlay={"font_family":font_family, "font_size":font_size, "text":text}, gravity=dict[position])
st.write("<h3>Output Image:</h3>", unsafe_allow_html=True)
response = requests.get(image['url'])
img_data = response.content
st.download_button(label="Download Image", data=img_data, file_name="image.jpg", mime="image/jpg")
st.image(image['url'])
elif operations == "Enhancing Tools":
sub_operations = st.selectbox('What Enchancing opreation would you like to perform from Resize Opreations available:', ('Select an operation', 'Improve', 'Limit Fit', 'Fill', 'Fit', 'Crop', 'Minimum Fit'))
else:
pass
else:
pass