Spaces:
Running
Running
Create app.py
Browse files
app.py
ADDED
@@ -0,0 +1,44 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
import streamlit as st
|
2 |
+
from diffusers import StableDiffusionPipeline
|
3 |
+
import torch
|
4 |
+
import os
|
5 |
+
|
6 |
+
# Load Stable Diffusion model
|
7 |
+
@st.cache_resource
|
8 |
+
def load_model():
|
9 |
+
model_id = "CompVis/stable-diffusion-v1-4"
|
10 |
+
device = "cuda" if torch.cuda.is_available() else "cpu"
|
11 |
+
pipe = StableDiffusionPipeline.from_pretrained(model_id, torch_dtype=torch.float16 if device == "cuda" else torch.float32)
|
12 |
+
pipe.to(device)
|
13 |
+
return pipe
|
14 |
+
|
15 |
+
# Load the model
|
16 |
+
pipe = load_model()
|
17 |
+
|
18 |
+
# Ensure output directory exists
|
19 |
+
output_dir = "./outputs_generated"
|
20 |
+
os.makedirs(output_dir, exist_ok=True)
|
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='content'>Create an anime-style GitHub profile picture that reflects your personality and passion for coding. ππ¨βπ»</div>", unsafe_allow_html=True)
|
29 |
+
|
30 |
+
# User input for the text prompt
|
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 |
+
images = pipe([user_prompt], num_inference_steps=50)["images"]
|
37 |
+
|
38 |
+
for i, image in enumerate(images):
|
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()
|