Update app.py
Browse files
    	
        app.py
    CHANGED
    
    | @@ -1,9 +1,8 @@ | |
| 1 | 
             
            import gradio as gr
         | 
| 2 | 
            -
            import numpy as np
         | 
| 3 | 
            -
            import random
         | 
| 4 | 
             
            import torch
         | 
| 5 | 
             
            from diffusers import DiffusionPipeline
         | 
| 6 | 
             
            from datasets import load_dataset
         | 
|  | |
| 7 |  | 
| 8 |  | 
| 9 | 
             
            # Configurações do dispositivo para uso apenas da CPU
         | 
| @@ -53,11 +52,9 @@ def resize_to_divisible_by_8(image): | |
| 53 | 
             
                new_height = height + (8 - height % 8) if height % 8 != 0 else height
         | 
| 54 | 
             
                return image.resize((new_width, new_height))
         | 
| 55 |  | 
| 56 | 
            -
            image = pipe(prompt, width=width, height=height)
         | 
| 57 | 
            -
            image = resize_to_divisible_by_8(image)
         | 
| 58 | 
            -
             | 
| 59 | 
             
            # Função simples para gerar imagem
         | 
| 60 | 
             
            def infer_simple(prompt):
         | 
|  | |
| 61 | 
             
                image = pipe(
         | 
| 62 | 
             
                    prompt=prompt,
         | 
| 63 | 
             
                    num_inference_steps=DEFAULT_INFERENCE_STEPS,
         | 
| @@ -65,6 +62,8 @@ def infer_simple(prompt): | |
| 65 | 
             
                    height=IMAGE_HEIGHT,
         | 
| 66 | 
             
                    width=IMAGE_WIDTH,
         | 
| 67 | 
             
                ).images[0]
         | 
|  | |
|  | |
| 68 | 
             
                return image
         | 
| 69 |  | 
| 70 | 
             
            # Interface Gradio
         | 
|  | |
| 1 | 
             
            import gradio as gr
         | 
|  | |
|  | |
| 2 | 
             
            import torch
         | 
| 3 | 
             
            from diffusers import DiffusionPipeline
         | 
| 4 | 
             
            from datasets import load_dataset
         | 
| 5 | 
            +
            from PIL import Image
         | 
| 6 |  | 
| 7 |  | 
| 8 | 
             
            # Configurações do dispositivo para uso apenas da CPU
         | 
|  | |
| 52 | 
             
                new_height = height + (8 - height % 8) if height % 8 != 0 else height
         | 
| 53 | 
             
                return image.resize((new_width, new_height))
         | 
| 54 |  | 
|  | |
|  | |
|  | |
| 55 | 
             
            # Função simples para gerar imagem
         | 
| 56 | 
             
            def infer_simple(prompt):
         | 
| 57 | 
            +
                # Geração da imagem
         | 
| 58 | 
             
                image = pipe(
         | 
| 59 | 
             
                    prompt=prompt,
         | 
| 60 | 
             
                    num_inference_steps=DEFAULT_INFERENCE_STEPS,
         | 
|  | |
| 62 | 
             
                    height=IMAGE_HEIGHT,
         | 
| 63 | 
             
                    width=IMAGE_WIDTH,
         | 
| 64 | 
             
                ).images[0]
         | 
| 65 | 
            +
                # Redimensionar a imagem para ser divisível por 8
         | 
| 66 | 
            +
                image = resize_to_divisible_by_8(image)
         | 
| 67 | 
             
                return image
         | 
| 68 |  | 
| 69 | 
             
            # Interface Gradio
         |