Spaces:
Runtime error
Runtime error
abdibrokhim
commited on
Commit
•
4c79642
1
Parent(s):
af32159
init, and major changes has been done
Browse files- .gitignore +2 -0
- app.py +193 -0
- instructions.txt +441 -0
- paper.txt +15 -0
- requirements.txt +5 -0
- systemPrompt.txt +40 -0
.gitignore
ADDED
@@ -0,0 +1,2 @@
|
|
|
|
|
|
|
1 |
+
.venv
|
2 |
+
.env
|
app.py
ADDED
@@ -0,0 +1,193 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
import gradio as gr
|
2 |
+
from openai import OpenAI
|
3 |
+
from dotenv import load_dotenv
|
4 |
+
import os
|
5 |
+
import requests
|
6 |
+
import base64
|
7 |
+
from PIL import Image
|
8 |
+
from io import BytesIO
|
9 |
+
|
10 |
+
load_dotenv()
|
11 |
+
|
12 |
+
# Initialize OpenAI client
|
13 |
+
client = OpenAI(api_key=os.getenv("OPENAI_API_KEY"))
|
14 |
+
|
15 |
+
# System prompt (to be updated)
|
16 |
+
SYSTEM_PROMPT = """
|
17 |
+
You are tasked with enhancing user prompts to generate clear, detailed, and creative descriptions for a sticker creation AI. The final prompt should be imaginative, visually rich, and aligned with the goal of producing a cute, stylized, and highly personalized sticker based on the user's input.
|
18 |
+
|
19 |
+
Instructions:
|
20 |
+
|
21 |
+
Visual Clarity: The enhanced prompt must provide clear visual details that can be directly interpreted by the image generation model. Break down and elaborate on specific elements of the scene, object, or character based on the user input.
|
22 |
+
|
23 |
+
Example: If the user says "A girl with pink hair," elaborate by adding features like "short wavy pink hair with soft, pastel hues."
|
24 |
+
Style & Theme:
|
25 |
+
|
26 |
+
Emphasize that the final output should reflect a cute, playful, and approachable style.
|
27 |
+
Add terms like "adorable," "cartoonish," "sticker-friendly," or "chibi-like" to guide the output to a lighter, cuter aesthetic.
|
28 |
+
Include styling prompts like “minimalistic lines,” “soft shading,” and “vibrant yet soothing colors.”
|
29 |
+
Personalization:
|
30 |
+
|
31 |
+
If a reference or context is given, enhance it to make the sticker feel personalized.
|
32 |
+
Add context-appropriate descriptors like “wearing a cozy blue hoodie,” “soft pink blush on cheeks,” or “a playful expression.”
|
33 |
+
Expression & Pose:
|
34 |
+
|
35 |
+
Where applicable, refine prompts with suggestions about facial expressions or body language. For example, “Smiling softly with big sparkling eyes” or “A cute wink and a slight tilt of the head.”
|
36 |
+
Background & Accessories:
|
37 |
+
|
38 |
+
Optionally suggest simple, complementary backgrounds or accessories, depending on user input. For instance, "A light pastel background with small, floating hearts" or "Holding a tiny, sparkling star."
|
39 |
+
Colors:
|
40 |
+
|
41 |
+
Emphasize the color scheme based on the user's description, making sure it's consistent with a cute, playful style.
|
42 |
+
Use descriptors like “soft pastels,” “bright and cheerful,” or “warm and friendly hues” to set the mood.
|
43 |
+
Avoid Overcomplication:
|
44 |
+
|
45 |
+
Keep the descriptions short enough to be concise and not overly complex, as the output should retain a sticker-friendly quality.
|
46 |
+
Avoid unnecessary details that could clutter the design.
|
47 |
+
Tone and Language:
|
48 |
+
|
49 |
+
The tone should be light, imaginative, and fun, matching the playful nature of stickers.
|
50 |
+
|
51 |
+
Example:
|
52 |
+
User Input:
|
53 |
+
"A girl with pink hair wearing a hoodie."
|
54 |
+
|
55 |
+
Enhanced Prompt:
|
56 |
+
"An adorable girl with short, wavy pink hair in soft pastel hues, wearing a cozy light blue hoodie. She has a sweet smile with big, sparkling eyes, and a playful expression. The sticker style is cartoonish with minimalistic lines and soft shading. The background is a simple light pastel color with small floating hearts, creating a cute and inviting look."
|
57 |
+
"""
|
58 |
+
|
59 |
+
# Function to enhance the user's prompt
|
60 |
+
def enhance_prompt(user_prompt) -> str:
|
61 |
+
completion = client.chat.completions.create(
|
62 |
+
model="gpt-4o",
|
63 |
+
messages=[
|
64 |
+
{"role": "system", "content": SYSTEM_PROMPT},
|
65 |
+
{"role": "user", "content": user_prompt}
|
66 |
+
]
|
67 |
+
)
|
68 |
+
ep = completion.choices[0].message.content
|
69 |
+
print('Enhanced Prompt:', ep)
|
70 |
+
return ep
|
71 |
+
|
72 |
+
# Function to generate images using the selected models
|
73 |
+
def generate_images(user_prompt, selected_models):
|
74 |
+
enhanced_prompt = enhance_prompt(user_prompt)
|
75 |
+
images = []
|
76 |
+
headers = {
|
77 |
+
"Authorization": f"Bearer {os.getenv('AIMLAPI_API_KEY')}",
|
78 |
+
}
|
79 |
+
for model in selected_models:
|
80 |
+
try:
|
81 |
+
payload = {
|
82 |
+
"prompt": enhanced_prompt,
|
83 |
+
"model": model,
|
84 |
+
}
|
85 |
+
response = requests.post(
|
86 |
+
"https://api.aimlapi.com/images/generations", headers=headers, json=payload
|
87 |
+
)
|
88 |
+
if response.status_code == 201:
|
89 |
+
response_json = response.json()
|
90 |
+
print(f"Response for model {model}: {response_json}")
|
91 |
+
# Handle OpenAI models differently (Aspect 2)
|
92 |
+
if model in ["dall-e-3", "dall-e-2"]:
|
93 |
+
if 'data' in response_json and 'url' in response_json['data'][0]:
|
94 |
+
image_url = response_json['data'][0]['url']
|
95 |
+
image_response = requests.get(image_url)
|
96 |
+
image = Image.open(BytesIO(image_response.content))
|
97 |
+
images.append(image)
|
98 |
+
else:
|
99 |
+
print(f"No URL found for model {model}")
|
100 |
+
else:
|
101 |
+
# Handle other models (Aspect 1)
|
102 |
+
if 'images' in response_json and 'url' in response_json['images'][0]:
|
103 |
+
image_url = response_json['images'][0]['url']
|
104 |
+
image_response = requests.get(image_url)
|
105 |
+
image = Image.open(BytesIO(image_response.content))
|
106 |
+
images.append(image)
|
107 |
+
else:
|
108 |
+
print(f"No URL found for model {model}")
|
109 |
+
else:
|
110 |
+
print(f"Error with model {model}: {response.text}")
|
111 |
+
except Exception as e:
|
112 |
+
print(f"Exception occurred with model {model}: {e}")
|
113 |
+
continue
|
114 |
+
return images
|
115 |
+
|
116 |
+
# List of available image generation models
|
117 |
+
model_list = [
|
118 |
+
"stable-diffusion-v35-large",
|
119 |
+
"flux-pro/v1.1",
|
120 |
+
"dall-e-3",
|
121 |
+
"stable-diffusion-v3-medium",
|
122 |
+
"runwayml/stable-diffusion-v1-5",
|
123 |
+
"stabilityai/stable-diffusion-xl-base-1.0",
|
124 |
+
"stabilityai/stable-diffusion-2-1",
|
125 |
+
"SG161222/Realistic_Vision_V3.0_VAE",
|
126 |
+
"prompthero/openjourney",
|
127 |
+
"wavymulder/Analog-Diffusion",
|
128 |
+
"flux-pro",
|
129 |
+
"flux-realism",
|
130 |
+
"dall-e-2",
|
131 |
+
]
|
132 |
+
|
133 |
+
# Gradio Interface
|
134 |
+
with gr.Blocks() as demo:
|
135 |
+
# Title and links
|
136 |
+
with gr.Row():
|
137 |
+
gr.Markdown("""
|
138 |
+
# Let's Generate Cutesy AI Sticker!
|
139 |
+
<p align="center">
|
140 |
+
<a title="Page" href="https://ai-sticker-maker.vercel.app/" target="_blank" rel="noopener noreferrer" style="display: inline-block;">
|
141 |
+
<img src="https://img.shields.io/badge/Project-Website-pink?logo=googlechrome&logoColor=white">
|
142 |
+
</a>
|
143 |
+
<a title="arXiv" href="https://rebrand.ly/aistickermakerpaper" target="_blank" rel="noopener noreferrer" style="display: inline-block;">
|
144 |
+
<img src="https://img.shields.io/badge/arXiv-Paper-b31b1b?logo=arxiv&logoColor=white">
|
145 |
+
</a>
|
146 |
+
<a title="Github" href="https://github.com/abdibrokhim/ai-sticker-maker" target="_blank" rel="noopener noreferrer" style="display: inline-block;">
|
147 |
+
<img src="https://img.shields.io/github/stars/EnVision-Research/Lotus?label=GitHub%20%E2%98%85&logo=github&color=C8C" alt="badge-github-stars">
|
148 |
+
</a>
|
149 |
+
<a title="Social" href="https://x.com/abdibrokhim" target="_blank" rel="noopener noreferrer" style="display: inline-block;">
|
150 |
+
<img src="https://www.obukhov.ai/img/badges/badge-social.svg" alt="social">
|
151 |
+
</a>
|
152 |
+
<a title="Social" href="https://x.com/haodongli00/status/1839524569058582884" target="_blank" rel="noopener noreferrer" style="display: inline-block;">
|
153 |
+
<img src="https://www.obukhov.ai/img/badges/badge-social.svg" alt="social">
|
154 |
+
</a>
|
155 |
+
<br>
|
156 |
+
<strong>Please consider starring <span style="color: orange">★</span> the <a href="https://github.com/abdibrokhim/ai-sticker-maker" target="_blank" rel="noopener noreferrer">GitHub Repo</a> if you find this useful!</strong>
|
157 |
+
""")
|
158 |
+
with gr.Row():
|
159 |
+
with gr.Column(scale=1):
|
160 |
+
# Model selection
|
161 |
+
selected_models = gr.CheckboxGroup(
|
162 |
+
choices=model_list,
|
163 |
+
label="Select Image Generation Models",
|
164 |
+
value=["stable-diffusion-v35-large"]
|
165 |
+
)
|
166 |
+
with gr.Column(scale=2):
|
167 |
+
# User prompt input
|
168 |
+
# Example propt: a very cutesy panda sitting and easting a pink very creamy ice cream
|
169 |
+
user_prompt = gr.Textbox(
|
170 |
+
placeholder="A girl with short pink hair wearing an oversize hoodie...",
|
171 |
+
label="Enter your prompt here"
|
172 |
+
)
|
173 |
+
# Generate button
|
174 |
+
generate_button = gr.Button("Generate Images")
|
175 |
+
|
176 |
+
# Outputs
|
177 |
+
image_outputs = gr.Gallery(label="Generated Images", columns=[3], rows=[1], elem_id="gallery")
|
178 |
+
|
179 |
+
# Function to run on button click
|
180 |
+
def on_click(user_prompt, selected_models):
|
181 |
+
images = generate_images(user_prompt, selected_models)
|
182 |
+
# Filter out None values in case of errors
|
183 |
+
return [img for img in images if img is not None]
|
184 |
+
|
185 |
+
# Event binding
|
186 |
+
generate_button.click(
|
187 |
+
fn=on_click,
|
188 |
+
inputs=[user_prompt, selected_models],
|
189 |
+
outputs=image_outputs
|
190 |
+
)
|
191 |
+
|
192 |
+
# Launch the Gradio app
|
193 |
+
demo.launch()
|
instructions.txt
ADDED
@@ -0,0 +1,441 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
|
2 |
+
Given the following code snippets, and the list of image generation models with example API requests.
|
3 |
+
|
4 |
+
[TASK]
|
5 |
+
<|gradio_app_instructions|>
|
6 |
+
Your task is to complete the code snippets by adding the necessary code to make the API requests.
|
7 |
+
The steps are really simple; user inputs any prompt; for example; "A girl with short pink hair wearing a oversize hoodie.".
|
8 |
+
Then, the prompt will be passed to the enhance_prompt function to enhance the prompt.
|
9 |
+
The enhanced prompt will be passed to the image generation model to generate the image.
|
10 |
+
However, here user will select which image generation model to use.
|
11 |
+
The image will be generated and displayed to the user.
|
12 |
+
|
13 |
+
[UI]
|
14 |
+
<|gradio_app_ui|>
|
15 |
+
List the image generation models on the left side of the UI.
|
16 |
+
Make image generation model selection as checkbox.
|
17 |
+
Display as much Image Output as user selected image generation models.
|
18 |
+
For example; we have 13 image generation models, and user selected 3 models using checkbox.
|
19 |
+
After user enters the prompt. The image will be generated using 3 models and displayed to the user.
|
20 |
+
|
21 |
+
[DOCS]
|
22 |
+
Feel free to use Gradio documentation to complete the task.
|
23 |
+
|
24 |
+
[CODE]
|
25 |
+
<|start_of_code_snippet|>
|
26 |
+
import gradio as gr
|
27 |
+
from openai import OpenAI
|
28 |
+
from dotenv import load_dotenv
|
29 |
+
import os
|
30 |
+
|
31 |
+
load_dotenv()
|
32 |
+
|
33 |
+
client = OpenAI(api_key=os.getenv("OPENAI_API_KEY"))
|
34 |
+
|
35 |
+
# i will update [SYSTEM_PROMPT] myself, ignore for now.
|
36 |
+
SYSTEM_PROMPT = """
|
37 |
+
<i will update myself, ignore for now.>
|
38 |
+
"""
|
39 |
+
|
40 |
+
# general function to enhance prompt
|
41 |
+
# user prompt will be passed as an argument
|
42 |
+
# this is very first step after user input
|
43 |
+
# then enhanced prompt will be passed to the image generation model
|
44 |
+
def enhance_prompt(user_prompt) -> str:
|
45 |
+
completion = client.chat.completions.create(
|
46 |
+
model="gpt-4o",
|
47 |
+
messages=[
|
48 |
+
{"role": "system", "content": SYSTEM_PROMPT},
|
49 |
+
{"role": "user", "content": user_prompt}
|
50 |
+
]
|
51 |
+
)
|
52 |
+
|
53 |
+
ep = completion.choices[0].message.content
|
54 |
+
print('Enhanced Prompt: ' ,ep)
|
55 |
+
|
56 |
+
return ep
|
57 |
+
|
58 |
+
# title should be centered
|
59 |
+
# gradio app title
|
60 |
+
title = "Let's Generate Cutesy AI Sticker!"
|
61 |
+
|
62 |
+
# align project_website and paper_url center and in one row
|
63 |
+
project_website = "https://ai-sticker-maker.vercel.app/"
|
64 |
+
paper_url = "https://rebrand.ly/aistickermakerpaper"
|
65 |
+
|
66 |
+
# call to action text should be also centered
|
67 |
+
call_to_action_text = "Please consider starring ⭐️ the [GitHub Repo](https://github.com/abdibrokhim/ai-sticker-maker) if you find this useful!"
|
68 |
+
|
69 |
+
# to build from scratch, you can follow the tutorial on medium and dev.to
|
70 |
+
tutorial_on_medium_link = "https://medium.com/@abdibrokhim/building-an-ai-sticker-maker-platform-with-ai-ml-api-next-js-8b0767a7e159"
|
71 |
+
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"
|
72 |
+
|
73 |
+
# general input placeholder
|
74 |
+
placeholder = "A girl with short pink hair wearing a oversize hoodie..."
|
75 |
+
|
76 |
+
<|list_of_image_generation_models|>
|
77 |
+
# list of image generation models with example API requests
|
78 |
+
|
79 |
+
# 1. stable-diffusion-v35-large
|
80 |
+
# import requests
|
81 |
+
# import base64
|
82 |
+
# def main():
|
83 |
+
# headers = {
|
84 |
+
# "Authorization": "Bearer <YOUR_API_KEY>",
|
85 |
+
# }
|
86 |
+
|
87 |
+
# payload = {
|
88 |
+
# "prompt": "Hyperrealistic art featuring a cat in costume.",
|
89 |
+
# "model": "stable-diffusion-v35-large",
|
90 |
+
# }
|
91 |
+
|
92 |
+
# response = requests.post(
|
93 |
+
# "https://api.aimlapi.com/images/generations", headers=headers, json=payload
|
94 |
+
# )
|
95 |
+
|
96 |
+
# image_base64 = response.json()["output"]["choices"][0]["image_base64"]
|
97 |
+
# image_data = base64.b64decode(image_base64)
|
98 |
+
|
99 |
+
# with open("./image.png", "wb") as file:
|
100 |
+
# file.write(image_data)
|
101 |
+
|
102 |
+
|
103 |
+
# main()
|
104 |
+
|
105 |
+
# 2. flux-pro/v1.1
|
106 |
+
# import requests
|
107 |
+
# import base64
|
108 |
+
|
109 |
+
|
110 |
+
# def main():
|
111 |
+
# headers = {
|
112 |
+
# "Authorization": "Bearer <YOUR_API_KEY>",
|
113 |
+
# }
|
114 |
+
|
115 |
+
# payload = {
|
116 |
+
# "prompt": "Hyperrealistic art featuring a cat in costume.",
|
117 |
+
# "model": "flux-pro/v1.1",
|
118 |
+
# }
|
119 |
+
|
120 |
+
# response = requests.post(
|
121 |
+
# "https://api.aimlapi.com/images/generations", headers=headers, json=payload
|
122 |
+
# )
|
123 |
+
|
124 |
+
# image_base64 = response.json()["output"]["choices"][0]["image_base64"]
|
125 |
+
# image_data = base64.b64decode(image_base64)
|
126 |
+
|
127 |
+
# with open("./image.png", "wb") as file:
|
128 |
+
# file.write(image_data)
|
129 |
+
|
130 |
+
|
131 |
+
# main()
|
132 |
+
|
133 |
+
# 3. dall-e-3
|
134 |
+
# import requests
|
135 |
+
# import base64
|
136 |
+
|
137 |
+
|
138 |
+
# def main():
|
139 |
+
# headers = {
|
140 |
+
# "Authorization": "Bearer <YOUR_API_KEY>",
|
141 |
+
# }
|
142 |
+
|
143 |
+
# payload = {
|
144 |
+
# "prompt": "Hyperrealistic art featuring a cat in costume.",
|
145 |
+
# "model": "dall-e-3",
|
146 |
+
# }
|
147 |
+
|
148 |
+
# response = requests.post(
|
149 |
+
# "https://api.aimlapi.com/images/generations", headers=headers, json=payload
|
150 |
+
# )
|
151 |
+
|
152 |
+
# image_base64 = response.json()["output"]["choices"][0]["image_base64"]
|
153 |
+
# image_data = base64.b64decode(image_base64)
|
154 |
+
|
155 |
+
# with open("./image.png", "wb") as file:
|
156 |
+
# file.write(image_data)
|
157 |
+
|
158 |
+
|
159 |
+
# main()
|
160 |
+
|
161 |
+
# 4. stable-diffusion-v3-medium
|
162 |
+
# import requests
|
163 |
+
# import base64
|
164 |
+
|
165 |
+
|
166 |
+
# def main():
|
167 |
+
# headers = {
|
168 |
+
# "Authorization": "Bearer <YOUR_API_KEY>",
|
169 |
+
# }
|
170 |
+
|
171 |
+
# payload = {
|
172 |
+
# "prompt": "Hyperrealistic art featuring a cat in costume.",
|
173 |
+
# "model": "stable-diffusion-v3-medium",
|
174 |
+
# }
|
175 |
+
|
176 |
+
# response = requests.post(
|
177 |
+
# "https://api.aimlapi.com/images/generations", headers=headers, json=payload
|
178 |
+
# )
|
179 |
+
|
180 |
+
# image_base64 = response.json()["output"]["choices"][0]["image_base64"]
|
181 |
+
# image_data = base64.b64decode(image_base64)
|
182 |
+
|
183 |
+
# with open("./image.png", "wb") as file:
|
184 |
+
# file.write(image_data)
|
185 |
+
|
186 |
+
|
187 |
+
# main()
|
188 |
+
|
189 |
+
# 5. runwayml/stable-diffusion-v1-5
|
190 |
+
# import requests
|
191 |
+
# import base64
|
192 |
+
|
193 |
+
|
194 |
+
# def main():
|
195 |
+
# headers = {
|
196 |
+
# "Authorization": "Bearer <YOUR_API_KEY>",
|
197 |
+
# }
|
198 |
+
|
199 |
+
# payload = {
|
200 |
+
# "prompt": "Hyperrealistic art featuring a cat in costume.",
|
201 |
+
# "model": "runwayml/stable-diffusion-v1-5",
|
202 |
+
# }
|
203 |
+
|
204 |
+
# response = requests.post(
|
205 |
+
# "https://api.aimlapi.com/images/generations", headers=headers, json=payload
|
206 |
+
# )
|
207 |
+
|
208 |
+
# image_base64 = response.json()["output"]["choices"][0]["image_base64"]
|
209 |
+
# image_data = base64.b64decode(image_base64)
|
210 |
+
|
211 |
+
# with open("./image.png", "wb") as file:
|
212 |
+
# file.write(image_data)
|
213 |
+
|
214 |
+
|
215 |
+
# main()
|
216 |
+
|
217 |
+
# 6. stabilityai/stable-diffusion-xl-base-1.0
|
218 |
+
# import requests
|
219 |
+
# import base64
|
220 |
+
|
221 |
+
|
222 |
+
# def main():
|
223 |
+
# headers = {
|
224 |
+
# "Authorization": "Bearer <YOUR_API_KEY>",
|
225 |
+
# }
|
226 |
+
|
227 |
+
# payload = {
|
228 |
+
# "prompt": "Hyperrealistic art featuring a cat in costume.",
|
229 |
+
# "model": "stabilityai/stable-diffusion-xl-base-1.0",
|
230 |
+
# }
|
231 |
+
|
232 |
+
# response = requests.post(
|
233 |
+
# "https://api.aimlapi.com/images/generations", headers=headers, json=payload
|
234 |
+
# )
|
235 |
+
|
236 |
+
# image_base64 = response.json()["output"]["choices"][0]["image_base64"]
|
237 |
+
# image_data = base64.b64decode(image_base64)
|
238 |
+
|
239 |
+
# with open("./image.png", "wb") as file:
|
240 |
+
# file.write(image_data)
|
241 |
+
|
242 |
+
|
243 |
+
# main()
|
244 |
+
|
245 |
+
# 7. stabilityai/stable-diffusion-2-1
|
246 |
+
# import requests
|
247 |
+
# import base64
|
248 |
+
|
249 |
+
|
250 |
+
# def main():
|
251 |
+
# headers = {
|
252 |
+
# "Authorization": "Bearer <YOUR_API_KEY>",
|
253 |
+
# }
|
254 |
+
|
255 |
+
# payload = {
|
256 |
+
# "prompt": "Hyperrealistic art featuring a cat in costume.",
|
257 |
+
# "model": "stabilityai/stable-diffusion-2-1",
|
258 |
+
# }
|
259 |
+
|
260 |
+
# response = requests.post(
|
261 |
+
# "https://api.aimlapi.com/images/generations", headers=headers, json=payload
|
262 |
+
# )
|
263 |
+
|
264 |
+
# image_base64 = response.json()["output"]["choices"][0]["image_base64"]
|
265 |
+
# image_data = base64.b64decode(image_base64)
|
266 |
+
|
267 |
+
# with open("./image.png", "wb") as file:
|
268 |
+
# file.write(image_data)
|
269 |
+
|
270 |
+
|
271 |
+
# main()
|
272 |
+
|
273 |
+
# 8. SG161222/Realistic_Vision_V3.0_VAE
|
274 |
+
# import requests
|
275 |
+
# import base64
|
276 |
+
|
277 |
+
|
278 |
+
# def main():
|
279 |
+
# headers = {
|
280 |
+
# "Authorization": "Bearer <YOUR_API_KEY>",
|
281 |
+
# }
|
282 |
+
|
283 |
+
# payload = {
|
284 |
+
# "prompt": "Hyperrealistic art featuring a cat in costume.",
|
285 |
+
# "model": "SG161222/Realistic_Vision_V3.0_VAE",
|
286 |
+
# }
|
287 |
+
|
288 |
+
# response = requests.post(
|
289 |
+
# "https://api.aimlapi.com/images/generations", headers=headers, json=payload
|
290 |
+
# )
|
291 |
+
|
292 |
+
# image_base64 = response.json()["output"]["choices"][0]["image_base64"]
|
293 |
+
# image_data = base64.b64decode(image_base64)
|
294 |
+
|
295 |
+
# with open("./image.png", "wb") as file:
|
296 |
+
# file.write(image_data)
|
297 |
+
|
298 |
+
|
299 |
+
# main()
|
300 |
+
|
301 |
+
# 9. prompthero/openjourney
|
302 |
+
# import requests
|
303 |
+
# import base64
|
304 |
+
|
305 |
+
|
306 |
+
# def main():
|
307 |
+
# headers = {
|
308 |
+
# "Authorization": "Bearer <YOUR_API_KEY>",
|
309 |
+
# }
|
310 |
+
|
311 |
+
# payload = {
|
312 |
+
# "prompt": "Hyperrealistic art featuring a cat in costume.",
|
313 |
+
# "model": "prompthero/openjourney",
|
314 |
+
# }
|
315 |
+
|
316 |
+
# response = requests.post(
|
317 |
+
# "https://api.aimlapi.com/images/generations", headers=headers, json=payload
|
318 |
+
# )
|
319 |
+
|
320 |
+
# image_base64 = response.json()["output"]["choices"][0]["image_base64"]
|
321 |
+
# image_data = base64.b64decode(image_base64)
|
322 |
+
|
323 |
+
# with open("./image.png", "wb") as file:
|
324 |
+
# file.write(image_data)
|
325 |
+
|
326 |
+
|
327 |
+
# main()
|
328 |
+
|
329 |
+
# 10. wavymulder/Analog-Diffusion
|
330 |
+
# import requests
|
331 |
+
# import base64
|
332 |
+
|
333 |
+
|
334 |
+
# def main():
|
335 |
+
# headers = {
|
336 |
+
# "Authorization": "Bearer <YOUR_API_KEY>",
|
337 |
+
# }
|
338 |
+
|
339 |
+
# payload = {
|
340 |
+
# "prompt": "Hyperrealistic art featuring a cat in costume.",
|
341 |
+
# "model": "wavymulder/Analog-Diffusion",
|
342 |
+
# }
|
343 |
+
|
344 |
+
# response = requests.post(
|
345 |
+
# "https://api.aimlapi.com/images/generations", headers=headers, json=payload
|
346 |
+
# )
|
347 |
+
|
348 |
+
# image_base64 = response.json()["output"]["choices"][0]["image_base64"]
|
349 |
+
# image_data = base64.b64decode(image_base64)
|
350 |
+
|
351 |
+
# with open("./image.png", "wb") as file:
|
352 |
+
# file.write(image_data)
|
353 |
+
|
354 |
+
|
355 |
+
# main()
|
356 |
+
|
357 |
+
# 11. flux-pro
|
358 |
+
# import requests
|
359 |
+
# import base64
|
360 |
+
|
361 |
+
|
362 |
+
# def main():
|
363 |
+
# headers = {
|
364 |
+
# "Authorization": "Bearer <YOUR_API_KEY>",
|
365 |
+
# }
|
366 |
+
|
367 |
+
# payload = {
|
368 |
+
# "prompt": "Hyperrealistic art featuring a cat in costume.",
|
369 |
+
# "model": "flux-pro",
|
370 |
+
# }
|
371 |
+
|
372 |
+
# response = requests.post(
|
373 |
+
# "https://api.aimlapi.com/images/generations", headers=headers, json=payload
|
374 |
+
# )
|
375 |
+
|
376 |
+
# image_base64 = response.json()["output"]["choices"][0]["image_base64"]
|
377 |
+
# image_data = base64.b64decode(image_base64)
|
378 |
+
|
379 |
+
# with open("./image.png", "wb") as file:
|
380 |
+
# file.write(image_data)
|
381 |
+
|
382 |
+
|
383 |
+
# main()
|
384 |
+
|
385 |
+
# 12. flux-realism
|
386 |
+
# import requests
|
387 |
+
# import base64
|
388 |
+
|
389 |
+
|
390 |
+
# def main():
|
391 |
+
# headers = {
|
392 |
+
# "Authorization": "Bearer <YOUR_API_KEY>",
|
393 |
+
# }
|
394 |
+
|
395 |
+
# payload = {
|
396 |
+
# "prompt": "Hyperrealistic art featuring a cat in costume.",
|
397 |
+
# "model": "flux-realism",
|
398 |
+
# }
|
399 |
+
|
400 |
+
# response = requests.post(
|
401 |
+
# "https://api.aimlapi.com/images/generations", headers=headers, json=payload
|
402 |
+
# )
|
403 |
+
|
404 |
+
# image_base64 = response.json()["output"]["choices"][0]["image_base64"]
|
405 |
+
# image_data = base64.b64decode(image_base64)
|
406 |
+
|
407 |
+
# with open("./image.png", "wb") as file:
|
408 |
+
# file.write(image_data)
|
409 |
+
|
410 |
+
|
411 |
+
# main()
|
412 |
+
|
413 |
+
# 13. dall-e-2
|
414 |
+
# import requests
|
415 |
+
# import base64
|
416 |
+
|
417 |
+
|
418 |
+
# def main():
|
419 |
+
# headers = {
|
420 |
+
# "Authorization": "Bearer <YOUR_API_KEY>",
|
421 |
+
# }
|
422 |
+
|
423 |
+
# payload = {
|
424 |
+
# "prompt": "Hyperrealistic art featuring a cat in costume.",
|
425 |
+
# "model": "dall-e-2",
|
426 |
+
# }
|
427 |
+
|
428 |
+
# response = requests.post(
|
429 |
+
# "https://api.aimlapi.com/images/generations", headers=headers, json=payload
|
430 |
+
# )
|
431 |
+
|
432 |
+
# image_base64 = response.json()["output"]["choices"][0]["image_base64"]
|
433 |
+
# image_data = base64.b64decode(image_base64)
|
434 |
+
|
435 |
+
# with open("./image.png", "wb") as file:
|
436 |
+
# file.write(image_data)
|
437 |
+
|
438 |
+
|
439 |
+
# main()
|
440 |
+
|
441 |
+
<|end_of_code_snippet|>
|
paper.txt
ADDED
@@ -0,0 +1,15 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
[title]
|
2 |
+
Text-to-Sticker: Leveraging Image Generation Models to generate AI stickers using simple Prompt Engineering techniques
|
3 |
+
|
4 |
+
[abstract]
|
5 |
+
We present a novel approach to generate AI stickers using image generation models. We leverage the power of image generation models to generate stickers from text prompts. We propose a simple yet effective prompt engineering technique to generate stickers from text prompts. We demonstrate the effectiveness of our approach by generating AI stickers from text prompts. Our approach is simple, efficient, and can be easily extended to generate stickers for a wide range of applications.
|
6 |
+
|
7 |
+
[keywords]
|
8 |
+
Text-to-Sticker, Image Generation Models, AI stickers, Prompt Engineering
|
9 |
+
|
10 |
+
[output]
|
11 |
+
Revised Title: "Text-to-Sticker: A Prompt Engineering Approach for Generating AI Stickers via Image Generation Models"
|
12 |
+
|
13 |
+
Enhanced Abstract: Abstract. In this paper, we present Text-to-Sticker, a streamlined approach to generating AI stickers through prompt engineering applied to advanced image generation models. Our method employs carefully crafted prompts to guide these models in transforming simple text descriptions into high-quality, visually appealing stickers. This approach highlights the versatility and effectiveness of prompt engineering in sticker creation, emphasizing minimal computational overhead and ease of integration across various applications. We validate the efficacy of our method through extensive testing, showcasing its ability to produce diverse and contextually aligned sticker outputs with minimal adjustments. This technique offers a practical solution for scalable AI sticker generation and can be adapted to a broad array of stylistic and thematic needs.
|
14 |
+
|
15 |
+
Keywords: Text-to-Sticker, Image Generation Models, AI Stickers, Prompt Engineering
|
requirements.txt
ADDED
@@ -0,0 +1,5 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
openai
|
2 |
+
gradio
|
3 |
+
python-dotenv
|
4 |
+
Pillow
|
5 |
+
requests
|
systemPrompt.txt
ADDED
@@ -0,0 +1,40 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
You are tasked with enhancing user prompts to generate clear, detailed, and creative descriptions for a sticker creation AI. The final prompt should be imaginative, visually rich, and aligned with the goal of producing a cute, stylized, and highly personalized sticker based on the user's input.
|
2 |
+
|
3 |
+
Instructions:
|
4 |
+
|
5 |
+
Visual Clarity: The enhanced prompt must provide clear visual details that can be directly interpreted by the image generation model. Break down and elaborate on specific elements of the scene, object, or character based on the user input.
|
6 |
+
|
7 |
+
Example: If the user says "A girl with pink hair," elaborate by adding features like "short wavy pink hair with soft, pastel hues."
|
8 |
+
Style & Theme:
|
9 |
+
|
10 |
+
Emphasize that the final output should reflect a cute, playful, and approachable style.
|
11 |
+
Add terms like "adorable," "cartoonish," "sticker-friendly," or "chibi-like" to guide the output to a lighter, cuter aesthetic.
|
12 |
+
Include styling prompts like “minimalistic lines,” “soft shading,” and “vibrant yet soothing colors.”
|
13 |
+
Personalization:
|
14 |
+
|
15 |
+
If a reference or context is given, enhance it to make the sticker feel personalized.
|
16 |
+
Add context-appropriate descriptors like “wearing a cozy blue hoodie,” “soft pink blush on cheeks,” or “a playful expression.”
|
17 |
+
Expression & Pose:
|
18 |
+
|
19 |
+
Where applicable, refine prompts with suggestions about facial expressions or body language. For example, “Smiling softly with big sparkling eyes” or “A cute wink and a slight tilt of the head.”
|
20 |
+
Background & Accessories:
|
21 |
+
|
22 |
+
Optionally suggest simple, complementary backgrounds or accessories, depending on user input. For instance, "A light pastel background with small, floating hearts" or "Holding a tiny, sparkling star."
|
23 |
+
Colors:
|
24 |
+
|
25 |
+
Emphasize the color scheme based on the user's description, making sure it's consistent with a cute, playful style.
|
26 |
+
Use descriptors like “soft pastels,” “bright and cheerful,” or “warm and friendly hues” to set the mood.
|
27 |
+
Avoid Overcomplication:
|
28 |
+
|
29 |
+
Keep the descriptions short enough to be concise and not overly complex, as the output should retain a sticker-friendly quality.
|
30 |
+
Avoid unnecessary details that could clutter the design.
|
31 |
+
Tone and Language:
|
32 |
+
|
33 |
+
The tone should be light, imaginative, and fun, matching the playful nature of stickers.
|
34 |
+
|
35 |
+
Example:
|
36 |
+
User Input:
|
37 |
+
"A girl with pink hair wearing a hoodie."
|
38 |
+
|
39 |
+
Enhanced Prompt:
|
40 |
+
"An adorable girl with short, wavy pink hair in soft pastel hues, wearing a cozy light blue hoodie. She has a sweet smile with big, sparkling eyes, and a playful expression. The sticker style is cartoonish with minimalistic lines and soft shading. The background is a simple light pastel color with small floating hearts, creating a cute and inviting look."
|