Last active
May 20, 2025 16:29
-
-
Save rafaelpontezup/4f0a7a0d69df29c82ca05eeeb9505704 to your computer and use it in GitHub Desktop.
Future Minds: Colinha
This file contains hidden or 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
import base64 | |
import os | |
from dotenv import load_dotenv | |
from openai import OpenAI | |
# Importa API KEY | |
load_dotenv() | |
api_key = os.getenv("OPENAI_API_KEY") | |
# Cria OpenAI client | |
client = OpenAI(api_key=api_key) | |
## | |
# Prompt (text) | |
## | |
print("💬 OpenAI Text") | |
response = client.responses.create( | |
model="gpt-4o-mini", | |
input="""Gere uma história com os seguintes temas | |
- Escola | |
- Amigos | |
""", | |
instructions=""" | |
Você é uma escritora especialista em literatura infantil. | |
Você irá criar histórias curtas entre 9 e 12 linhas baseadas nos temas informados pelo usuário. | |
Você tem um tom didático, descomplicado e amigável. | |
""", | |
temperature=1.2 | |
) | |
historia = response.output_text | |
print(historia) | |
with open("historia-text.txt", "w", encoding="utf-8") as file: | |
file.write(historia) | |
## | |
# Prompt (audio) | |
## | |
print("🎧 OpenAI Audio") | |
with client.audio.speech.with_streaming_response.create( | |
model="gpt-4o-mini-tts", | |
voice="fable", | |
input=historia, | |
instructions="Fale com tom descomplicado e amigável digirido para uma criança.", | |
response_format="mp3" | |
) as response: | |
response.stream_to_file("historia-audio.mp3") | |
## | |
# Prompt (image) | |
## | |
print("🖼️ OpenAI Images") | |
response = client.images.generate( | |
model="gpt-image-1", | |
prompt=f""" | |
Gere uma imagem ficticia baseada na história infantil abaixo. | |
A imagem deve contar a história através de ilustrações inspiradas no texto. | |
A imagem deve usar um estilo de ilustração infantil. | |
<historia> | |
{historia} | |
</historia> | |
""", | |
quality="high" | |
) | |
image_base64 = response.data[0].b64_json | |
image_bytes = base64.b64decode(image_base64) | |
with open("historia-image.png", "wb") as f: | |
f.write(image_bytes) | |
This file contains hidden or 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
import base64 | |
import os | |
from dotenv import load_dotenv | |
from openai import OpenAI | |
# Importa API KEY | |
load_dotenv() | |
api_key = os.getenv("OPENAI_API_KEY") | |
# Cria OpenAI client | |
client = OpenAI(api_key=api_key) | |
## | |
# Prompt (image) | |
## | |
print("🖼️ OpenAI Images | Studio Ghibli") | |
image_file = "eu-em-milao.jpg" | |
response = client.images.edit( | |
model="gpt-image-1", | |
prompt="Transforme essa imagem em uma ilustração parecida com os desenhos do studio Ghibli.", | |
image=open(image_file, "rb"), | |
) | |
image_base64 = response.data[0].b64_json | |
image_bytes = base64.b64decode(image_base64) | |
with open(f"{image_file}-ghibli.png", "wb") as f: | |
f.write(image_bytes) | |
This file contains hidden or 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
response = client.images.generate( | |
model="dall-e-3", | |
prompt=f""" | |
Gere uma imagem ficticia baseada na história infantil abaixo. | |
A imagem deve contar a história através de ilustrações inspiradas no texto. | |
A imagem deve usar um estilo de ilustração infantil. | |
<historia> | |
{historia} | |
</historia> | |
""", | |
quality="standard", | |
response_format="b64_json", | |
) | |
image_base64 = response.data[0].b64_json | |
image_bytes = base64.b64decode(image_base64) | |
with open("historia-image.png", "wb") as f: | |
f.write(image_bytes) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment