mirror of
https://github.com/gradio-app/gradio.git
synced 2024-12-15 02:11:15 +08:00
ef3862e075
* Sort requirements.in * Switch flake8 + isort to ruff * Apply ruff import order fixes * Fix ruff complaints in demo/ * Fix ruff complaints in test/ * Use `x is not y`, not `not x is y` * Remove unused listdir from website generator * Clean up duplicate dict keys * Add changelog entry * Clean up unused imports (except in gradio/__init__.py) * add space --------- Co-authored-by: Abubakar Abid <abubakar@huggingface.co>
37 lines
807 B
Python
37 lines
807 B
Python
# 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()
|