Spaces:
Runtime error
Runtime error
File size: 1,364 Bytes
7aa2ba3 bfac29e 7aa2ba3 bfac29e 7aa2ba3 506ff08 bfac29e 20943b6 bfac29e 7aa2ba3 2073fa6 7aa2ba3 d5e59e9 78da47e 2073fa6 0d1ef3c 7aa2ba3 bfac29e 7aa2ba3 d5e59e9 7aa2ba3 bfac29e |
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 |
import os
import shutil
import torch
import gradio as gr
MY_SECRET_TOKEN=os.environ.get('HF_TOKEN_SD')
from PIL import Image,ImageFont,ImageDraw
from gradio.mix import Series
#from io import BytesIO
from diffusers import StableDiffusionImg2ImgPipeline
YOUR_TOKEN=MY_SECRET_TOKEN
device="cpu"
pipe = StableDiffusionImg2ImgPipeline.from_pretrained("runwayml/stable-diffusion-v1-5", use_auth_token=YOUR_TOKEN)
pipe.to(device)
#draw an image based off of user's text input
def drawImage(text, prompt): #(text, font, prompt)
out = Image.new("RGB", (512, 512), (0, 0, 0))
#add some code here to move font to font-directory
font = './font-directory/DimpleSans-Regular.otf'
fnt = ImageFont.truetype(font, 160)
d = ImageDraw.Draw(out)
d.multiline_text((10, 64), text, font=fnt, fill=(255, 255, 255))
init_image = out
out_image = pipe(prompt=prompt, init_image=init_image, strength=0.75, guidance_scale=7.5)
#out.show()
return out_image
demo = gr.Interface(
title="AI text decorator",
description="christina",
fn=drawImage,
inputs=[
gr.Textbox(placeholder="shift + enter for new line",label="what do you want to say?"),
#"file"
gr.Textbox(placeholder="prompt",label="how does your message look and feel?") #figure out models in series
],
outputs="image")
demo.launch() |