-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathImageToText.py
52 lines (33 loc) · 1.15 KB
/
ImageToText.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
from flask_cors import CORS
from flask import Flask, request, send_file
from werkzeug.utils import secure_filename
import os
app = Flask(__name__)
# Enable CORS for all routes
CORS(app)
# Define the upload folder
UPLOAD_FOLDER = 'uploads'
app.config['UPLOAD_FOLDER'] = UPLOAD_FOLDER
# Define a function to check and create the upload folder if it doesn't exist
def create_upload_folder():
if not os.path.exists(UPLOAD_FOLDER):
os.makedirs(UPLOAD_FOLDER)
# Route to serve the ImageToText.js file
@app.route('/image-to-text', methods=['GET'])
def send_js():
return send_file('ImageToText.js')
# Route to handle file upload
@app.route('/image-to-text', methods=['POST'])
def upload_file():
if 'image' not in request.files:
return 'No file part'
uploaded_file = request.files['image']
if uploaded_file.filename == '':
return 'No selected file'
create_upload_folder()
filename = secure_filename(uploaded_file.filename)
upload_path = os.path.join(app.config['UPLOAD_FOLDER'], filename)
uploaded_file.save(upload_path)
return 'File uploaded successfully'
if __name__ == '__main__':
app.run(port=8000)