Shankarm08 commited on
Commit
83f6f35
·
verified ·
1 Parent(s): 2c49388
Files changed (1) hide show
  1. demotwotext.py +27 -0
demotwotext.py ADDED
@@ -0,0 +1,27 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import streamlit as st
2
+ from diffusers import DiffusionPipeline
3
+ import base64
4
+ import io
5
+
6
+ # Load the pre-trained model
7
+ pipeline = DiffusionPipeline.from_pretrained("runwayml/stable-diffusion-512x512", use_safetensors=True)
8
+
9
+ # Create a Streamlit interface
10
+ st.title("Image Generation Model")
11
+ st.write("Enter a prompt for the image generation model:")
12
+
13
+ # Generate the image
14
+ prompt = st.text_input("Prompt", label_visibility="collapsed")
15
+ if st.button("Generate Image"):
16
+ with st.spinner("Generating image..."):
17
+ # Generate the image
18
+ image = pipeline(prompt, num_inference_steps=20).images[0]
19
+
20
+ # Convert the image to bytes
21
+ buf = io.BytesIO()
22
+ image.save(buf, format='JPEG')
23
+ img_bytes = buf.getvalue()
24
+
25
+ # Display the generated image
26
+ st.write("Generated image:")
27
+ st.image(img_bytes, caption="Generated image", use_column_width=True)