Spaces:
Runtime error
Runtime error
mrolando
commited on
Commit
•
24f2f30
1
Parent(s):
3f285ec
added dalle3
Browse files- .gitignore +2 -1
- app.py +22 -14
- img.png +0 -0
.gitignore
CHANGED
@@ -1,2 +1,3 @@
|
|
1 |
.env
|
2 |
-
env
|
|
|
|
1 |
.env
|
2 |
+
env
|
3 |
+
/venv
|
app.py
CHANGED
@@ -12,9 +12,7 @@ with open("Iso_Logotipo_Ceibal.png", "rb") as image_file:
|
|
12 |
encoded_image = base64.b64encode(image_file.read()).decode()
|
13 |
|
14 |
import os
|
15 |
-
import
|
16 |
-
|
17 |
-
openai.api_key = os.environ["OPENAI_API_KEY"]
|
18 |
|
19 |
|
20 |
es_en_translator = pipeline("translation", model="Helsinki-NLP/opus-mt-es-en")
|
@@ -25,20 +23,29 @@ def translate_text(text):
|
|
25 |
return text
|
26 |
|
27 |
|
|
|
|
|
|
|
|
|
|
|
28 |
def get_image(text: str, translate: bool):
|
29 |
print(text)
|
30 |
if translate:
|
31 |
text = translate_text(text)
|
32 |
-
response =
|
33 |
-
|
|
|
|
|
|
|
|
|
34 |
) # ,response_format="b64_json"
|
35 |
print(response)
|
36 |
|
37 |
-
urllib.request.urlretrieve(response
|
38 |
|
39 |
img = Image.open("img.png")
|
40 |
|
41 |
-
return img
|
42 |
|
43 |
# return response["data"][0]["url"] # type: ignore
|
44 |
|
@@ -52,11 +59,11 @@ with gr.Blocks() as demo:
|
|
52 |
</h1>
|
53 |
<img src='data:image/jpg;base64,{}' width=200px>
|
54 |
<h2>
|
55 |
-
Con este espacio podrás generar imagenes a partir de texto. Utiliza el modelo DALL-E de OpenAI.
|
56 |
-
</h2>
|
57 |
-
<h2>
|
58 |
-
Obtendrás mejores resultados cuanto más larga sea la descripción.
|
59 |
</h2>
|
|
|
|
|
|
|
60 |
|
61 |
</center>
|
62 |
""".format(
|
@@ -82,8 +89,9 @@ with gr.Blocks() as demo:
|
|
82 |
btn = gr.Button("Generar") # Submit button side by side!
|
83 |
|
84 |
with gr.Column():
|
|
|
85 |
output = gr.Image(
|
86 |
-
label="Resultado", height=
|
87 |
) # Move the output up too
|
88 |
# examples = gr.Examples(
|
89 |
# inputs=[prompt]
|
@@ -93,7 +101,7 @@ with gr.Blocks() as demo:
|
|
93 |
btn.click(
|
94 |
fn=get_image,
|
95 |
inputs=[prompt, check],
|
96 |
-
outputs=[output],
|
97 |
) # steps,guidance,width,height]
|
98 |
-
demo.queue(
|
99 |
demo.launch(debug=True)
|
|
|
12 |
encoded_image = base64.b64encode(image_file.read()).decode()
|
13 |
|
14 |
import os
|
15 |
+
from openai import OpenAI
|
|
|
|
|
16 |
|
17 |
|
18 |
es_en_translator = pipeline("translation", model="Helsinki-NLP/opus-mt-es-en")
|
|
|
23 |
return text
|
24 |
|
25 |
|
26 |
+
client = OpenAI()
|
27 |
+
|
28 |
+
client.api_key = os.environ["OPENAI_API_KEY"]
|
29 |
+
|
30 |
+
|
31 |
def get_image(text: str, translate: bool):
|
32 |
print(text)
|
33 |
if translate:
|
34 |
text = translate_text(text)
|
35 |
+
response = client.images.generate(
|
36 |
+
model="dall-e-3",
|
37 |
+
prompt="a white siamese cat",
|
38 |
+
size="1024x1024",
|
39 |
+
quality="standard",
|
40 |
+
n=1,
|
41 |
) # ,response_format="b64_json"
|
42 |
print(response)
|
43 |
|
44 |
+
urllib.request.urlretrieve(response.data[0].url, "img.png") # type: ignore
|
45 |
|
46 |
img = Image.open("img.png")
|
47 |
|
48 |
+
return img, response.data[0].revised_prompt
|
49 |
|
50 |
# return response["data"][0]["url"] # type: ignore
|
51 |
|
|
|
59 |
</h1>
|
60 |
<img src='data:image/jpg;base64,{}' width=200px>
|
61 |
<h2>
|
62 |
+
Con este espacio podrás generar imagenes a partir de texto. Utiliza el modelo DALL-E 3 de OpenAI.
|
|
|
|
|
|
|
63 |
</h2>
|
64 |
+
<h3>
|
65 |
+
Tenés que tener en cuenta que el modelo ahora toma el mensaje predeterminado proporcionado y lo reescribe automáticamente por razones de seguridad y para agregar más detalles reescribe el prompt dado. Para
|
66 |
+
</h3>
|
67 |
|
68 |
</center>
|
69 |
""".format(
|
|
|
89 |
btn = gr.Button("Generar") # Submit button side by side!
|
90 |
|
91 |
with gr.Column():
|
92 |
+
text_output = gr.TextArea(label="Prompt revisado por el modelo:")
|
93 |
output = gr.Image(
|
94 |
+
label="Resultado", height=1024, width=1024
|
95 |
) # Move the output up too
|
96 |
# examples = gr.Examples(
|
97 |
# inputs=[prompt]
|
|
|
101 |
btn.click(
|
102 |
fn=get_image,
|
103 |
inputs=[prompt, check],
|
104 |
+
outputs=[output, text_output],
|
105 |
) # steps,guidance,width,height]
|
106 |
+
demo.queue()
|
107 |
demo.launch(debug=True)
|
img.png
DELETED
Binary file (787 kB)
|
|