Spaces:
Runtime error
Runtime error
| import gradio as gr | |
| #from diffusers import DiffusionPipeline | |
| import torch | |
| import numpy as np | |
| import PIL | |
| import cv2 | |
| # ----------------- | |
| import os | |
| print('\nDEBUG: Cloning diffusers project') | |
| os.system('git clone https://github.com/huggingface/diffusers') | |
| print('\nDEBUG: Pwd') | |
| os.system('pwd') | |
| os.system('ls -la') | |
| print('\nDEBUG: Install dependencies of diffusers') | |
| os.system('cd diffusers && pip install -e .') | |
| print('\nDEBUG: Pip install from the build of diffusers') | |
| os.system('pip install git+file:///home/user/app/diffusers') | |
| from diffusers import DiffusionPipeline | |
| # ----------------- | |
| pipeline = DiffusionPipeline.from_pretrained("fusing/latent-diffusion-text2im-large") | |
| generator = torch.manual_seed(42) | |
| FOOTER = '<img id="visitor-badge" alt="visitor badge" src="https://visitor-badge.glitch.me/badge?page_id=milyiyo.testing-diffusers" />' | |
| def greet(name): | |
| return "Hello " + name + "!!" | |
| def genimage(prompt, iterations): | |
| image = pipeline([prompt], generator=generator, eta=0.3, guidance_scale=6.0, num_inference_steps=iterations) | |
| image_processed = image.cpu().permute(0, 2, 3, 1) | |
| image_processed = image_processed * 255. | |
| image_processed = image_processed.numpy().astype(np.uint8) | |
| image_pil = PIL.Image.fromarray(image_processed[0]) | |
| # save image | |
| file_name = "test.png" | |
| image_pil.save(file_name) | |
| img = cv2.imread(file_name) | |
| #cv2_imshow(img) | |
| return img | |
| iface = gr.Interface(fn=genimage, inputs=["text", "number"], outputs="image") | |
| iface.launch() |