Skip to content

Commit

Permalink
从头开发一个表情包自动生成工具,实现:
Browse files Browse the repository at this point in the history
1、传入表情包的描述内容;
2、然后调用chatgpt的sdk,根据输入的描述自动生成10张表情包供用户选择;
  • Loading branch information
charging-kuafuai committed Jun 16, 2024
1 parent 3d409e3 commit c2939a0
Showing 1 changed file with 23 additions and 2 deletions.
25 changes: 23 additions & 2 deletions app/routes.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,19 +2,32 @@

app = Flask(__name__)

import chatgpt

@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
# Check if the description parameter is missing or invalid
if not description:
return jsonify({'error': 'Missing or invalid description parameter'})

# Call the chatgpt SDK to generate emojis
emojis = chatgpt.generate_emojis(description)

# Check if the emojis list is empty
if not emojis:
return jsonify({'error': 'No emojis generated'})

# Get the limit parameter from the request (default to 10 if not provided)
limit = request.json.get('limit', 10)

# 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:
for emoji in emojis[:limit]:
emoji_id = emoji.id
thumbnail = emoji.thumbnail
emoji_list.append({'id': emoji_id, 'thumbnail': thumbnail})
Expand All @@ -24,9 +37,17 @@ def generate_emojis():

@app.route('/preview_emoji/<emoji_id>', methods=['GET'])
def preview_emoji(emoji_id):
# Check if the emoji_id parameter is missing or invalid
if not emoji_id:
return jsonify({'error': 'Missing or invalid emoji_id parameter'})

# Call the chatgpt SDK to get the emoji image based on the emoji id
emoji_image = chatgpt.get_emoji_image(emoji_id)

# Check if the emoji image is not found
if not emoji_image:
return jsonify({'error': 'Emoji image not found'})

# Return the emoji image as a response
return emoji_image

Expand Down

0 comments on commit c2939a0

Please sign in to comment.