Spaces:
Running
Running
mrolando
commited on
Commit
·
6a1d099
1
Parent(s):
ce4bc91
trying multithread
Browse files
app.py
CHANGED
@@ -15,24 +15,23 @@ import openai
|
|
15 |
openai.api_key = os.environ["OPENAI_API_KEY"]
|
16 |
|
17 |
|
|
|
18 |
|
19 |
|
20 |
-
es_en_translator = pipeline("translation",model = "Helsinki-NLP/opus-mt-es-en")
|
21 |
def translate_text(text):
|
22 |
-
text = es_en_translator(text)[0].get("translation_text") #type: ignore
|
23 |
return text
|
24 |
|
25 |
|
26 |
-
def get_image(text: str,translate: bool):
|
27 |
print(text)
|
28 |
-
if
|
29 |
text = translate_text(text)
|
30 |
-
response = openai.Image.create(
|
31 |
-
|
32 |
-
|
33 |
-
|
34 |
-
|
35 |
-
|
36 |
|
37 |
|
38 |
with gr.Blocks() as demo:
|
@@ -57,9 +56,10 @@ with gr.Blocks() as demo:
|
|
57 |
)
|
58 |
with gr.Row():
|
59 |
with gr.Column():
|
60 |
-
|
61 |
with gr.Row():
|
62 |
-
gr.Markdown(
|
|
|
|
|
63 |
check = gr.Checkbox(label="Traducir al inglés")
|
64 |
with gr.Row():
|
65 |
gr.Markdown("Primero debes ingresar el texto para generar la imagen:")
|
@@ -71,7 +71,7 @@ with gr.Blocks() as demo:
|
|
71 |
) # Give prompt some real estate
|
72 |
with gr.Column(scale=1, min_width=50):
|
73 |
btn = gr.Button("Generar") # Submit button side by side!
|
74 |
-
|
75 |
with gr.Column():
|
76 |
output = gr.Image(
|
77 |
label="Resultado", height=512, width=512
|
@@ -83,8 +83,8 @@ with gr.Blocks() as demo:
|
|
83 |
|
84 |
btn.click(
|
85 |
fn=get_image,
|
86 |
-
inputs=[prompt,check],
|
87 |
outputs=[output],
|
88 |
) # steps,guidance,width,height]
|
89 |
-
|
90 |
-
demo.launch(debug=True)
|
|
|
15 |
openai.api_key = os.environ["OPENAI_API_KEY"]
|
16 |
|
17 |
|
18 |
+
es_en_translator = pipeline("translation", model="Helsinki-NLP/opus-mt-es-en")
|
19 |
|
20 |
|
|
|
21 |
def translate_text(text):
|
22 |
+
text = es_en_translator(text)[0].get("translation_text") # type: ignore
|
23 |
return text
|
24 |
|
25 |
|
26 |
+
def get_image(text: str, translate: bool):
|
27 |
print(text)
|
28 |
+
if translate:
|
29 |
text = translate_text(text)
|
30 |
+
response = openai.Image.create(
|
31 |
+
prompt=text, n=1, size="512x512"
|
32 |
+
) # ,response_format="b64_json"
|
33 |
+
print(response)
|
34 |
+
return response["data"][0]["url"] # type: ignore
|
|
|
35 |
|
36 |
|
37 |
with gr.Blocks() as demo:
|
|
|
56 |
)
|
57 |
with gr.Row():
|
58 |
with gr.Column():
|
|
|
59 |
with gr.Row():
|
60 |
+
gr.Markdown(
|
61 |
+
"El modelo funciona mejor con entradas en inglés, podés elegir traducir al inglés con este check:"
|
62 |
+
)
|
63 |
check = gr.Checkbox(label="Traducir al inglés")
|
64 |
with gr.Row():
|
65 |
gr.Markdown("Primero debes ingresar el texto para generar la imagen:")
|
|
|
71 |
) # Give prompt some real estate
|
72 |
with gr.Column(scale=1, min_width=50):
|
73 |
btn = gr.Button("Generar") # Submit button side by side!
|
74 |
+
|
75 |
with gr.Column():
|
76 |
output = gr.Image(
|
77 |
label="Resultado", height=512, width=512
|
|
|
83 |
|
84 |
btn.click(
|
85 |
fn=get_image,
|
86 |
+
inputs=[prompt, check],
|
87 |
outputs=[output],
|
88 |
) # steps,guidance,width,height]
|
89 |
+
demo.queue(concurrency_count=2)
|
90 |
+
demo.launch(debug=True)
|