-
Notifications
You must be signed in to change notification settings - Fork 5
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
1、传入表情包的描述内容; 2、然后调用chatgpt的sdk,根据输入的描述自动生成10张表情包供用户选择;
- Loading branch information
1 parent
b146038
commit 3d409e3
Showing
1 changed file
with
34 additions
and
55 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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/<int:demo_id>', 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/<int:demo_id>', 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/<int:demo_id>', 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/<emoji_id>', 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) |