-
Notifications
You must be signed in to change notification settings - Fork 0
/
app.py
123 lines (76 loc) · 5.15 KB
/
app.py
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
import streamlit as st
from helper import update_secondary_col, ConvertPdfToX, ConvertImageToPdf, ConvertImageToImage, Resizer
from io import BytesIO
from helper import video_to_video
st.set_page_config(
page_title="Crypto Twitter Analysis Web App",
page_icon="🧊",
layout="wide",
initial_sidebar_state="expanded",
menu_items={
'Get Help': 'https://github.com/everydaycodings',
'About': "Flexidocs is a web app that allows you to convert images from one format to another and resize your images using various options such as dimensions, percentage, and image size. #### Github Code: (Click HERE)[https://github.com/everydaycodings/FlexiDocs]"
}
)
imagetopdf = ["jpg", "png", "jpeg"]
imagetoimage_primary = ["jpg", "png", "jpeg"]
imagetoimage_secondry = ["jpg", "png", "jpeg"]
video_format = ["mp4", "mov", "mkv", "gif"]
st.header("Welcome To FlexiDocs")
worker_option = st.selectbox("Selet the Option: ", options=["Resizer", "Convertor"])
if worker_option == "Resizer":
st.subheader("Resize your Image as your wish")
resizer_option = st.selectbox("Select your Prefered Resizer: ", options=["Percentage", "Dimensions", "Image Size"])
uploaded_files = st.file_uploader("Choose a file")
if uploaded_files is not None:
if resizer_option == "Percentage":
percenatge_value = st.number_input("Enter the Percentage you want to reduce to: ", min_value=1, max_value=100, step=1, value=70)
height, width = Resizer().percentage_resize_details(uploaded_file=uploaded_files, percentage_value=percenatge_value)
st.warning("You want to set the new size to be {}% of the original size which is {}*{}".format(percenatge_value, width, height))
if st.button("Resize The Image"):
Resizer().percentage_resizing(percentage_value=percenatge_value, uploaded_file=uploaded_files)
elif resizer_option == "Dimensions":
img_width, img_height = Resizer().image_dimensions(uploaded_files)
height = st.number_input("Enter the new Height of the image: ", min_value=1, max_value=img_height, step=1, value=int(img_height*50/100))
width = st.number_input("Enter the new Width of the image: ", min_value=1, max_value=img_width, step=1, value=int(img_width*50/100))
if st.button("Resize The Image"):
Resizer().dimension_resizing(height=height, width=width, uploaded_file=uploaded_files)
elif resizer_option == "Image Size":
col1, col2 = st.columns(2)
with col1:
image_size = st.number_input("Enter the size of the image you want to resize to: ", min_value=1, step=1)
with col2:
image_size_format = st.selectbox("Enter the Image size type: ", options=["KB", "MB"])
check = Resizer().image_size_resizing_check(uploaded_file=uploaded_files, image_size=image_size, size_format=image_size_format)
if check:
if st.button("Resize Image"):
Resizer().image_size_resizing(uploaded_file=uploaded_files, image_size=image_size, size_format=image_size_format)
elif worker_option == "Convertor":
st.subheader("Convert your files from one format to another: ")
col1, col2 = st.columns(2)
with col1:
primary_format = st.selectbox("Select the format of your file: ", options=["jpg", "jpeg", "png", "pdf", "mp4", "mov", "mkv", "gif"])
with col2:
secondary_format = st.selectbox("Select the format you want to convert your file: ", options=update_secondary_col(primary_col=primary_format))
if primary_format == "pdf":
uploaded_files = st.file_uploader("Choose a file")
elif primary_format in imagetopdf and secondary_format in ["pdf"]:
uploaded_files = st.file_uploader("Choose a file", accept_multiple_files=True)
elif primary_format in imagetoimage_primary and secondary_format in imagetoimage_secondry:
uploaded_files = st.file_uploader("Choose a file")
elif primary_format in video_format and secondary_format in video_format:
uploaded_files = st.file_uploader("Choose a file", accept_multiple_files=True)
submitted = st.button("Convert")
if submitted:
if uploaded_files is not None:
if primary_format == "pdf":
with st.spinner("Converting..."):
pdf_bytes = BytesIO(uploaded_files.read()).getvalue()
file_name = str(uploaded_files.name).split(".")[0]
ConvertPdfToX().convert(secondary_format=secondary_format, pdf_bytes=pdf_bytes, pdf_filename=file_name)
elif primary_format in imagetopdf and secondary_format in ["pdf"]:
ConvertImageToPdf().convert(uploaded_files=uploaded_files)
elif primary_format in imagetoimage_primary and secondary_format in imagetoimage_secondry:
ConvertImageToImage().convert(secondary_format, uploaded_files)
elif primary_format in video_format and secondary_format in video_format:
video_to_video(uploaded_files, secondary_format)