-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathapp.py
More file actions
61 lines (51 loc) · 1.86 KB
/
app.py
File metadata and controls
61 lines (51 loc) · 1.86 KB
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
from flask import Flask, request, jsonify, send_from_directory
import os
from model import getAnswer
import uuid
app = Flask(__name__)
UPLOAD_FOLDER = 'uploads'
STATIC_FOLDER = 'static'
app.config['UPLOAD_FOLDER'] = UPLOAD_FOLDER
# Ensure the upload folder exists
if not os.path.exists(UPLOAD_FOLDER):
os.makedirs(UPLOAD_FOLDER)
# Home route to serve the upload form
@app.route('/')
def index():
return app.send_static_file('index.html')
# Upload route to handle file uploads
@app.route('/upload', methods=['POST'])
def upload_file():
if 'file' not in request.files:
return jsonify({'error': 'No file part'}), 400
file = request.files['file']
if file.filename == '':
return jsonify({'error': 'No selected file'}), 400
if file:
# Generate a unique filename
ext = os.path.splitext(file.filename)[1]
unique_filename = str(uuid.uuid4()) + ext
file.save(os.path.join(app.config['UPLOAD_FOLDER'], unique_filename))
return jsonify({'message': 'File uploaded successfully', 'filename': unique_filename}), 200
# Route to serve uploaded files
@app.route('/uploads/<filename>')
def uploaded_file(filename):
return send_from_directory(app.config['UPLOAD_FOLDER'], filename)
def model(prompt, image):
# Call your model here
return getAnswer(image, prompt)
# route to send a text prompt, an image filename, and return model response
@app.route('/prompt', methods=['POST'])
def prompt():
data = request.get_json()
prompt = data.get('prompt')
image = data.get('image')
response = model(prompt, image)
print(prompt, image)
return jsonify({'response': response})
# Route to serve static files
@app.route('/static/<path:filename>')
def static_files(filename):
return send_from_directory(STATIC_FOLDER, filename)
if __name__ == '__main__':
app.run(host='0.0.0.0', port=5001, debug=True)