CoolFace
Apppublic

ankush-003/Image-Data-Generator

sourceHugging Faceupdated 3y agoView on Hugging Face
0likes
app.py65 linesDownload Raw Back to root
1import numpy as np2import matplotlib.pyplot as plt3from diffusers import DiffusionPipeline4 5# Load the pre-trained model6pipeline = DiffusionPipeline.from_pretrained("ankush-003/retinal_fundus")7# pipeline.to("cuda")8# gradio function for generating image9def generate_image():10    image = pipeline().images[0]11    image.save("trial.png")12    img = plt.imread("trial.png")13    # Display the image (optional)14    # plt.imshow(img)15    # plt.axis("off")16    # plt.show()17    return img18 19# gradio interface20# import gradio as gr21# iface = gr.Interface(fn=generate_image, inputs=None, outputs=[gr.Image(label="Generated Image", type="numpy", tool='editor')],22#                 title="Image Data Generator",23#                 description="This tool generates synthetic images using the DiffusionPipeline model.",24#                 article="### Using the Image Data Generator\n\nSimply click 'Generate Image' to create a synthetic image. The generated image will be displayed below.")25# iface.launch(debug=True)26 27# blocks ui28import gradio as gr29 30def generate_multiple(num):31    images = []32    for i in range(num):33      images.append(generate_image())34    return images    35 36with gr.Blocks(theme=gr.themes.Soft()) as app:37    gr.Markdown("""<h1 style="text-align: center;">Synthetic Image Generator</h1>""")38    39    with gr.Tab("Generate Single Image"):40      with gr.Row():41        with gr.Column():42          gr.Markdown("""## Using the Synthetic Image Generator\n\nSimply click 'Generate Image' to create a synthetic image.\n""")43          gr.Image("./train.png",label="Training Image sample").style( rounded=True, scale=1)44          gen_button = gr.Button("Generate", variant="primary")45        gen_img = gr.Image( tool="select", type="numpy", label="Generated Image").style(height=512, width=512, rounded=True)46 47    with gr.Tab("Generate Multiple Images"):48      gr.Markdown(49          """50          ## Using the Synthetic Image Generator to generate multiple images51          """52      )53      gen_number = gr.Slider(2, 5, step=1.0, label="Number of Images", info="Generate multiple images")54      gen_images = gr.Gallery(label="Generated Images").style(columns=[2], rows=[2], object_fit="contain", height="auto")55      gen_m_button = gr.Button("Generate Images", variant="primary")56        57    with gr.Accordion("Read More"):58        gr.Markdown("""59        - [Images used to train the model](https://ieee-dataport.org/open-access/retinal-fundus-multi-disease-image-dataset-rfmid)60        """)61 62    gen_button.click(generate_image, inputs=None, outputs=gen_img)63    gen_m_button.click(generate_multiple, inputs=gen_number, outputs=gen_images)64    65app.launch(debug=True)