gradio/demo/fake_gan_2/run.ipynb
aliabid94 9b42ba8f10
Update guides esp plots (#8907)
* changes

* changes

* revert changes

* changes

* add changeset

* notebooks script

* changes

* changes

---------

Co-authored-by: Ali Abid <aliabid94@gmail.com>
Co-authored-by: gradio-pr-bot <gradio-pr-bot@users.noreply.github.com>
Co-authored-by: Ali Abdalla <ali.si3luwa@gmail.com>
2024-07-29 22:08:51 -07:00

2.1 KiB

Gradio Demo: fake_gan_2

In [ ]:
!pip install -q gradio 
In [ ]:
# Downloading files from the demo repo
import os
os.mkdir('files')
!wget -q -O files/cheetah1.jpg https://github.com/gradio-app/gradio/raw/main/demo/fake_gan_2/files/cheetah1.jpg
!wget -q -O files/elephant.jpg https://github.com/gradio-app/gradio/raw/main/demo/fake_gan_2/files/elephant.jpg
!wget -q -O files/tiger.jpg https://github.com/gradio-app/gradio/raw/main/demo/fake_gan_2/files/tiger.jpg
!wget -q -O files/zebra.jpg https://github.com/gradio-app/gradio/raw/main/demo/fake_gan_2/files/zebra.jpg
In [ ]:
# This demo needs to be run from the repo folder.
# python demo/fake_gan/run.py
import random
import time

import gradio as gr

def fake_gan(desc):
    if desc == "NSFW":
        raise gr.Error("NSFW - banned content.")
    if desc == "error":
        raise ValueError("error")
    time.sleep(9)
    image = random.choice(
        [
            "files/cheetah1.jpg",
            "files/elephant.jpg",
            "files/tiger.jpg",
            "files/zebra.jpg",
        ]
    )
    return image

demo = gr.Interface(
    fn=fake_gan,
    inputs=gr.Textbox(),
    outputs=gr.Image(label="Generated Image"),
    title="FD-GAN",
    description="This is a fake demo of a GAN. In reality, the images are randomly chosen from Unsplash.",
)
demo.queue(max_size=3)

if __name__ == "__main__":
    demo.launch()