import streamlit as st import torch import numpy as np from diffusers import DiffusionPipeline from transformers import pipeline # Load text generation pipeline text_pipe = pipeline('text-generation', model='daspartho/prompt-extend') def extend_prompt(prompt): return text_pipe(prompt + ',', num_return_sequences=1, max_new_tokens=50)[0]["generated_text"] @st.cache_resource def load_pipeline(use_cuda): device = "cuda" if use_cuda and torch.cuda.is_available() else "cpu" pipe = DiffusionPipeline.from_pretrained( "stabilityai/sdxl-turbo", torch_dtype=torch.float16 if device == "cuda" else torch.float32, variant="fp16" if device == "cuda" else None, use_safetensors=True ) if device == "cuda": pipe.enable_xformers_memory_efficient_attention() pipe.to(device) return pipe def generate_image(prompt, use_details, use_cuda): pipe = load_pipeline(use_cuda) generator = torch.manual_seed(np.random.randint(0, 2**32)) extended_prompt = extend_prompt(prompt) if use_details else prompt image = pipe(prompt=extended_prompt, generator=generator, num_inference_steps=25, guidance_scale=7.5).images[0] return image, extended_prompt # Add the custom CSS file st.markdown('', unsafe_allow_html=True) st.markdown("
✨ Generate Your Custom GitHub Profile Picture! ✨
", unsafe_allow_html=True) st.markdown("
Create an anime-style GitHub profile picture that reflects your personality and passion for coding. 🚀👨‍💻
", unsafe_allow_html=True) # Input widgets input_text = st.text_area("Describe your GitHub profile picture:", "Create an anime-style GitHub profile picture for a boy") details_checkbox = st.checkbox("Generate Details?", value=True) cuda_checkbox = st.checkbox("Use CUDA?", value=False) if st.button("Generate Image"): with st.spinner('Generating image...'): image, extended_prompt = generate_image(input_text, details_checkbox, cuda_checkbox) st.image(image, caption="Generated Image") st.text(f"Extended Prompt: {extended_prompt}") st.balloons()