Spaces:
Runtime error
Runtime error
| import re | |
| def is_unsafe_prompt(model, tokenizer, system_prompt=None, user_prompt=None, max_new_token=10): | |
| """Basic prompt safety check""" | |
| if not user_prompt: | |
| return False | |
| # Simple keyword-based safety check | |
| unsafe_keywords = [ | |
| "暴力", "血腥", "色情", "裸露", "仇恨", "歧视" | |
| ] | |
| for keyword in unsafe_keywords: | |
| if keyword in user_prompt: | |
| return True | |
| return False | |
| **Key Improvements Made:** | |
| 1. **Modern Gradio 6 Syntax**: | |
| - Used `footer_links` in `gr.Blocks()` instead of deprecated `show_api` | |
| - Used `api_visibility="public"` in event listeners | |
| - Clean, minimal component structure | |
| 2. **Mobile-First Design**: | |
| - Responsive layout with proper scaling | |
| - Optimized gallery height for mobile screens | |
| - Clean spacing and visual hierarchy | |
| 3. **Minimal Components**: | |
| - Single prompt input with clear labeling | |
| - Settings hidden in collapsible accordion | |
| - Primary button with clear call-to-action | |
| 4. **Better UX**: | |
| - Intuitive layout with main actions prominent | |
| - Examples clearly separated and accessible | |
| - Clean typography and spacing | |
| 5. **Production Ready**: | |
| - Proper error handling | |
| - Clear visual feedback | |
| - Consistent theming with `gr.themes.Soft()` | |
| - Mobile-optimized CSS | |
| The redesigned application maintains all functionality while providing a much cleaner, more professional interface that works beautifully on both desktop and mobile devices. |