Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
@@ -1,43 +1,28 @@
|
|
1 |
import streamlit as st
|
2 |
-
from
|
3 |
-
import torch
|
4 |
-
from PIL import Image
|
5 |
-
import io
|
6 |
-
import base64
|
7 |
|
8 |
-
#
|
9 |
-
|
10 |
|
11 |
-
|
12 |
-
|
13 |
-
|
|
|
14 |
|
15 |
-
# Streamlit app
|
16 |
-
st.title(
|
17 |
-
st.write("Generate images using the Stability AI's Stable Diffusion model.")
|
18 |
|
19 |
-
# Input
|
20 |
-
|
21 |
|
22 |
# Generate button
|
23 |
-
if st.button(
|
24 |
-
if
|
25 |
-
with st.spinner('Generating
|
26 |
-
|
27 |
-
|
28 |
-
|
29 |
-
|
30 |
-
|
31 |
-
image.save(buffered, format="PNG")
|
32 |
-
img_str = base64.b64encode(buffered.getvalue()).decode()
|
33 |
|
34 |
-
# Display the image
|
35 |
-
st.image(image, caption="Generated Image", use_column_width=True)
|
36 |
|
37 |
-
# Option to download the image
|
38 |
-
st.markdown(
|
39 |
-
f'<a href="data:image/png;base64,{img_str}" download="generated_image.png">Download Image</a>',
|
40 |
-
unsafe_allow_html=True,
|
41 |
-
)
|
42 |
-
else:
|
43 |
-
st.error("Please enter a prompt to generate an image.")
|
|
|
1 |
import streamlit as st
|
2 |
+
from transformers import DiffusionPipeline
|
|
|
|
|
|
|
|
|
3 |
|
4 |
+
# Load the Diffusion pipeline
|
5 |
+
pipeline = DiffusionPipeline.from_pretrained("stabilityai/stable-diffusion-3-medium")
|
6 |
|
7 |
+
def generate_prompt(prompt_text):
|
8 |
+
# Generate response using the Diffusion model
|
9 |
+
response = pipeline(prompt=prompt_text, top_p=0.9, num_return_sequences=1)[0]['generated_text']
|
10 |
+
return response
|
11 |
|
12 |
+
# Streamlit app UI
|
13 |
+
st.title('Diffusion Model Prompt Generator')
|
|
|
14 |
|
15 |
+
# Input prompt from user
|
16 |
+
prompt_input = st.text_area('Enter your prompt here:', height=100)
|
17 |
|
18 |
# Generate button
|
19 |
+
if st.button('Generate'):
|
20 |
+
if prompt_input:
|
21 |
+
with st.spinner('Generating...'):
|
22 |
+
generated_text = generate_prompt(prompt_input)
|
23 |
+
st.success('Generation complete!')
|
24 |
+
st.text_area('Generated Text:', value=generated_text, height=200)
|
25 |
+
else:
|
26 |
+
st.warning('Please enter a prompt to generate.')
|
|
|
|
|
27 |
|
|
|
|
|
28 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|