-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.py
152 lines (116 loc) · 5.05 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
from flask import Flask, render_template
from flask_wtf import FlaskForm
from wtforms import FileField, SubmitField
from werkzeug.utils import secure_filename
import os
from wtforms.validators import InputRequired
from flask import send_file
app = Flask(__name__)
app.config['SECRET_KEY'] = 'supersecretkey'
app.config['UPLOAD_FOLDER'] = 'static/files'
class UploadFileForm(FlaskForm):
file = FileField("WAV File", validators=[InputRequired()])
submit = SubmitField("Upload File")
@app.route('/', methods=['GET',"POST"])
@app.route('/home', methods=['GET',"POST"])
def home():
form = UploadFileForm()
if form.validate_on_submit():
file = form.file.data
filename = secure_filename(file.filename)
file_path = os.path.join(os.path.abspath(os.path.dirname(__file__)), app.config['UPLOAD_FOLDER'], filename)
file.save(file_path)
return send_file(file_path, as_attachment=True)
return render_template('main.html', form=form)
if __name__ == '__main__':
app.run(debug=True)
# from flask import Flask, render_template, jsonify
# from flask_wtf import FlaskForm
# from wtforms import FileField, SubmitField
# from werkzeug.utils import secure_filename
# import os
# from wtforms.validators import InputRequired
# from flask import send_file
# app = Flask(__name__)
# app.config['SECRET_KEY'] = 'supersecretkey'
# app.config['UPLOAD_FOLDER'] = 'static/files'
# class UploadFileForm(FlaskForm):
# file = FileField("WAV File", validators=[InputRequired()])
# submit = SubmitField("Upload File")
# @app.route('/', methods=['GET', 'POST'])
# @app.route('/home', methods=['GET', 'POST'])
# def home():
# form = UploadFileForm()
# if form.validate_on_submit():
# file = form.file.data
# filename = secure_filename(file.filename)
# file_path = os.path.join(os.path.abspath(os.path.dirname(__file__)), app.config['UPLOAD_FOLDER'], filename)
# file.save(file_path)
# # Trigger the file download using JavaScript
# return render_template('index.html', form=form, filename=filename, js_download=True)
# return render_template('index.html', form=form)
# @app.route('/download/<filename>')
# def download_file(filename):
# file_path = os.path.join(app.config['UPLOAD_FOLDER'], filename)
# return send_file(file_path, as_attachment=True)
# if __name__ == '__main__':
# app.run(debug=True)
# from flask import Flask, render_template, send_file
# from flask_wtf import FlaskForm
# from wtforms import FileField, SubmitField
# from werkzeug.utils import secure_filename
# import os
# from wtforms.validators import InputRequired
# app = Flask(__name__)
# app.config['SECRET_KEY'] = 'supersecretkey'
# app.config['UPLOAD_FOLDER'] = 'static/files'
# # Check if the UPLOAD_FOLDER exists, and create it if it doesn't
# if not os.path.exists(app.config['UPLOAD_FOLDER']):
# os.makedirs(app.config['UPLOAD_FOLDER'])
# class UploadFileForm(FlaskForm):
# file = FileField("WAV File", validators=[InputRequired()])
# submit = SubmitField("Upload File")
# @app.route('/', methods=['GET', 'POST'])
# @app.route('/home', methods=['GET', 'POST'])
# def home():
# form = UploadFileForm()
# success_message = None
# if form.validate_on_submit():
# file = form.file.data
# filename = secure_filename(file.filename)
# file_path = os.path.join(os.path.abspath(os.path.dirname(__file__)), app.config['UPLOAD_FOLDER'], filename)
# file.save(file_path)
# success_message = f"File '{filename}' uploaded and downloaded successfully."
# return render_template('tempclassifi.html', form=form, success_message=success_message)
# if __name__ == '__main__':
# app.run(debug=True,port=5500)
# from flask import Flask, render_template, send_file
# from flask_wtf import FlaskForm
# from wtforms import FileField, SubmitField
# from werkzeug.utils import secure_filename
# import os
# from wtforms.validators import InputRequired
# from flask import send_file
# app = Flask(__name__)
# app.config['SECRET_KEY'] = 'supersecretkey'
# app.config['UPLOAD_FOLDER'] = 'static/files'
# # # Check if the UPLOAD_FOLDER exists, and create it if it doesn't
# # if not os.path.exists(app.config['UPLOAD_FOLDER']):
# # os.makedirs(app.config['UPLOAD_FOLDER'])
# class UploadFileForm(FlaskForm):
# file = FileField("WAV File", validators=[InputRequired()])
# submit = SubmitField("Upload File")
# # @app.route('/', methods=['GET', 'POST'])
# # @app.route('/home', methods=['GET', 'POST'])
# # def home():
# # form = UploadFileForm()
# # success_message = None
# # if form.validate_on_submit():
# # file = form.file.data
# # filename = secure_filename(file.filename)
# # file_path = os.path.join(os.path.abspath(os.path.dirname(__file__)), app.config['UPLOAD_FOLDER'], filename)
# # file.save(file_path)
# # success_message = f"File '{filename}' uploaded and downloaded successfully."
# return render_template('tempclassifi.html', form=form, success_message=success_message)
# if __name__ == '__main__':
# app.run(debug=True)