File size: 1,453 Bytes
64ea77f
232aeb3
 
038d520
 
232aeb3
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
64ea77f
232aeb3
 
 
 
 
 
 
 
 
 
 
 
2691f07
232aeb3
 
 
 
 
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
import streamlit as st
import cv2 as cv
import time
import torch
from diffusers import StableDiffusionPipeline

# "stabilityai/stable-diffusion-2-1-base"
# "CompVis/stable-diffusion-v1-4"
def create_model(loc = "stabilityai/stable-diffusion-2-1-base", mch = 'cuda'):
    pipe = StableDiffusionPipeline.from_pretrained(loc, torch_dtype=torch.float16)
    pipe = pipe.to(mch)
    return pipe



openai.api_key = "please-paste-your-API-key-here"

def chatWithGPT(prompt):
  completion = openai.ChatCompletion.create(
  model="gpt-3.5-turbo",
  messages=[
  {"role": "expert in creating prompts for stable diffusion", "content": prompt}
  ]
  )
  return print(completion.choices[0].message.content)



t2i = st.checkbox("Text2Image")

if t2i:
    st.title("Text2Image")
    t2m_mod = create_model()
    
    prom = st.text_input("# Prompt",'')

    c1,c2,c3 = st.columns([1,1,3])
    c4,c5 = st.columns(2)
    with c1:
      bu_1 = st.text_input("Seed",'999')
    with c2:
      bu_2 = st.text_input("Steps",'12')
    with c3:
      bu_3 = st.text_input("Number of Images",'1')
    with c4:
      sl_1 = st.slider("Width",256,1024,128)
    with c5:
      sl_2 = st.slider("hight",256,1024,128)

    create = st.button("Imagine")
    if create:
        generator = torch.Generator("cuda").manual_seed(int(bu_1))
        img = t2m_mod(prom, width=int(sl_1), height=int(sl_2), num_inference_steps=int(bu_2), generator=generator).images[0]
        st.image(img)