mrm8488/hf-diffusers
2
1from diffusers import DDPMPipeline2import gradio as gr3from ui import title, description, examples4 5 6RES = None7 8models = [9 {'type': 'pokemon', 'res': 64, 'id': 'mrm8488/ddpm-ema-pokemon-64'},10 {'type': 'flowers', 'res': 64, 'id': 'mrm8488/ddpm-ema-flower-64'},11 {'type': 'anime_faces', 'res': 128, 'id': 'mrm8488/ddpm-ema-anime-v2-128'},12 {'type': 'butterflies', 'res': 128, 'id': 'mrm8488/ddpm-ema-butterflies-128'},13 #{'type': 'human_faces', 'res': 256, 'id': 'fusing/ddpm-celeba-hq'}14]15for model in models:16 print(model)17 pipeline = DDPMPipeline.from_pretrained(model['id'])18 pipeline.save_pretrained('.')19 model['pipeline'] = pipeline20 21 22def predict(type):23 pipeline = None24 for model in models:25 if model['type'] == type:26 pipeline = model['pipeline']27 RES = model['res']28 break29 # run pipeline in inference30 image = pipeline()["sample"]31 32 return image[0]33 34 35gr.Interface(36 predict,37 inputs=[gr.components.Dropdown(choices=[model['type'] for model in models], label='Choose a model')38 ],39 outputs=[gr.Image(shape=(64,64), type="pil",40 elem_id="generated_image")],41 title=title,42 description=description43).launch()44 