ranga-godhandaraman commited on
Commit
34812b4
·
verified ·
1 Parent(s): d804bcd

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +12 -13
app.py CHANGED
@@ -8,23 +8,22 @@
8
  # if text:
9
  # out = pipe(text)
10
  # st.write(out)
 
11
  import streamlit as st
12
- from transformers import AutoModelForImageGeneration, AutoTokenizer
13
- from PIL import Image
14
- import torch
15
 
16
- model_name = "stabilityai/stable-diffusion-2-1" # loading the model
17
- model = AutoModelForImageGeneration.from_pretrained(model_name)
18
- tokenizer = AutoTokenizer.from_pretrained(model_name)
19
 
20
- text_input = st.text_area('Enter some text') #getting user text
 
21
 
 
22
  if st.button('Generate Image'):
23
  if text_input:
24
- input_ids = tokenizer(text_input, return_tensors="pt").input_ids #input token
25
- with torch.no_grad(): #img generation
26
- output = model.generate(input_ids)
27
-
28
- image = Image.fromarray(output[0].numpy().astype('uint8')) # certing tensor to imgonv
29
 
30
- st.image(image, caption='Generated Image', use_column_width=True) #display output
 
8
  # if text:
9
  # out = pipe(text)
10
  # st.write(out)
11
+
12
  import streamlit as st
13
+ from diffusers import DiffusionPipeline
 
 
14
 
15
+ # Load the stable-diffusion-2-1 model from diffusers
16
+ pipeline = DiffusionPipeline.from_pretrained("stabilityai/stable-diffusion-2-1")
 
17
 
18
+ # Get input text from the user
19
+ text_input = st.text_area('Enter some text')
20
 
21
+ # Add a submit button
22
  if st.button('Generate Image'):
23
  if text_input:
24
+ # Generate the image using the model
25
+ generated_image = pipeline(text_input)
26
+
27
+ # Display the generated image
28
+ st.image(generated_image, caption='Generated Image', use_column_width=True)
29