mrolando
first commit
771872b
raw history blame
No virus
2.03 kB
import gradio as gr
from dotenv import load_dotenv
# Load environment variables from the .env file de forma local
load_dotenv()
import base64
with open("Iso_Logotipo_Ceibal.png", "rb") as image_file:
encoded_image = base64.b64encode(image_file.read()).decode()
import os
import openai
openai.api_key = os.environ["OPENAI_API_KEY"]
def get_image(text: str):
response = openai.Image.create(prompt=text, n=1, size="512x512") #,response_format="b64_json"
print(response['data'][0]['url']) # type: ignore
return response['data'][0]['url']# type: ignore
with gr.Blocks() as demo:
gr.Markdown(
"""
<center>
<h1>
Uso de AI para la generación de imagenes a partir de texto.
</h1>
<img src='data:image/jpg;base64,{}' width=200px>
<h2>
Con este espacio podrás generar imagenes a partir de texto. Utiliza el modelo DALL-E de OpenAI.
</h2>
<h2>
Obtendrás mejores resultados cuanto más larga sea la descripción.
</h2>
</center>
""".format(
encoded_image
)
)
with gr.Row():
with gr.Column():
gr.Markdown("Primero debes ingresar el texto para generar la imagen:")
with gr.Row():
with gr.Column(scale=4):
prompt = gr.Textbox(
label="Texo base para generar la imagen"
) # Give prompt some real estate
with gr.Column(scale=1, min_width=50):
btn = gr.Button("Generar") # Submit button side by side!
with gr.Column():
output = gr.Image(
label="Resultado", height=512, width=512
) # Move the output up too
# examples = gr.Examples(
# inputs=[prompt]
# examples=[["Un perro en el parque", "low quality"]],
# )
btn.click(
fn=get_image,
inputs=prompt,
outputs=[output],
) # steps,guidance,width,height]
demo.launch(debug=True)