mrolando commited on
Commit
0efebd7
1 Parent(s): dd605bc

added check

Browse files
Files changed (1) hide show
  1. app.py +25 -4
app.py CHANGED
@@ -1,5 +1,6 @@
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()
@@ -14,12 +15,26 @@ import openai
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
  """
@@ -42,7 +57,13 @@ with gr.Blocks() as demo:
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(
@@ -62,7 +83,7 @@ with gr.Blocks() as demo:
62
 
63
  btn.click(
64
  fn=get_image,
65
- inputs=prompt,
66
  outputs=[output],
67
  ) # steps,guidance,width,height]
68
 
 
1
  import gradio as gr
2
  from dotenv import load_dotenv
3
+ from transformers import pipeline
4
 
5
  # Load environment variables from the .env file de forma local
6
  load_dotenv()
 
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(translate):
29
+ text = translate_text(text)
30
  response = openai.Image.create(prompt=text, n=1, size="512x512") #,response_format="b64_json"
31
+ print(text)
32
  return response['data'][0]['url']# type: ignore
33
 
34
 
35
+
36
+
37
+
38
  with gr.Blocks() as demo:
39
  gr.Markdown(
40
  """
 
57
  )
58
  with gr.Row():
59
  with gr.Column():
60
+
61
+ with gr.Row():
62
+ gr.Markdown("El modelo funciona mejor con entradas en inglés, podés elegir traducir al inglés con este check:")
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:")
66
+
67
  with gr.Row():
68
  with gr.Column(scale=4):
69
  prompt = gr.Textbox(
 
83
 
84
  btn.click(
85
  fn=get_image,
86
+ inputs=[prompt,check],
87
  outputs=[output],
88
  ) # steps,guidance,width,height]
89