diff --git a/app/routes.py b/app/routes.py index c91be32..43eb4a4 100644 --- a/app/routes.py +++ b/app/routes.py @@ -1,55 +1,34 @@ -from flask import request, jsonify -from app import app, db -from app.models import Demo - -# 添加用户 -@app.route('/demos', methods=['POST']) -def add_demo(): - data = request.get_json() - new_demo = Demo(info1=data['info1'], info2=data['info2']) - db.session.add(new_demo) - db.session.commit() - return jsonify({'message': 'Demo added successfully'}) - -# 获取所有用户 -@app.route('/demos', methods=['GET']) -def get_demos(): - demos = Demo.query.all() - demo_list = [] - for demo in demos: - demo_data = {'id': demo.id, 'info1': demo.info1, 'info2': demo.info2} - demo_list.append(demo_data) - return jsonify({'demos': demo_list}) - -# 获取单个用户 -@app.route('/demos/', methods=['GET']) -def get_demo(demo_id): - demo = Demo.query.get(demo_id) - if demo: - demo_data = {'id': demo.id, 'info1': demo.info1, 'info2': demo.info2} - return jsonify(demo_data) - return jsonify({'message': 'Demo not found'}), 404 - -# 更新用户信息 -@app.route('/demos/', methods=['PUT']) -def update_demo(demo_id): - demo = Demo.query.get(demo_id) - if not demo: - return jsonify({'message': 'Demo not found'}), 404 - - data = request.get_json() - demo.info1 = data['info1'] - demo.info2 = data['info2'] - db.session.commit() - return jsonify({'message': 'Demo updated successfully'}) - -# 删除用户 -@app.route('/demos/', methods=['DELETE']) -def delete_demo(demo_id): - demo = Demo.query.get(demo_id) - if not demo: - return jsonify({'message': 'Demo not found'}), 404 - - db.session.delete(demo) - db.session.commit() - return jsonify({'message': 'Demo deleted successfully'}) +from flask import Flask, request, jsonify + +app = Flask(__name__) + +@app.route('/generate_emojis', methods=['POST']) +def generate_emojis(): + # Get the description parameter from the request + description = request.json.get('description') + + # Call the chatgpt SDK to generate 10 emojis + emojis = chatgpt.generate_emojis(description) + + # Create a list to store the emoji ids and thumbnails + emoji_list = [] + + # Iterate over the emojis and add the id and thumbnail to the list + for emoji in emojis: + emoji_id = emoji.id + thumbnail = emoji.thumbnail + emoji_list.append({'id': emoji_id, 'thumbnail': thumbnail}) + + # Return the emoji list as a JSON response + return jsonify(emoji_list) + +@app.route('/preview_emoji/', methods=['GET']) +def preview_emoji(emoji_id): + # Call the chatgpt SDK to get the emoji image based on the emoji id + emoji_image = chatgpt.get_emoji_image(emoji_id) + + # Return the emoji image as a response + return emoji_image + +if __name__ == '__main__': + app.run(debug=True)