|
import argparse |
|
import binascii |
|
import glob |
|
import os |
|
import os.path |
|
import numpy as np |
|
import matplotlib.pyplot as plt |
|
import random |
|
import sys |
|
import tempfile |
|
import time |
|
import torch |
|
from PIL import Image |
|
from diffusers import StableDiffusionPipeline |
|
|
|
import gradio as gr |
|
|
|
import artist_lib |
|
|
|
from dotenv import load_dotenv |
|
load_dotenv() |
|
SERVER_NAME = os.getenv("SERVER_NAME") |
|
|
|
drawdemo = gr.Interface( |
|
fn=artist_lib.draw, |
|
inputs=[ |
|
gr.Text(label="Drawing description text", value="hindu mandala neon orange and blue"), |
|
gr.Dropdown(label='Model', choices=["stable-diffusion-2", "stable-diffusion-2-1", "stable-diffusion-v1-5"], value="stable-diffusion-v1-5"), |
|
gr.Checkbox(label="Force-New"), |
|
], |
|
outputs="image", |
|
examples=[ |
|
['van gogh dogs playing poker', "stable-diffusion-v1-5", False], |
|
['picasso the scream', "stable-diffusion-v1-5", False], |
|
['dali american gothic', "stable-diffusion-v1-5", False], |
|
['matisse mona lisa', "stable-diffusion-v1-5", False], |
|
['maxfield parrish angel in lake ', "stable-diffusion-v1-5", False], |
|
['peter max dogs playing poker', "stable-diffusion-v1-5", False], |
|
['hindu mandala copper and patina green', "stable-diffusion-v1-5", False], |
|
['hindu mandala fruit salad', "stable-diffusion-v1-5", False], |
|
['hindu mandala neon green black and purple', "stable-diffusion-v1-5", False], |
|
['astronaut riding a horse on mars', "stable-diffusion-v1-5", False] |
|
], |
|
) |
|
|
|
AudioDemo = gr.Interface( |
|
fn=artist_lib.generate_tone, |
|
inputs=[ |
|
gr.Dropdown(artist_lib.notes, type="index"), |
|
gr.Slider(4, 6, step=1), |
|
gr.Textbox(value=1, label="Duration in seconds") |
|
], |
|
outputs="audio" |
|
) |
|
|
|
imageClassifierDemo = gr.Interface( |
|
fn=artist_lib.imageClassifier, |
|
inputs="image", |
|
outputs="text" |
|
) |
|
|
|
audioGeneratorDemo = gr.Interface( |
|
fn=artist_lib.audioGenerator, |
|
inputs="text", |
|
outputs="audio", |
|
examples=[ |
|
['balsamic beats'], |
|
['dance the night away'] |
|
] |
|
) |
|
|
|
nameMyPetDemo = gr.Interface( |
|
fn=artist_lib.nameMyPet, |
|
inputs=[ |
|
gr.Text(label="What type of animal is your pet?", value="green cat") |
|
], |
|
outputs="text", |
|
examples=[ |
|
['dog'], |
|
['pink dolphin'], |
|
['elevated elephant'], |
|
['green monkey'], |
|
['bionic beaver'], |
|
['felonous fish'], |
|
['delinquent dog'], |
|
['dragging donkey'], |
|
['stinky skunk'], |
|
['pink unicorn'], |
|
['naughty narwahl'], |
|
['blue cat'] |
|
], |
|
) |
|
|
|
blog_writer_demo = gr.Interface( |
|
fn=artist_lib.write_blog, |
|
inputs=[ |
|
gr.Text(label="Blog description text", value="machine learning can be used to track chickens"), |
|
gr.Dropdown(label='Model', choices=["gpt-neo-1.3B", "gpt-neo-2.7B"], value="gpt-neo-1.3B"), |
|
gr.Number(label='Minimum word count', value=50, precision=0), |
|
gr.Number(label='Maximum word count', value=50, precision=0), |
|
gr.Checkbox(label="Force-New"), |
|
], |
|
outputs="text", |
|
examples=[ |
|
['machine learning can be used to track chickens', "gpt-neo-1.3B", 50, 50, False], |
|
['music and machine learning', "gpt-neo-2.7B", 50, 50, False] |
|
], |
|
) |
|
|
|
generateAudioDemo = gr.Interface( |
|
fn=artist_lib.generate_spectrogram_audio_and_loop, |
|
title="Audio Diffusion", |
|
description="Generate audio using Huggingface diffusers.\ |
|
The models without 'latent' or 'ddim' give better results but take about \ |
|
20 minutes without a GPU. For GPU, you can use \ |
|
[colab](https://colab.research.google.com/github/teticio/audio-diffusion/blob/master/notebooks/gradio_app.ipynb) \ |
|
to run this app.", |
|
inputs=[ |
|
gr.Dropdown(label="Model", |
|
choices=[ |
|
"teticio/audio-diffusion-256", |
|
"teticio/audio-diffusion-breaks-256", |
|
"teticio/audio-diffusion-instrumental-hiphop-256", |
|
"teticio/audio-diffusion-ddim-256", |
|
"teticio/latent-audio-diffusion-256", |
|
"teticio/latent-audio-diffusion-ddim-256" |
|
], |
|
value="teticio/latent-audio-diffusion-ddim-256") |
|
], |
|
outputs=[ |
|
gr.Image(label="Mel spectrogram", image_mode="L"), |
|
gr.Audio(label="Audio"), |
|
gr.Audio(label="Loop"), |
|
], |
|
allow_flagging="never") |
|
|
|
with gr.Blocks() as gallerydemo: |
|
with gr.Column(variant="panel"): |
|
with gr.Row(variant="compact"): |
|
text = gr.Textbox( |
|
label="Enter your prompt", |
|
show_label=False, |
|
max_lines=1, |
|
placeholder="Enter your prompt" |
|
) |
|
btn = gr.Button("Generate image") |
|
|
|
gallery = gr.Gallery( |
|
label="Generated images", show_label=False, elem_id="gallery" |
|
) |
|
|
|
btn.click(artist_lib.fake_gan, None, gallery) |
|
|
|
|
|
|
|
artist = gr.TabbedInterface( [drawdemo, imageClassifierDemo, generateAudioDemo, nameMyPetDemo, blog_writer_demo], ["Draw", "imageClassifier", "generateAudio", "nameMyPet", "Bloggr"]) |
|
|
|
artist.queue( |
|
max_size = 4 |
|
) |
|
artist.launch() |
|
|