Spaces:
Running
Running
Update app.py
Browse files
app.py
CHANGED
@@ -1,44 +1,57 @@
|
|
1 |
import streamlit as st
|
2 |
-
from diffusers import DiffusionPipeline
|
3 |
import torch
|
4 |
-
import
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
5 |
|
6 |
-
# Load Diffusion model
|
7 |
@st.cache_resource
|
8 |
-
def
|
9 |
-
|
10 |
-
|
11 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
12 |
pipe.to(device)
|
13 |
return pipe
|
14 |
|
15 |
-
|
16 |
-
pipe =
|
17 |
-
|
18 |
-
|
19 |
-
|
20 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
21 |
|
22 |
-
# Load custom CSS
|
23 |
-
with open("styles.css") as f:
|
24 |
-
st.markdown(f"<style>{f.read()}</style>", unsafe_allow_html=True)
|
25 |
-
|
26 |
-
# Streamlit app
|
27 |
st.markdown("<div class='header'>β¨ Generate Your Custom GitHub Profile Picture! β¨</div>", unsafe_allow_html=True)
|
28 |
-
st.markdown("<div class='
|
29 |
|
30 |
-
|
31 |
-
user_prompt = st.text_area("Describe your GitHub profile picture:",
|
32 |
"Create an anime-style GitHub profile picture for a boy. The character should have a friendly and approachable expression, embodying a sense of curiosity and enthusiasm, reflecting the qualities of a passionate coder. Incorporate elements that suggest technology or coding, such as a pair of stylish glasses, a laptop, or a background with subtle code or tech motifs. Use vibrant and appealing colors to make the profile picture stand out and convey a sense of creativity and innovation.")
|
33 |
|
|
|
|
|
|
|
|
|
|
|
34 |
if st.button("Generate Image"):
|
35 |
with st.spinner('Generating image...'):
|
36 |
-
|
37 |
-
|
38 |
-
|
39 |
-
file_path = os.path.join(output_dir, f"aditya_profile_pic_{i}.png")
|
40 |
-
image.save(file_path)
|
41 |
-
st.image(file_path, caption=f"Generated Image {i+1}")
|
42 |
-
st.success(f"Saved image to {file_path}")
|
43 |
-
|
44 |
st.balloons()
|
|
|
1 |
import streamlit as st
|
|
|
2 |
import torch
|
3 |
+
import numpy as np
|
4 |
+
from diffusers import DiffusionPipeline
|
5 |
+
from transformers import pipeline
|
6 |
+
|
7 |
+
text_pipe = pipeline('text-generation', model='daspartho/prompt-extend')
|
8 |
+
|
9 |
+
def extend_prompt(prompt):
|
10 |
+
return text_pipe(prompt + ',', num_return_sequences=1)[0]["generated_text"]
|
11 |
|
|
|
12 |
@st.cache_resource
|
13 |
+
def load_pipeline(use_cuda):
|
14 |
+
device = "cuda" if use_cuda and torch.cuda.is_available() else "cpu"
|
15 |
+
pipe = DiffusionPipeline.from_pretrained(
|
16 |
+
"stabilityai/sdxl-turbo",
|
17 |
+
torch_dtype=torch.float16 if device == "cuda" else torch.float32,
|
18 |
+
variant="fp16" if device == "cuda" else None,
|
19 |
+
use_safetensors=True
|
20 |
+
)
|
21 |
+
if device == "cuda":
|
22 |
+
pipe.enable_xformers_memory_efficient_attention()
|
23 |
pipe.to(device)
|
24 |
return pipe
|
25 |
|
26 |
+
def generate_image(prompt, use_details, steps, seed, use_cuda):
|
27 |
+
pipe = load_pipeline(use_cuda)
|
28 |
+
generator = torch.manual_seed(seed) if seed != 0 else np.random.seed(0)
|
29 |
+
extended_prompt = extend_prompt(prompt) if use_details else prompt
|
30 |
+
image = pipe(prompt=extended_prompt, generator=generator, num_inference_steps=steps, guidance_scale=0.0).images[0]
|
31 |
+
return image, extended_prompt
|
32 |
+
|
33 |
+
st.markdown("""
|
34 |
+
<style>
|
35 |
+
body {background-color: #E8F5E9;}
|
36 |
+
.header {font-size: 2.5em; color: #2E7D32; text-align: center; margin-top: 20px;}
|
37 |
+
.subheader {font-size: 1.2em; color: #4CAF50; text-align: center; margin-bottom: 30px;}
|
38 |
+
</style>
|
39 |
+
""", unsafe_allow_html=True)
|
40 |
|
|
|
|
|
|
|
|
|
|
|
41 |
st.markdown("<div class='header'>β¨ Generate Your Custom GitHub Profile Picture! β¨</div>", unsafe_allow_html=True)
|
42 |
+
st.markdown("<div class='subheader'>Create an anime-style GitHub profile picture that reflects your personality and passion for coding. ππ¨βπ»</div>", unsafe_allow_html=True)
|
43 |
|
44 |
+
input_text = st.text_area("Describe your GitHub profile picture:",
|
|
|
45 |
"Create an anime-style GitHub profile picture for a boy. The character should have a friendly and approachable expression, embodying a sense of curiosity and enthusiasm, reflecting the qualities of a passionate coder. Incorporate elements that suggest technology or coding, such as a pair of stylish glasses, a laptop, or a background with subtle code or tech motifs. Use vibrant and appealing colors to make the profile picture stand out and convey a sense of creativity and innovation.")
|
46 |
|
47 |
+
details_checkbox = st.checkbox("Generate Details?", value=True)
|
48 |
+
steps_slider = st.slider("Number of Iterations", min_value=1, max_value=5, value=2, step=1)
|
49 |
+
seed_slider = st.slider("Seed", min_value=0, max_value=999999999999999999, value=398231747038484200, step=1)
|
50 |
+
cuda_checkbox = st.checkbox("Use CUDA?", value=False)
|
51 |
+
|
52 |
if st.button("Generate Image"):
|
53 |
with st.spinner('Generating image...'):
|
54 |
+
image, extended_prompt = generate_image(input_text, details_checkbox, steps_slider, seed_slider, cuda_checkbox)
|
55 |
+
st.image(image, caption="Generated Image")
|
56 |
+
st.text(f"Extended Prompt: {extended_prompt}")
|
|
|
|
|
|
|
|
|
|
|
57 |
st.balloons()
|