Upload app.py
Browse files
app.py
ADDED
|
@@ -0,0 +1,25 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import streamlit as st
|
| 2 |
+
from diffusers import AutoPipelineForText2Image
|
| 3 |
+
import torch
|
| 4 |
+
|
| 5 |
+
# Load model and move it to CUDA
|
| 6 |
+
pipe = AutoPipelineForText2Image.from_pretrained("stabilityai/sdxl-turbo", torch_dtype=torch.float16, variant="fp16")
|
| 7 |
+
pipe.to("cuda")
|
| 8 |
+
|
| 9 |
+
def generate_image(prompt):
|
| 10 |
+
# Generate image using the model
|
| 11 |
+
image = pipe(prompt=prompt, num_inference_steps=1, guidance_scale=0.0).images[0]
|
| 12 |
+
return image
|
| 13 |
+
|
| 14 |
+
# Streamlit app
|
| 15 |
+
st.title("Text to Image Generation App")
|
| 16 |
+
|
| 17 |
+
# User input prompt
|
| 18 |
+
prompt = st.text_area("Enter a prompt for image generation:")
|
| 19 |
+
|
| 20 |
+
if st.button("Generate Image"):
|
| 21 |
+
if prompt:
|
| 22 |
+
# Generate and display the image
|
| 23 |
+
st.image(generate_image(prompt), caption="Generated Image", use_column_width=True)
|
| 24 |
+
else:
|
| 25 |
+
st.warning("Please enter a prompt.")
|