File size: 684 Bytes
351a99e
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
import gradio as gr


def generate_image(input_text):
    """Generates an image from the input text."""

    # Generate the image
    image = ...

    # Convert the image to a base64 string
    base64_string = base64.b64encode(image.tobytes())

    # Return the base64 string
    return base64_string


def download_image(base64_string):
    """Downloads the output image as a .png file."""

    filename = "image.png"
    with open(filename, "wb") as f:
        f.write(base64.b64decode(base64_string))

    # Allow the user to download the file
    gr.File.download(filename)


if __name__ == "__main__":
    gr.Interface(fn=generate_image, inputs="text", outputs="image").launch()