Spaces:
Sleeping
Sleeping
File size: 13,856 Bytes
db64d27 7aa8120 db64d27 7aa8120 db64d27 | 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 | === streamlit_app.py ===
import streamlit as st
from utils import load_css, create_prompt_selector, display_image_gallery, generate_image_placeholder
import time
def main():
st.set_page_config(
page_title="AI Image Generator - Dramatic Scenes",
page_icon="π¨",
layout="wide",
initial_sidebar_state="expanded"
)
load_css()
# Header
st.markdown("""
<div class="header">
<h1>π¬ AI Image Generator - Dramatic Scenes</h1>
<p>Create hyperrealistic, cinematic images with detailed prompts</p>
<p style="font-size: 0.9em; opacity: 0.7;">Built with <a href="https://huggingface.co/spaces/akhaliq/anycoder" target="_blank">anycoder</a></p>
</div>
""", unsafe_allow_html=True)
# Sidebar
with st.sidebar:
st.markdown("## βοΈ Generation Settings")
# Aspect ratio
aspect_ratio = st.selectbox(
"Aspect Ratio",
options=["4:5", "16:9", "1:1", "3:2", "2:3"],
index=0
)
# Quality
quality = st.selectbox(
"Quality",
options=["Standard", "High", "Ultra (8K)"],
index=2
)
# Style
style = st.selectbox(
"Style",
options=["Cinematic", "Photorealistic", "Dramatic", "Hollywood", "Artistic"],
index=0
)
# Resolution
resolution = st.selectbox(
"Resolution",
options=["1024x1024", "1024x1280", "1280x720", "1920x1080", "2048x2560"],
index=1
)
st.markdown("---")
st.markdown("### π Statistics")
if 'generated_count' not in st.session_state:
st.session_state.generated_count = 0
st.metric("Images Generated", st.session_state.generated_count)
# Main content
col1, col2 = st.columns([1, 1])
with col1:
st.markdown("## π Prompt Editor")
# Predefined prompts
prompt_option = st.radio(
"Choose a scene template:",
["Custom Prompt", "Haunted Hut Scene", "Disaster Scene"],
index=0
)
# Predefined prompts
prompts = {
"Haunted Hut Scene": """Hyperrealistic and dramatic scene showing a terrified man sitting on a bamboo bench in a thatch-roofed hut. He's wearing a black T-shirt with "WALIΔ RUDEGO" text and symbolic pattern underneath. A semi-transparent, smoky, ghostly figure emerges from the air beside him, grabbing his neck with a misty hand. The ghost has a skeletal, menacing face and glowing eyes, screaming or roaring. The man looks shocked and terrified, with wide eyes and mouth agape, frozen in fear. Natural lighting with warm sunlight filtering through the hut, background shows green vegetation outside. Intense, eerie, and cinematic atmosphere with strong emotional contrast between ghost and victim. 8K resolution, 4:5 aspect ratio.""",
"Disaster Scene": """A man and cat falling through the air. Background: skyscrapers curve dramatically in a wide fisheye perspective, as if the entire city is collapsing inward. Flying debris, concrete chunks, and glass shards fill the air. Action elements: A police car floats behind him - its red and blue sirens flash intensely through dust and smoke. Behind the vehicle follows a powerful explosion, casting orange light and shrapnel across the scene. In the background, a police officer is seen waving arms, thrown by the explosion. Lighting and atmosphere: Cinematic lighting with strong, directional shadows, motion blur, and bright lights from sirens and fireball. Dark and gritty color palette with golden-brown tones punctuated by vivid red, blue, and orange accents from explosions and sirens. Clothing: The man wears a torn, olive-green hoodie and dark, worn pants - flailing wildly in the wind. Hollywood disaster movie style - dramatic freeze-frame with intense city destruction, emotions, and surreal action. Hyperrealistic details in skin texture, movement, and lighting."""
}
# Text area for prompt
if prompt_option == "Custom Prompt":
prompt_text = st.text_area(
"Enter your prompt:",
height=200,
placeholder="Describe the image you want to generate in detail..."
)
else:
prompt_text = st.text_area(
"Edit the preset prompt:",
value=prompts.get(prompt_option, ""),
height=200
)
# Negative prompt
negative_prompt = st.text_area(
"Negative Prompt (what to avoid):",
value="blurry, low quality, distorted, deformed, bad anatomy, watermark, text, signature",
height=100
)
# Generate button
generate_col1, generate_col2, generate_col3 = st.columns([1, 2, 1])
with generate_col2:
if st.button("π¨ Generate Image", type="primary", use_container_width=True):
if prompt_text:
with st.spinner("Generating your image..."):
# Simulate image generation
time.sleep(2)
# Update session state
if 'generated_images' not in st.session_state:
st.session_state.generated_images = []
# Add new image to gallery
new_image = {
'prompt': prompt_text,
'negative_prompt': negative_prompt,
'aspect_ratio': aspect_ratio,
'quality': quality,
'style': style,
'timestamp': time.time()
}
st.session_state.generated_images.append(new_image)
st.session_state.generated_count += 1
st.success("β
Image generated successfully!")
st.rerun()
else:
st.error("β Please enter a prompt to generate an image.")
with col2:
st.markdown("## πΌοΈ Generated Images")
if 'generated_images' in st.session_state and st.session_state.generated_images:
display_image_gallery(st.session_state.generated_images)
else:
st.markdown("""
<div class="empty-state">
<h3>No images generated yet</h3>
<p>Enter a prompt and click "Generate Image" to start creating!</p>
</div>
""", unsafe_allow_html=True)
# Show example placeholders
st.markdown("### Example Scenes")
example_col1, example_col2 = st.columns(2)
with example_col1:
st.image(
generate_image_placeholder("Haunted", "#FF6B6B"),
caption="Haunted Hut Scene Example",
use_column_width=True
)
with example_col2:
st.image(
generate_image_placeholder("Disaster", "#4ECDC4"),
caption="Disaster Scene Example",
use_column_width=True
)
# Footer
st.markdown("---")
st.markdown("""
<div class="footer">
<p>π‘ Tip: Be as detailed as possible in your prompts for better results!</p>
<p>π― Focus on: lighting, atmosphere, emotions, and specific visual elements</p>
</div>
""", unsafe_allow_html=True)
if __name__ == "__main__":
main()
=== utils.py ===
import streamlit as st
import base64
from io import BytesIO
import time
def load_css():
"""Load custom CSS styles"""
st.markdown("""
<style>
.header {
text-align: center;
padding: 2rem 0;
background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
color: white;
border-radius: 10px;
margin-bottom: 2rem;
}
.header h1 {
margin: 0;
font-size: 2.5rem;
font-weight: 700;
}
.header p {
margin: 0.5rem 0;
opacity: 0.9;
}
.header a {
color: #FFD700;
text-decoration: none;
font-weight: bold;
}
.header a:hover {
text-decoration: underline;
}
.image-card {
background: white;
border-radius: 10px;
padding: 1rem;
box-shadow: 0 4px 6px rgba(0, 0, 0, 0.1);
margin-bottom: 1rem;
transition: transform 0.2s;
}
.image-card:hover {
transform: translateY(-2px);
box-shadow: 0 6px 12px rgba(0, 0, 0, 0.15);
}
.image-container {
position: relative;
border-radius: 8px;
overflow: hidden;
}
.image-overlay {
position: absolute;
bottom: 0;
left: 0;
right: 0;
background: linear-gradient(to top, rgba(0,0,0,0.8), transparent);
color: white;
padding: 1rem;
opacity: 0;
transition: opacity 0.3s;
}
.image-container:hover .image-overlay {
opacity: 1;
}
.empty-state {
text-align: center;
padding: 3rem;
color: #666;
}
.empty-state h3 {
margin-bottom: 1rem;
color: #333;
}
.footer {
text-align: center;
padding: 1rem;
color: #666;
font-size: 0.9em;
}
.prompt-preview {
background: #f7f7f7;
padding: 0.5rem;
border-radius: 5px;
font-size: 0.85em;
color: #555;
margin-top: 0.5rem;
white-space: nowrap;
overflow: hidden;
text-overflow: ellipsis;
}
.stButton > button {
transition: all 0.2s;
}
.stButton > button:hover {
transform: translateY(-2px);
box-shadow: 0 4px 8px rgba(0, 0, 0, 0.2);
}
.metric-card {
background: white;
padding: 1rem;
border-radius: 8px;
text-align: center;
box-shadow: 0 2px 4px rgba(0, 0, 0, 0.1);
}
</style>
""", unsafe_allow_html=True)
def create_prompt_selector():
"""Create a prompt selection interface"""
pass
def display_image_gallery(images):
"""Display a gallery of generated images"""
cols = st.columns(2)
for idx, image_data in enumerate(reversed(images[-6:])): # Show last 6 images
with cols[idx % 2]:
st.markdown(f"""
<div class="image-card">
<div class="image-container">
<img src="data:image/png;base64,{create_placeholder_image(image_data['prompt'][:20])}"
style="width: 100%; border-radius: 8px;">
<div class="image-overlay">
<strong>Generated</strong><br>
{time.strftime('%Y-%m-%d %H:%M', time.localtime(image_data['timestamp']))}
</div>
</div>
<div style="margin-top: 0.5rem;">
<strong>Style:</strong> {image_data['style']}<br>
<strong>Quality:</strong> {image_data['quality']}<br>
<strong>Aspect:</strong> {image_data['aspect_ratio']}
</div>
<div class="prompt-preview">
{image_data['prompt'][:100]}{'...' if len(image_data['prompt']) > 100 else ''}
</div>
</div>
""", unsafe_allow_html=True)
if st.button(f"π Copy Prompt", key=f"copy_{idx}"):
st.write(f"**Prompt copied to clipboard:** {image_data['prompt']}")
st.success("Prompt ready to copy!")
def generate_image_placeholder(text, color="#667eea"):
"""Generate a placeholder image with text"""
# This would normally use an image generation API
# For now, we'll create a simple placeholder
return f"https://picsum.photos/seed/{text}/400/500"
def create_placeholder_image(seed):
"""Create a base64 encoded placeholder image"""
# Simple placeholder - in real app this would be the generated image
placeholder_url = f"https://picsum.photos/seed/{seed}/400/500"
return ""
def save_image_to_history(image_data):
"""Save generated image to session history"""
if 'image_history' not in st.session_state:
st.session_state.image_history = []
st.session_state.image_history.append({
'timestamp': time.time(),
'data': image_data
})
# Keep only last 50 images
if len(st.session_state.image_history) > 50:
st.session_state.image_history = st.session_state.image_history[-50:]
def get_prompt_suggestions():
"""Get prompt suggestions for users"""
return [
"Cinematic portrait with dramatic lighting",
"Fantasy landscape with magical elements",
"Urban street scene at golden hour",
"Abstract art with vibrant colors",
"Historical scene with period accuracy"
]
=== requirements.txt ===
streamlit
pillow
numpy
requests
base64
time |