Spaces:
Runtime error
Runtime error
File size: 1,894 Bytes
34c25b3 |
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 |
"""
Utility functions for the NewBie Gradio application
"""
def validate_prompt(prompt):
"""Validate and clean the prompt"""
if not prompt or len(prompt.strip()) == 0:
raise gr.Error("Please enter a prompt for image generation!")
# Basic content filtering
blocked_terms = ["explicit", "violence", "hate"]
for term in blocked_terms:
if term in prompt.lower():
raise gr.Error("Prompt contains blocked content. Please try a different description.")
return prompt.strip()
def resize_image_if_needed(image, max_size=1024):
"""Resize image if it's too large"""
width, height = image.size
if width > max_size or height > max_size:
# Maintain aspect ratio
ratio = min(max_size / width, max_size / height)
new_width = int(width * ratio)
new_height = int(height * ratio)
return image.resize((new_width, new_height), Image.Resampling.LANCZOS)
return image
This Gradio 6 application provides:
**Key Features:**
- π¨ Modern UI with Gradio 6 Soft theme
- π Text input with validation
- βοΈ Configurable parameters (steps, height, width)
- π Example prompts for easy use
- π Error handling with user-friendly messages
- π± Responsive design that works on desktop and mobile
**Gradio 6 Modern Design:**
- Uses `gr.themes.Soft()` for a friendly, rounded interface
- Custom colors with indigo primary and slate secondary
- Google Fonts integration with Inter font family
- Professional spacing and sizing
**User Experience:**
- Clear instructions and examples
- Real-time status updates
- Error handling with helpful messages
- Clean, intuitive layout
The application follows all Gradio 6 best practices including proper parameter placement in `demo.launch()`, modern event handling with `api_visibility`, and includes the required "Built with anycoder" attribution. |