Spaces:
Runtime error
Runtime error
satablediffusion-2-1
Browse files
app.py
CHANGED
@@ -1,10 +1,30 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
import streamlit as st
|
2 |
-
from transformers import
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
3 |
|
4 |
-
|
5 |
-
|
|
|
|
|
|
|
|
|
|
|
6 |
|
7 |
-
|
8 |
-
if text:
|
9 |
-
out = pipe(text)
|
10 |
-
st.write(out)
|
|
|
1 |
+
# import streamlit as st
|
2 |
+
# from transformers import pipeline
|
3 |
+
|
4 |
+
# pipe = pipeline('sentiment-analysis')
|
5 |
+
# text= st.text_area('enter some text')
|
6 |
+
|
7 |
+
# if st.button('Submit'):
|
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
|
|
|
|
|
|