Spaces:
Sleeping
Sleeping
mrolando
commited on
Commit
•
771872b
1
Parent(s):
3eb588a
first commit
Browse files- .gitignore +2 -0
- .vscode/settings.json +7 -0
- Iso_Logotipo_Ceibal.png +0 -0
- app.py +69 -0
.gitignore
ADDED
@@ -0,0 +1,2 @@
|
|
|
|
|
|
|
1 |
+
.env
|
2 |
+
env
|
.vscode/settings.json
ADDED
@@ -0,0 +1,7 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
{
|
2 |
+
"python.analysis.typeCheckingMode": "basic",
|
3 |
+
"[python]": {
|
4 |
+
"editor.defaultFormatter": "ms-python.black-formatter"
|
5 |
+
},
|
6 |
+
"python.formatting.provider": "none"
|
7 |
+
}
|
Iso_Logotipo_Ceibal.png
ADDED
app.py
ADDED
@@ -0,0 +1,69 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
import gradio as gr
|
2 |
+
from dotenv import load_dotenv
|
3 |
+
|
4 |
+
# Load environment variables from the .env file de forma local
|
5 |
+
load_dotenv()
|
6 |
+
import base64
|
7 |
+
|
8 |
+
with open("Iso_Logotipo_Ceibal.png", "rb") as image_file:
|
9 |
+
encoded_image = base64.b64encode(image_file.read()).decode()
|
10 |
+
|
11 |
+
import os
|
12 |
+
import openai
|
13 |
+
|
14 |
+
openai.api_key = os.environ["OPENAI_API_KEY"]
|
15 |
+
|
16 |
+
|
17 |
+
def get_image(text: str):
|
18 |
+
response = openai.Image.create(prompt=text, n=1, size="512x512") #,response_format="b64_json"
|
19 |
+
print(response['data'][0]['url']) # type: ignore
|
20 |
+
return response['data'][0]['url']# type: ignore
|
21 |
+
|
22 |
+
|
23 |
+
with gr.Blocks() as demo:
|
24 |
+
gr.Markdown(
|
25 |
+
"""
|
26 |
+
<center>
|
27 |
+
<h1>
|
28 |
+
Uso de AI para la generación de imagenes a partir de texto.
|
29 |
+
</h1>
|
30 |
+
<img src='data:image/jpg;base64,{}' width=200px>
|
31 |
+
<h2>
|
32 |
+
Con este espacio podrás generar imagenes a partir de texto. Utiliza el modelo DALL-E de OpenAI.
|
33 |
+
</h2>
|
34 |
+
<h2>
|
35 |
+
Obtendrás mejores resultados cuanto más larga sea la descripción.
|
36 |
+
</h2>
|
37 |
+
|
38 |
+
</center>
|
39 |
+
""".format(
|
40 |
+
encoded_image
|
41 |
+
)
|
42 |
+
)
|
43 |
+
with gr.Row():
|
44 |
+
with gr.Column():
|
45 |
+
gr.Markdown("Primero debes ingresar el texto para generar la imagen:")
|
46 |
+
with gr.Row():
|
47 |
+
with gr.Column(scale=4):
|
48 |
+
prompt = gr.Textbox(
|
49 |
+
label="Texo base para generar la imagen"
|
50 |
+
) # Give prompt some real estate
|
51 |
+
with gr.Column(scale=1, min_width=50):
|
52 |
+
btn = gr.Button("Generar") # Submit button side by side!
|
53 |
+
|
54 |
+
with gr.Column():
|
55 |
+
output = gr.Image(
|
56 |
+
label="Resultado", height=512, width=512
|
57 |
+
) # Move the output up too
|
58 |
+
# examples = gr.Examples(
|
59 |
+
# inputs=[prompt]
|
60 |
+
# examples=[["Un perro en el parque", "low quality"]],
|
61 |
+
# )
|
62 |
+
|
63 |
+
btn.click(
|
64 |
+
fn=get_image,
|
65 |
+
inputs=prompt,
|
66 |
+
outputs=[output],
|
67 |
+
) # steps,guidance,width,height]
|
68 |
+
|
69 |
+
demo.launch(debug=True)
|