ai-sticker-maker / instructions.txt
abdibrokhim's picture
init, and major changes has been done
4c79642
raw
history blame
11.4 kB
Given the following code snippets, and the list of image generation models with example API requests.
[TASK]
<|gradio_app_instructions|>
Your task is to complete the code snippets by adding the necessary code to make the API requests.
The steps are really simple; user inputs any prompt; for example; "A girl with short pink hair wearing a oversize hoodie.".
Then, the prompt will be passed to the enhance_prompt function to enhance the prompt.
The enhanced prompt will be passed to the image generation model to generate the image.
However, here user will select which image generation model to use.
The image will be generated and displayed to the user.
[UI]
<|gradio_app_ui|>
List the image generation models on the left side of the UI.
Make image generation model selection as checkbox.
Display as much Image Output as user selected image generation models.
For example; we have 13 image generation models, and user selected 3 models using checkbox.
After user enters the prompt. The image will be generated using 3 models and displayed to the user.
[DOCS]
Feel free to use Gradio documentation to complete the task.
[CODE]
<|start_of_code_snippet|>
import gradio as gr
from openai import OpenAI
from dotenv import load_dotenv
import os
load_dotenv()
client = OpenAI(api_key=os.getenv("OPENAI_API_KEY"))
# i will update [SYSTEM_PROMPT] myself, ignore for now.
SYSTEM_PROMPT = """
<i will update myself, ignore for now.>
"""
# general function to enhance prompt
# user prompt will be passed as an argument
# this is very first step after user input
# then enhanced prompt will be passed to the image generation model
def enhance_prompt(user_prompt) -> str:
completion = client.chat.completions.create(
model="gpt-4o",
messages=[
{"role": "system", "content": SYSTEM_PROMPT},
{"role": "user", "content": user_prompt}
]
)
ep = completion.choices[0].message.content
print('Enhanced Prompt: ' ,ep)
return ep
# title should be centered
# gradio app title
title = "Let's Generate Cutesy AI Sticker!"
# align project_website and paper_url center and in one row
project_website = "https://ai-sticker-maker.vercel.app/"
paper_url = "https://rebrand.ly/aistickermakerpaper"
# call to action text should be also centered
call_to_action_text = "Please consider starring ⭐️ the [GitHub Repo](https://github.com/abdibrokhim/ai-sticker-maker) if you find this useful!"
# to build from scratch, you can follow the tutorial on medium and dev.to
tutorial_on_medium_link = "https://medium.com/@abdibrokhim/building-an-ai-sticker-maker-platform-with-ai-ml-api-next-js-8b0767a7e159"
tutorial_on_dev_link = "https://dev.to/abdibrokhim/building-an-ai-sticker-maker-platform-with-aiml-api-nextjs-react-and-tailwind-css-using-openai-gpt-4o-and-dalle-3-models-46ip"
# general input placeholder
placeholder = "A girl with short pink hair wearing a oversize hoodie..."
<|list_of_image_generation_models|>
# list of image generation models with example API requests
# 1. stable-diffusion-v35-large
# import requests
# import base64
# def main():
# headers = {
# "Authorization": "Bearer <YOUR_API_KEY>",
# }
# payload = {
# "prompt": "Hyperrealistic art featuring a cat in costume.",
# "model": "stable-diffusion-v35-large",
# }
# response = requests.post(
# "https://api.aimlapi.com/images/generations", headers=headers, json=payload
# )
# image_base64 = response.json()["output"]["choices"][0]["image_base64"]
# image_data = base64.b64decode(image_base64)
# with open("./image.png", "wb") as file:
# file.write(image_data)
# main()
# 2. flux-pro/v1.1
# import requests
# import base64
# def main():
# headers = {
# "Authorization": "Bearer <YOUR_API_KEY>",
# }
# payload = {
# "prompt": "Hyperrealistic art featuring a cat in costume.",
# "model": "flux-pro/v1.1",
# }
# response = requests.post(
# "https://api.aimlapi.com/images/generations", headers=headers, json=payload
# )
# image_base64 = response.json()["output"]["choices"][0]["image_base64"]
# image_data = base64.b64decode(image_base64)
# with open("./image.png", "wb") as file:
# file.write(image_data)
# main()
# 3. dall-e-3
# import requests
# import base64
# def main():
# headers = {
# "Authorization": "Bearer <YOUR_API_KEY>",
# }
# payload = {
# "prompt": "Hyperrealistic art featuring a cat in costume.",
# "model": "dall-e-3",
# }
# response = requests.post(
# "https://api.aimlapi.com/images/generations", headers=headers, json=payload
# )
# image_base64 = response.json()["output"]["choices"][0]["image_base64"]
# image_data = base64.b64decode(image_base64)
# with open("./image.png", "wb") as file:
# file.write(image_data)
# main()
# 4. stable-diffusion-v3-medium
# import requests
# import base64
# def main():
# headers = {
# "Authorization": "Bearer <YOUR_API_KEY>",
# }
# payload = {
# "prompt": "Hyperrealistic art featuring a cat in costume.",
# "model": "stable-diffusion-v3-medium",
# }
# response = requests.post(
# "https://api.aimlapi.com/images/generations", headers=headers, json=payload
# )
# image_base64 = response.json()["output"]["choices"][0]["image_base64"]
# image_data = base64.b64decode(image_base64)
# with open("./image.png", "wb") as file:
# file.write(image_data)
# main()
# 5. runwayml/stable-diffusion-v1-5
# import requests
# import base64
# def main():
# headers = {
# "Authorization": "Bearer <YOUR_API_KEY>",
# }
# payload = {
# "prompt": "Hyperrealistic art featuring a cat in costume.",
# "model": "runwayml/stable-diffusion-v1-5",
# }
# response = requests.post(
# "https://api.aimlapi.com/images/generations", headers=headers, json=payload
# )
# image_base64 = response.json()["output"]["choices"][0]["image_base64"]
# image_data = base64.b64decode(image_base64)
# with open("./image.png", "wb") as file:
# file.write(image_data)
# main()
# 6. stabilityai/stable-diffusion-xl-base-1.0
# import requests
# import base64
# def main():
# headers = {
# "Authorization": "Bearer <YOUR_API_KEY>",
# }
# payload = {
# "prompt": "Hyperrealistic art featuring a cat in costume.",
# "model": "stabilityai/stable-diffusion-xl-base-1.0",
# }
# response = requests.post(
# "https://api.aimlapi.com/images/generations", headers=headers, json=payload
# )
# image_base64 = response.json()["output"]["choices"][0]["image_base64"]
# image_data = base64.b64decode(image_base64)
# with open("./image.png", "wb") as file:
# file.write(image_data)
# main()
# 7. stabilityai/stable-diffusion-2-1
# import requests
# import base64
# def main():
# headers = {
# "Authorization": "Bearer <YOUR_API_KEY>",
# }
# payload = {
# "prompt": "Hyperrealistic art featuring a cat in costume.",
# "model": "stabilityai/stable-diffusion-2-1",
# }
# response = requests.post(
# "https://api.aimlapi.com/images/generations", headers=headers, json=payload
# )
# image_base64 = response.json()["output"]["choices"][0]["image_base64"]
# image_data = base64.b64decode(image_base64)
# with open("./image.png", "wb") as file:
# file.write(image_data)
# main()
# 8. SG161222/Realistic_Vision_V3.0_VAE
# import requests
# import base64
# def main():
# headers = {
# "Authorization": "Bearer <YOUR_API_KEY>",
# }
# payload = {
# "prompt": "Hyperrealistic art featuring a cat in costume.",
# "model": "SG161222/Realistic_Vision_V3.0_VAE",
# }
# response = requests.post(
# "https://api.aimlapi.com/images/generations", headers=headers, json=payload
# )
# image_base64 = response.json()["output"]["choices"][0]["image_base64"]
# image_data = base64.b64decode(image_base64)
# with open("./image.png", "wb") as file:
# file.write(image_data)
# main()
# 9. prompthero/openjourney
# import requests
# import base64
# def main():
# headers = {
# "Authorization": "Bearer <YOUR_API_KEY>",
# }
# payload = {
# "prompt": "Hyperrealistic art featuring a cat in costume.",
# "model": "prompthero/openjourney",
# }
# response = requests.post(
# "https://api.aimlapi.com/images/generations", headers=headers, json=payload
# )
# image_base64 = response.json()["output"]["choices"][0]["image_base64"]
# image_data = base64.b64decode(image_base64)
# with open("./image.png", "wb") as file:
# file.write(image_data)
# main()
# 10. wavymulder/Analog-Diffusion
# import requests
# import base64
# def main():
# headers = {
# "Authorization": "Bearer <YOUR_API_KEY>",
# }
# payload = {
# "prompt": "Hyperrealistic art featuring a cat in costume.",
# "model": "wavymulder/Analog-Diffusion",
# }
# response = requests.post(
# "https://api.aimlapi.com/images/generations", headers=headers, json=payload
# )
# image_base64 = response.json()["output"]["choices"][0]["image_base64"]
# image_data = base64.b64decode(image_base64)
# with open("./image.png", "wb") as file:
# file.write(image_data)
# main()
# 11. flux-pro
# import requests
# import base64
# def main():
# headers = {
# "Authorization": "Bearer <YOUR_API_KEY>",
# }
# payload = {
# "prompt": "Hyperrealistic art featuring a cat in costume.",
# "model": "flux-pro",
# }
# response = requests.post(
# "https://api.aimlapi.com/images/generations", headers=headers, json=payload
# )
# image_base64 = response.json()["output"]["choices"][0]["image_base64"]
# image_data = base64.b64decode(image_base64)
# with open("./image.png", "wb") as file:
# file.write(image_data)
# main()
# 12. flux-realism
# import requests
# import base64
# def main():
# headers = {
# "Authorization": "Bearer <YOUR_API_KEY>",
# }
# payload = {
# "prompt": "Hyperrealistic art featuring a cat in costume.",
# "model": "flux-realism",
# }
# response = requests.post(
# "https://api.aimlapi.com/images/generations", headers=headers, json=payload
# )
# image_base64 = response.json()["output"]["choices"][0]["image_base64"]
# image_data = base64.b64decode(image_base64)
# with open("./image.png", "wb") as file:
# file.write(image_data)
# main()
# 13. dall-e-2
# import requests
# import base64
# def main():
# headers = {
# "Authorization": "Bearer <YOUR_API_KEY>",
# }
# payload = {
# "prompt": "Hyperrealistic art featuring a cat in costume.",
# "model": "dall-e-2",
# }
# response = requests.post(
# "https://api.aimlapi.com/images/generations", headers=headers, json=payload
# )
# image_base64 = response.json()["output"]["choices"][0]["image_base64"]
# image_data = base64.b64decode(image_base64)
# with open("./image.png", "wb") as file:
# file.write(image_data)
# main()
<|end_of_code_snippet|>