christinac commited on
Commit
7aa2ba3
·
1 Parent(s): 78da47e

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +23 -10
app.py CHANGED
@@ -1,30 +1,43 @@
1
- from PIL import Image,ImageFont,ImageDraw
2
- #import os
3
- #import shutil
4
  import gradio as gr
 
 
 
5
  from gradio.mix import Series
 
 
 
 
 
 
 
6
 
7
  #draw an input image based off of user's text input
8
 
9
- def drawImage(text): #add another argument for prompt later
10
  out = Image.new("RGB", (512, 512), (0, 0, 0))
11
- #move font to font-directory
 
12
  font = './font-directory/DimpleSans-Regular.otf'
13
  fnt = ImageFont.truetype(font, 160)
14
  d = ImageDraw.Draw(out)
15
- #d.multiline_text((10, 64), text, fill=(255, 255, 255))
16
  d.multiline_text((10, 64), text, font=fnt, fill=(255, 255, 255))
17
- out.show()
18
- return out
 
 
 
19
 
20
  demo = gr.Interface(
21
  title="AI text decorator",
22
  description="christina",
23
  fn=drawImage,
24
  inputs=[
25
- gr.Textbox(placeholder="shift + enter for new line",label="what do you want to say?")
26
  #"file"
27
- #gr.Textbox(placeholder="prompt",label="how does your message look and feel?") #figure out models in series
28
  ],
29
  outputs="image")
30
  demo.launch()
 
1
+ import os
2
+ import shutil
3
+ import torch
4
  import gradio as gr
5
+ MY_SECRET_TOKEN=os.environ.get('HF_TOKEN_SD')
6
+
7
+ from PIL import Image,ImageFont,ImageDraw
8
  from gradio.mix import Series
9
+ #from io import BytesIO
10
+ from diffusers import StableDiffusionImg2ImgPipeline
11
+
12
+ YOUR_TOKEN=MY_SECRET_TOKEN
13
+ device="cpu"
14
+ img_pipe = StableDiffusionImg2ImgPipeline.from_pretrained("runwayml/stable-diffusion-v1-5", use_auth_token=YOUR_TOKEN)
15
+ img_pipe.to(device)
16
 
17
  #draw an input image based off of user's text input
18
 
19
+ def drawImage(text, prompt): #(text, font, prompt)
20
  out = Image.new("RGB", (512, 512), (0, 0, 0))
21
+ #add some code here to move font to font-directory
22
+
23
  font = './font-directory/DimpleSans-Regular.otf'
24
  fnt = ImageFont.truetype(font, 160)
25
  d = ImageDraw.Draw(out)
 
26
  d.multiline_text((10, 64), text, font=fnt, fill=(255, 255, 255))
27
+
28
+ init_image = out
29
+ out_image = pipe(prompt=prompt, init_image=init_image, strength=0.75, guidance_scale=7.5)
30
+ #out.show()
31
+ return out_image
32
 
33
  demo = gr.Interface(
34
  title="AI text decorator",
35
  description="christina",
36
  fn=drawImage,
37
  inputs=[
38
+ gr.Textbox(placeholder="shift + enter for new line",label="what do you want to say?"),
39
  #"file"
40
+ gr.Textbox(placeholder="prompt",label="how does your message look and feel?") #figure out models in series
41
  ],
42
  outputs="image")
43
  demo.launch()