File size: 5,594 Bytes
158667b 78e3b34 158667b 78e3b34 158667b |
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 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 |
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, blog_writer_demo, gallerydemo], ["Draw", "Bloggr", "Gallery"])
#artist = gr.TabbedInterface( [drawdemo, blog_writer_demo, imageClassifierDemo, generateAudioDemo, audioGeneratorDemo, AudioDemo, nameMyPetDemo], ["Draw", "Bloggr", "imageClassifier", "generateAudio", "audioGenerator", "AudioDemo", "nameMyPet"])
artist = gr.TabbedInterface( [drawdemo, imageClassifierDemo, generateAudioDemo, nameMyPetDemo, blog_writer_demo], ["Draw", "imageClassifier", "generateAudio", "nameMyPet", "Bloggr"])
artist.queue(
max_size = 4
)
artist.launch()
|