Spaces:
Runtime error
Runtime error
File size: 3,441 Bytes
7aa2ba3 bfac29e 7aa2ba3 bfac29e 7aa2ba3 0a95991 506ff08 bfac29e 20943b6 bfac29e 9b24bad 2fd4b91 ea2ca52 d5e59e9 9b24bad 2073fa6 2fd4b91 7aa2ba3 6b9749a b551eba eaeb63b b551eba 6b9749a ce8d301 7aa2ba3 eaed5ef bfac29e ea2ca52 c86736a ea2ca52 3de3ba6 0fc04c4 3de3ba6 28e335a 0fc04c4 3de3ba6 4a4612d 0fc04c4 4a4612d 3de3ba6 89c5bf1 3de3ba6 89c5bf1 3de3ba6 0fc04c4 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 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 |
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="cuda" if torch.cuda.is_available() else "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, text_size, prompt, strength, guidance_scale): #(text, text_size, font)
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, int(text_size))
d = ImageDraw.Draw(out)
d.multiline_text((16, 64), text, font=fnt, fill=(255, 255, 255))
#init_image = out
out.save('initImage.png')
images = []
images = pipe(prompt=prompt, image=out, strength=strength, guidance_scale=guidance_scale).images
#images[0].save = ("image.png")
#images = []
#images.append(out)
#out.show()
return images[0]
#def newImage(image, prompt):
#return images test
#drawImage = gr.Interface(fn=drawImage, inputs=gr.Textbox(placeholder="shift + enter for new line",label="what do you want to say?"),outputs="image")
#newImage = gr.Interface(fn=newImage,inputs=[gr.Textbox(placeholder="prompt",label="how does your message look and feel?")],outputs="image")
#demo = gr.Series(drawImage,newImage)
#blocks = gr.Blocks()
demo = gr.Interface(
title="Text Decorator",
description="Note: This will be very slow since it is running on CPU.",
#description="Save or screenshot your creations and share on https://forms.gle/qhzc7nfX7VGwBco96 ⚡️ (Note: I've upgraded the hardware today from 7-9pm so that it runs faster, if you visit this link in the future, it will be slower.)",
##theme='huggingface',
#css="""
#body {font-family: system-ui, Helvetica, Arial, sans-serif}
#""",
fn=drawImage,
inputs=[
gr.Textbox(placeholder="shift + enter for new line",label="what do you want to say?"),
##"file"
gr.Number(label="text size",value=240),
gr.Textbox(placeholder="eg. imagery, art style, materials, emotions",label="how does your message look and feel?"), #figure out models in series
gr.Slider(label="strength (how much noise will be added to the input image)",minimum=0, maximum=1, step=0.01, value=0.7),
gr.Slider(label="guidance scale (how much the image generation follows the prompt)",value=15, maximum=20),
],
outputs="image")
#with blocks (css=".gradio-container {background-color: red}") as demo:
#fn=drawImage,
#inputs=[
#gr.Textbox(placeholder="shift + enter for new line",label="what do you want to say?"),
##"file"
#gr.Number(label="text size",value=240),
#gr.Textbox(placeholder="eg. imagery, art style, materials, emotions",label="how does your message look and feel?"), #figure out models in series
#gr.Slider(label="strength (how much noise will be added to the input image)",minimum=0, maximum=1, step=0.01, value=0.7),
#gr.Slider(label="guidance scale (how much the image generation follows the prompt)",value=15, maximum=20),
#],
#outputs="image"
demo.launch() |