Guest User

Untitled

a guest
Jan 18th, 2023
51
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 1.14 KB | None | 0 0
  1. from diffusers import DiffusionPipeline
  2. import gradio as gr
  3. import numpy as np
  4. import imageio
  5. from PIL import Image
  6. import torch
  7.  
  8. device = "cuda" if torch.cuda.is_available() else "cpu"
  9. pipe = DiffusionPipeline.from_pretrained(/*udaleno*/, torch_dtype=torch.float32)
  10. pipe.to(device)
  11.  
  12. def resize(height,img):
  13.   baseheight = height
  14.   img = Image.open(img)
  15.   hpercent = (baseheight/float(img.size[1]))
  16.   wsize = int((float(img.size[0])*float(hpercent)))
  17.   img = img.resize((wsize,baseheight), Image.Resampling.LANCZOS)
  18.   return img
  19.  
  20. def predict(prompt, negative_prompt):
  21.     image = pipe(prompt=prompt, negative_prompt=negative_prompt, num_inference_steps=25, width=768, height=768).images[0]
  22.     return image
  23.  
  24. title="i 768x768"
  25. description="test"
  26. gr.Interface(fn=predict, inputs=[
  27.     #gr.Image(source="upload", type="numpy", tool="sketch", elem_id="source_container"),
  28.     gr.Textbox(label='What you want the AI to Generate, 77 Token limit'),
  29.     gr.Textbox(label='What you Do Not want the AI to generate')],
  30.     outputs='image',
  31.     title=title,
  32.     description=description,
  33.     article = " "
  34. ).launch(max_threads=True, debug=True)
Advertisement
Add Comment
Please, Sign In to add comment