muhammadzain commited on
Commit
9e86fac
1 Parent(s): 735281f

try with git lfs

Browse files
Files changed (6) hide show
  1. .gitattributes +1 -0
  2. main.py +186 -0
  3. models/ESPCN_x2.pb +3 -0
  4. models/ESPCN_x3.pb +3 -0
  5. models/ESPCN_x4.pb +3 -0
  6. requirements.txt +189 -0
.gitattributes CHANGED
@@ -32,3 +32,4 @@ saved_model/**/* filter=lfs diff=lfs merge=lfs -text
32
  *.zip filter=lfs diff=lfs merge=lfs -text
33
  *.zst filter=lfs diff=lfs merge=lfs -text
34
  *tfevents* filter=lfs diff=lfs merge=lfs -text
 
 
32
  *.zip filter=lfs diff=lfs merge=lfs -text
33
  *.zst filter=lfs diff=lfs merge=lfs -text
34
  *tfevents* filter=lfs diff=lfs merge=lfs -text
35
+ models/*.pb filter=lfs diff=lfs merge=lfs -text
main.py ADDED
@@ -0,0 +1,186 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import math
2
+ import time
3
+ import numpy as np
4
+ import streamlit as st
5
+ from PIL import Image
6
+ import cv2
7
+
8
+ hide_streamlit_style = """
9
+ <style>
10
+ #root > div:nth-child(1) > div > div > div > div > section > div {padding-top: 0rem;
11
+ padding-left: 1%;
12
+ }
13
+ </style>
14
+
15
+ """
16
+
17
+ st.set_page_config(layout="wide")
18
+
19
+
20
+
21
+ @st.cache_resource(show_spinner=False)
22
+ def loadModel(n):
23
+ super_res = cv2.dnn_superres.DnnSuperResImpl_create()
24
+ super_res.readModel('models/ESPCN_x'+n+'.pb')
25
+ return super_res
26
+
27
+ # on removing (show_spinner=False), it will show that fuction is running on web app
28
+ @st.cache_data(show_spinner=False)
29
+ def upscale(file,task):
30
+ with open(file.name, "wb") as f:
31
+ f.write(file.getbuffer())
32
+ print('No file found, so added in list files')
33
+ if isinstance(task,str):
34
+ super_res = loadModel(task)
35
+ super_res.setModel('espcn', int(task))
36
+ if file.type.split('/')[0] == 'image':
37
+ img = cv2.imread(file.name)
38
+ upscaled_image = super_res.upsample(img)
39
+ print('I upscaled upto',task,'times')
40
+ cv2.imwrite("processed_"+file.name,upscaled_image)
41
+ return True
42
+ else:
43
+ req_width,req_height = int(task[0]),int(task[1])
44
+ if file.type.split('/')[0] == 'image':
45
+ img = cv2.imread(file.name)
46
+ actual_width,actual_height = img.shape[1],img.shape[0]
47
+ w_ratio,h_ratio = req_width/actual_width , req_height/actual_height
48
+ if min([w_ratio,h_ratio]) <= 1.0:
49
+ img = cv2.resize(img,(req_width,req_height))
50
+ print("I did resizing only!")
51
+ cv2.imwrite("processed_" + file.name, img)
52
+ return True
53
+ # rounding off the ratios
54
+ w_ratio,h_ratio = math.ceil(w_ratio),math.ceil(h_ratio)
55
+ # find bigger number
56
+ upscale_number = max(w_ratio,h_ratio)
57
+
58
+ # task can be greater than 4 but we can upscale upto 4. So setting task to 4.
59
+ if upscale_number >= 4:
60
+ upscale_number = 4
61
+
62
+ super_res = loadModel(str(upscale_number))
63
+ super_res.setModel('espcn', int(upscale_number))
64
+ upscaled_image = super_res.upsample(img)
65
+ print("Before resizing ",(upscaled_image.shape[1], upscaled_image.shape[0]))
66
+ upscaled_image = cv2.resize(upscaled_image,(task[0],task[1]))
67
+ print("Final size got: ",(upscaled_image.shape[1],upscaled_image.shape[0]))
68
+
69
+ print("I upscale upto", upscale_number , "times and then resize it.")
70
+
71
+ cv2.imwrite("processed_" + file.name, upscaled_image)
72
+
73
+ return True
74
+
75
+ return "It's second"
76
+
77
+
78
+ if 'disable_opt2' not in st.session_state:
79
+ st.session_state.disable_opt2 = True
80
+ if 'disable_opt1' not in st.session_state:
81
+ st.session_state.disable_opt1 = False
82
+ if 'disable_download' not in st.session_state:
83
+ st.session_state.disable_download = True
84
+
85
+
86
+ st.markdown(hide_streamlit_style, unsafe_allow_html=True)
87
+
88
+ col1,_,col2 = st.columns([6,1,3],gap="small")
89
+
90
+ def toggle_state_opt1():
91
+
92
+ if st.session_state.get("opt1") == True:
93
+ st.session_state.opt2 = False
94
+ st.session_state.disable_opt2 = True
95
+
96
+ else:
97
+ st.session_state.opt2 = True
98
+ st.session_state.disable_opt2 = False
99
+
100
+ def toggle_state_opt2():
101
+ if st.session_state.get("opt2") == True:
102
+ st.session_state.opt1 = False
103
+ st.session_state.disable_opt1 = True
104
+ else:
105
+ st.session_state.opt1 = True
106
+ st.session_state.disable_opt1 = False
107
+
108
+ # Update the states based on user selection before drawing the widgets in the web page
109
+ toggle_state_opt2()
110
+ toggle_state_opt1()
111
+
112
+ with col1:
113
+ file = st.file_uploader("",type=['png','jpeg','jpg','pgm','jpe'])
114
+ if file is not None:
115
+ # writing file and saving its details in dict for further processing
116
+
117
+
118
+
119
+ if file.type.split('/')[0] == "image":
120
+ image = Image.open(file)
121
+ st.image(image,caption="Upload Image", use_column_width=True)
122
+ elif file.type.split('/')[0] == 'video':
123
+ st.video(file)
124
+
125
+
126
+ with col2:
127
+ st.markdown("\n")
128
+ st.markdown("\n")
129
+ st.markdown("\n")
130
+
131
+ st.subheader(" UPSCALE RESOLUTION UP TO")
132
+ st.markdown("\n")
133
+ st.markdown("\n")
134
+
135
+ opt1 = st.checkbox("MULTIPLES OF",key="opt1",value=True,on_change=toggle_state_opt1)
136
+ st.selectbox("SELECT", ["2", "3", "4"],key="opt1_selBox",disabled=st.session_state.disable_opt1)
137
+
138
+ st.markdown("\n")
139
+ st.markdown("\n")
140
+ opt2 = st.checkbox("CUSTOM SIZE",key="opt2",on_change=toggle_state_opt2)
141
+
142
+ subCol3, subCol4 = st.columns(2)
143
+
144
+ with subCol3:
145
+ st.number_input("Width", step=1, min_value=150,max_value=3840, value=900, key="width",disabled=st.session_state.disable_opt2)
146
+
147
+ with subCol4:
148
+ st.number_input("Height", step=1, min_value=150,max_value=2160, value=900, key="height",disabled=st.session_state.disable_opt2)
149
+
150
+ st.markdown("\n")
151
+ st.markdown("\n")
152
+
153
+ _, dcol, _ = st.columns([1,5,1],gap="small")
154
+
155
+ with dcol:
156
+
157
+ if st.button("PROCEED",use_container_width=True) and file is not None:
158
+ if st.session_state.get('opt1') == True:
159
+ task = st.session_state.opt1_selBox
160
+ else:
161
+ task = [st.session_state.width, st.session_state.height]
162
+ print(task)
163
+ st.session_state.disable_download = not upscale(file,task)
164
+
165
+
166
+ #print(resulted_file.shape)
167
+
168
+ st.markdown("\n")
169
+ st.markdown("\n")
170
+
171
+ if file is None:
172
+ st.session_state.disable_download = True
173
+
174
+ if st.session_state.disable_download == True:
175
+ st.button("DOWNLOAD FILE",disabled=True,use_container_width=True)
176
+ else:
177
+ with open('processed_'+file.name, "rb") as download_file:
178
+ st.download_button(label="Download image", data=download_file,
179
+ file_name= 'processed_'+file.name, mime= "image/png",
180
+ use_container_width=True, disabled=st.session_state.disable_download)
181
+
182
+
183
+
184
+ st.markdown("\n")
185
+ st.markdown("\n")
186
+ st.info("DESCRIPTION : This web app is a free tool that allow user to upscale or resize media file resolution.")
models/ESPCN_x2.pb ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:59f77351e1d7c0057bf6fe088b4a8a07e42c468c8c8aebb674a6b4ea1823221d
3
+ size 86446
models/ESPCN_x3.pb ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:0e667db7a431d14c32568ed79bf21701a64df8b1d162e48ca1f8800affe2c2b3
3
+ size 92226
models/ESPCN_x4.pb ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:e403f06309229cf36009cd8fb0da032ba7643fae9f15cf94fe562e8edf8fef47
3
+ size 100323
requirements.txt ADDED
@@ -0,0 +1,189 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ action-msgs==1.2.1
2
+ action-tutorials-interfaces==0.20.3
3
+ action-tutorials-py==0.20.3
4
+ actionlib-msgs==4.2.3
5
+ altair==4.2.2
6
+ ament-cmake-test==1.3.3
7
+ ament-copyright==0.12.5
8
+ ament-cppcheck==0.12.5
9
+ ament-cpplint==0.12.5
10
+ ament-flake8==0.12.5
11
+ ament-index-python==1.4.0
12
+ ament-lint==0.12.5
13
+ ament-lint-cmake==0.12.5
14
+ ament-package==0.14.0
15
+ ament-pep257==0.12.5
16
+ ament-uncrustify==0.12.5
17
+ ament-xmllint==0.12.5
18
+ angles==1.15.0
19
+ appdirs==1.4.4
20
+ attrs==22.2.0
21
+ beautifulsoup4==4.12.2
22
+ blinker==1.6
23
+ builtin-interfaces==1.2.1
24
+ cachetools==5.3.0
25
+ certifi==2022.12.7
26
+ cffi==1.15.1
27
+ charset-normalizer==3.1.0
28
+ click==8.1.3
29
+ composition-interfaces==1.2.1
30
+ cryptography==40.0.1
31
+ cv-bridge==3.2.1
32
+ decorator==5.1.1
33
+ demo-nodes-py==0.20.3
34
+ diagnostic-msgs==4.2.3
35
+ domain-coordinator==0.10.0
36
+ entrypoints==0.4
37
+ example-interfaces==0.9.3
38
+ examples-rclpy-executors==0.15.1
39
+ examples-rclpy-minimal-action-client==0.15.1
40
+ examples-rclpy-minimal-action-server==0.15.1
41
+ examples-rclpy-minimal-client==0.15.1
42
+ examples-rclpy-minimal-publisher==0.15.1
43
+ examples-rclpy-minimal-service==0.15.1
44
+ examples-rclpy-minimal-subscriber==0.15.1
45
+ frozendict==2.3.6
46
+ geometry-msgs==4.2.3
47
+ gitdb==4.0.10
48
+ GitPython==3.1.31
49
+ html5lib==1.1
50
+ idna==3.4
51
+ image-geometry==3.2.1
52
+ importlib-metadata==6.2.0
53
+ interactive-markers==2.3.2
54
+ Jinja2==3.1.2
55
+ jsonschema==4.17.3
56
+ laser-geometry==2.4.0
57
+ launch==1.0.4
58
+ launch-ros==0.19.4
59
+ launch-testing==1.0.4
60
+ launch-testing-ros==0.19.4
61
+ launch-xml==1.0.4
62
+ launch-yaml==1.0.4
63
+ lifecycle-msgs==1.2.1
64
+ logging-demo==0.20.3
65
+ lxml==4.9.2
66
+ map-msgs==2.1.0
67
+ markdown-it-py==2.2.0
68
+ MarkupSafe==2.1.2
69
+ mdurl==0.1.2
70
+ message-filters==4.3.2
71
+ multitasking==0.0.11
72
+ nav-msgs==4.2.3
73
+ numpy==1.24.2
74
+ opencv-contrib-python==4.5.5.64
75
+ osrf-pycommon==2.0.2
76
+ packaging==23.0
77
+ pandas==1.5.3
78
+ pcl-msgs==1.0.0
79
+ pendulum-msgs==0.20.3
80
+ Pillow==9.5.0
81
+ protobuf==3.20.3
82
+ pyarrow==11.0.0
83
+ pycparser==2.21
84
+ pydeck==0.8.0
85
+ Pygments==2.14.0
86
+ Pympler==1.0.1
87
+ pyrsistent==0.19.3
88
+ python-dateutil==2.8.2
89
+ python-qt-binding==1.1.1
90
+ pytz==2023.3
91
+ pytz-deprecation-shim==0.1.0.post0
92
+ qt-dotgraph==2.2.2
93
+ qt-gui==2.2.2
94
+ qt-gui-cpp==2.2.2
95
+ qt-gui-py-common==2.2.2
96
+ quality-of-service-demo-py==0.20.3
97
+ rcl-interfaces==1.2.1
98
+ rclpy==3.3.7
99
+ rcutils==5.1.2
100
+ requests==2.28.2
101
+ resource-retriever==3.1.1
102
+ rich==13.3.3
103
+ rmw-dds-common==1.6.0
104
+ ros2action==0.18.5
105
+ ros2bag==0.15.4
106
+ ros2cli==0.18.5
107
+ ros2component==0.18.5
108
+ ros2doctor==0.18.5
109
+ ros2interface==0.18.5
110
+ ros2launch==0.19.4
111
+ ros2lifecycle==0.18.5
112
+ ros2multicast==0.18.5
113
+ ros2node==0.18.5
114
+ ros2param==0.18.5
115
+ ros2pkg==0.18.5
116
+ ros2run==0.18.5
117
+ ros2service==0.18.5
118
+ ros2topic==0.18.5
119
+ rosbag2-interfaces==0.15.4
120
+ rosbag2-py==0.15.4
121
+ rosgraph-msgs==1.2.1
122
+ rosidl-adapter==3.1.4
123
+ rosidl-cli==3.1.4
124
+ rosidl-cmake==3.1.4
125
+ rosidl-generator-c==3.1.4
126
+ rosidl-generator-cpp==3.1.4
127
+ rosidl-generator-py==0.14.4
128
+ rosidl-parser==3.1.4
129
+ rosidl-runtime-py==0.9.3
130
+ rosidl-typesupport-c==2.0.0
131
+ rosidl-typesupport-cpp==2.0.0
132
+ rosidl-typesupport-fastrtps-c==2.2.0
133
+ rosidl-typesupport-fastrtps-cpp==2.2.0
134
+ rosidl-typesupport-introspection-c==3.1.4
135
+ rosidl-typesupport-introspection-cpp==3.1.4
136
+ rpyutils==0.2.1
137
+ rqt-action==2.0.1
138
+ rqt-bag==1.1.4
139
+ rqt-bag-plugins==1.1.4
140
+ rqt-console==2.0.2
141
+ rqt-graph==1.3.0
142
+ rqt-gui==1.1.4
143
+ rqt-gui-py==1.1.4
144
+ rqt-msg==1.2.0
145
+ rqt-plot==1.1.2
146
+ rqt-publisher==1.5.0
147
+ rqt-py-common==1.1.4
148
+ rqt-py-console==1.0.2
149
+ rqt-reconfigure==1.1.1
150
+ rqt-service-caller==1.0.5
151
+ rqt-shell==1.0.2
152
+ rqt-srv==1.0.3
153
+ rqt-topic==1.5.0
154
+ sensor-msgs==4.2.3
155
+ sensor-msgs-py==4.2.3
156
+ shape-msgs==4.2.3
157
+ six==1.16.0
158
+ smmap==5.0.0
159
+ soupsieve==2.4
160
+ sros2==0.10.4
161
+ statistics-msgs==1.2.1
162
+ std-msgs==4.2.3
163
+ std-srvs==4.2.3
164
+ stereo-msgs==4.2.3
165
+ streamlit==1.21.0
166
+ teleop-twist-keyboard==2.3.2
167
+ tf2-geometry-msgs==0.25.2
168
+ tf2-kdl==0.25.2
169
+ tf2-msgs==0.25.2
170
+ tf2-py==0.25.2
171
+ tf2-ros-py==0.25.2
172
+ tf2-tools==0.25.2
173
+ toml==0.10.2
174
+ toolz==0.12.0
175
+ topic-monitor==0.20.3
176
+ tornado==6.2
177
+ trajectory-msgs==4.2.3
178
+ turtlesim==1.4.2
179
+ typing_extensions==4.5.0
180
+ tzdata==2023.3
181
+ tzlocal==4.3
182
+ unique-identifier-msgs==2.2.1
183
+ urllib3==1.26.15
184
+ validators==0.20.0
185
+ visualization-msgs==4.2.3
186
+ watchdog==3.0.0
187
+ webencodings==0.5.1
188
+ yfinance==0.2.14
189
+ zipp==3.15.0