-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.py
320 lines (205 loc) · 7.72 KB
/
main.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
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
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
# Flask
# Bir şablonu oluşturmak için render_template() yöntemini kullanabilirsiniz
# Flask uygulamasını olusturup ayaga kaldırmak icin Flask(__name__) yöntemini kullanabilirsiniz
# Koddaki duruma gore on yuzde (HTML) hata veya uyari mesajları vermek icin flash methodunu kullanabilirsiniz
# istekleri kontrol etmek icin request methodu kullanılır
# jsonify; Bir application/json mimetype ile verilen bağımsız değişkenlerin JSON temsiliyle bir Yanıt oluşturur. Bu işlevin argümanları, dict yapıcısıyla aynıdır.
from flask import render_template, Flask, flash, request, jsonify
# path, isletim sistemi vb. icin
import os
# secilen bir dosyanin guvenli bir surumunu geri donderir
from werkzeug.utils import secure_filename
# farklı thredlerde farklı işler yaparak kodda dallanma sağlamak
from threading import Thread
# süre
import time
# resim sitili icin yazdigim fonskiyon
import image as im
# video sitili icin yazdigim fonskiyon
import video as vid
# video ve image stayle kisminda islem bittimi kontrolu icin refresh yapar
global asd
global asd0
asd = 0
asd0 = 0
# calisma alani dosyalari bu alana tasiyip bu alandan ceker
global path
path = os.getcwd()
# style isleminin Flask dan bagimsiz calismasini sağlamak
th = Thread()
finished = False
finished0 = False
# dosyalar
global content_file
global stil_file
app = Flask(__name__)
# upload turleri
app.config['UPLOAD_EXTENSIONS'] = ['.jpg', '.png', '.gif']
# upload yolu
app.config['UPLOAD_PATH'] = 'static/uploads'
# Şifreleme gerektiren herhangi bir şey (saldırganların kurcalamasına karşı güvenlik sağlamak için), gizli anahtarın ayarlanmasını gerektirir.
app.secret_key = b'_5#y2L"F4Q8z\n\xec]/'
# image style 'in koddan bagimsiz calismasini saglayan fonsiyon
def dataa():
global finished
im.asd()
finished = True
# Video style 'in koddan bagimsiz calismasini saglayan fonsiyon
def data():
global finished0
vid.asdd()
finished0 = True
@app.route("/")
def main():
return render_template("index.html")
@app.route("/VideoStyle",methods = ['GET', 'POST'])
def VideoStyle():
global content_file
global stil_file
sz = {"a":False, "b":False, "c":False, "d":False}
# GET : sunucudan veri istemek için.
# POST : işlenecek verileri sunucuya göndermek için.
if request.method == "POST":
try:
content_file = request.files['file1']
stil_file = request.files['file']
filename = secure_filename(content_file.filename)
temp = filename.split(".")
content_file.save(os.path.join(app.config['UPLOAD_PATH'], "content0."+temp[1]))
filename = secure_filename(stil_file.filename)
temp = filename.split(".")
stil_file.save(os.path.join(app.config['UPLOAD_PATH'], "stil."+temp[1]))
except:
sz["a"] = True
pass
try:
true = request.form['gender']
file = open("{}/booll/asd.txt".format(path),"w+")
file.write(true)
file.close()
except:
sz["b"] = True
pass
try:
height = request.form['height']
width = request.form['width']
if (int(height)<100 or int(height) > 1000) or (int(width)<100 or int(width) > 1000):
sz["c"] = True
pass
filea = open("{}/booll/asdd.txt".format(path), "w+")
filea.write(height +","+ width)
filea.close()
except:
sz["d"] = True
pass
flaa = False
if sz["a"] == True:
flash("Image data is missing or extensions of data are incorrect")
flaa = True
if sz["b"] == True:
flash("Please select whether to have color protection")
flaa = True
if sz["c"] == True:
flash("width and height cannot be less than 100 and greater than 1000")
flaa = True
if sz["d"] == True:
flash("Please enter height and width in data type int")
flaa = True
if flaa == True:
return render_template("/VideoStyle.html")
global th0
global finished0
finished0 = False
th0 = Thread(target=data)
th0.start()
return render_template("/VideoStyle0.html")
else:
return render_template("/VideoStyle.html")
@app.route("/ImageStyle",methods = ['GET', 'POST'])
def ImageStyle():
global content_file
global stil_file
sz = {"a":False, "b":False, "c":False, "d":False}
if request.method == "POST":
try:
content_file = request.files['file1']
stil_file = request.files['file']
filename = secure_filename(content_file.filename)
temp = filename.split(".")
content_file.save(os.path.join(app.config['UPLOAD_PATH'], "content."+temp[1]))
filename = secure_filename(stil_file.filename)
temp = filename.split(".")
stil_file.save(os.path.join(app.config['UPLOAD_PATH'], "stil."+temp[1]))
except:
sz["a"] = True
pass
try:
true = request.form['gender']
file = open("{}/booll/asd.txt".format(path),"w+")
file.write(true)
file.close()
except:
sz["b"] = True
pass
try:
height = request.form['height']
width = request.form['width']
if (int(height)<100 or int(height) > 6000) or (int(width)<100 or int(width) > 6000):
sz["c"] = True
pass
filea = open("{}/booll/asdd.txt".format(path), "w+")
filea.write(height +","+ width)
filea.close()
except:
sz["d"] = True
pass
flaa = False
if sz["a"] == True:
flash("Image data is missing or extensions of data are incorrect")
flaa = True
if sz["b"] == True:
flash("Please select whether to have color protection")
flaa = True
if sz["c"] == True:
flash("width and height cannot be less than 100 and greater than 6000")
flaa = True
if sz["d"] == True:
flash("Please enter height and width in data type int")
flaa = True
if flaa == True:
return render_template("/ImageStyle.html")
global th
global finished
finished = False
th = Thread(target=dataa)
th.start()
return render_template("/ImageStyle0.html")
else:
return render_template("/ImageStyle.html")
@app.route('/result',methods = ['GET', 'POST'])
def result():
global asd
asd += 1
""" Just give back the result of your heavy work """
return render_template("/ImageStyle1.html",asd=asd)
@app.route('/result0',methods = ['GET', 'POST'])
def result0():
global asd0
asd0 += 1
""" Just give back the result of your heavy work """
return render_template("/VideoStyle1.html",asd0=asd0)
@app.route('/status')
def thread_status():
""" Return the status of the worker thread """
time.sleep(20)
return jsonify(dict(status=('finished' if finished else 'running')))
@app.route('/status0')
def thread_status0():
""" Return the status of the worker thread """
time.sleep(20)
return jsonify(dict(status=('finished' if finished0 else 'running')))
@app.route('/me')
def me():
return render_template("/me.html")
if __name__ == "__main__":
app.run(debug=True, host='0.0.0.0', port=443, ssl_context=('cert.pem', 'key.pem'))