Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
@@ -54,7 +54,6 @@ def sd2_inference(pipeline, prompts, params, seed = 42, num_inference_steps = 50
|
|
54 |
HF_ACCESS_TOKEN = os.environ["HFAUTH"]
|
55 |
|
56 |
# Load Model
|
57 |
-
# - Reference: https://github.com/huggingface/diffusers/blob/main/README.md
|
58 |
pipeline, params = FlaxStableDiffusionPipeline.from_pretrained(
|
59 |
"CompVis/stable-diffusion-v1-4",
|
60 |
use_auth_token = HF_ACCESS_TOKEN,
|
@@ -73,7 +72,6 @@ model = FlaxVisionEncoderDecoderModel.from_pretrained(loc)
|
|
73 |
gen_kwargs = {"max_length": 16, "num_beams": 4}
|
74 |
|
75 |
|
76 |
-
# This takes sometime when compiling the first time, but the subsequent inference will be much faster
|
77 |
|
78 |
def generate(pixel_values):
|
79 |
output_ids = model.generate(pixel_values, **gen_kwargs).sequences
|
@@ -95,11 +93,11 @@ def image2text(image):
|
|
95 |
|
96 |
|
97 |
def text_to_image_and_image_to_text(text=None,image=None):
|
98 |
-
txt=
|
99 |
img=None
|
100 |
if image != None:
|
101 |
txt=image2text(image)
|
102 |
-
if text !=
|
103 |
images = sd2_inference(pipeline, [text], params, seed = 42, num_inference_steps = 5 )
|
104 |
img = images[0]
|
105 |
return img,txt
|
@@ -107,7 +105,7 @@ def text_to_image_and_image_to_text(text=None,image=None):
|
|
107 |
|
108 |
if __name__ == '__main__':
|
109 |
interFace = gr.Interface(fn=text_to_image_and_image_to_text,
|
110 |
-
inputs=[gr.inputs.Textbox(placeholder="Enter the text to Encode to an image",
|
111 |
outputs=[gr.outputs.Image(type="pil", label="Encoded Image"),gr.outputs.Textbox( label="Decoded Text")],
|
112 |
title="T2I2T: Text2Image2Text imformation transmiter",
|
113 |
description="⭐️The next generation of QR codes, an information sharing tool via images⭐️ Error rates are high & Image generation takes about 200 seconds.",
|
|
|
54 |
HF_ACCESS_TOKEN = os.environ["HFAUTH"]
|
55 |
|
56 |
# Load Model
|
|
|
57 |
pipeline, params = FlaxStableDiffusionPipeline.from_pretrained(
|
58 |
"CompVis/stable-diffusion-v1-4",
|
59 |
use_auth_token = HF_ACCESS_TOKEN,
|
|
|
72 |
gen_kwargs = {"max_length": 16, "num_beams": 4}
|
73 |
|
74 |
|
|
|
75 |
|
76 |
def generate(pixel_values):
|
77 |
output_ids = model.generate(pixel_values, **gen_kwargs).sequences
|
|
|
93 |
|
94 |
|
95 |
def text_to_image_and_image_to_text(text=None,image=None):
|
96 |
+
txt=""
|
97 |
img=None
|
98 |
if image != None:
|
99 |
txt=image2text(image)
|
100 |
+
if text !="":
|
101 |
images = sd2_inference(pipeline, [text], params, seed = 42, num_inference_steps = 5 )
|
102 |
img = images[0]
|
103 |
return img,txt
|
|
|
105 |
|
106 |
if __name__ == '__main__':
|
107 |
interFace = gr.Interface(fn=text_to_image_and_image_to_text,
|
108 |
+
inputs=[gr.inputs.Textbox(placeholder="Enter the text to Encode to an image", label="Text to Encode to Image ",lines=1,optional=True),gr.Image(type="pil",label="Image to Decode to text",optional=True)],
|
109 |
outputs=[gr.outputs.Image(type="pil", label="Encoded Image"),gr.outputs.Textbox( label="Decoded Text")],
|
110 |
title="T2I2T: Text2Image2Text imformation transmiter",
|
111 |
description="⭐️The next generation of QR codes, an information sharing tool via images⭐️ Error rates are high & Image generation takes about 200 seconds.",
|