Spaces:
Runtime error
Runtime error
| """ | |
| Utility functions for the Revert text transformation application. | |
| """ | |
| import re | |
| from typing import List, Tuple | |
| def sanitize_input(text: str) -> str: | |
| """ | |
| Basic input sanitization for text processing. | |
| Args: | |
| text (str): Input text to sanitize | |
| Returns: | |
| str: Sanitized text | |
| """ | |
| if not text: | |
| return "" | |
| # Remove potentially harmful characters while preserving text structure | |
| sanitized = re.sub(r'[<>"\']', '', text) | |
| return sanitized.strip() | |
| def validate_intensity(intensity: float) -> float: | |
| """ | |
| Ensure intensity is within valid range. | |
| Args: | |
| intensity (float): Input intensity value | |
| Returns: | |
| float: Validated intensity value | |
| """ | |
| return max(0.0, min(1.0, intensity)) | |
| def get_operation_description(operation: str) -> str: | |
| """ | |
| Get a human-readable description of each operation. | |
| Args: | |
| operation (str): Name of the operation | |
| Returns: | |
| str: Description of what the operation does | |
| """ | |
| descriptions = { | |
| "Reverse": "Reverses the entire text character by character", | |
| "Uppercase": "Converts all text to upper case", | |
| "Lowercase": "Converts all text to lower case", | |
| "Title Case": "Capitalizes the first letter of each word", | |
| "Random Case": "Randomly capitalizes letters based on intensity", | |
| "Alternating Case": "Alternates between upper and lower case", | |
| "Spongebob Mock": "Applies the Spongebob mocking text style", | |
| "Leet Speak": "Converts text to leet (1337) speak", | |
| "Add Emojis": "Adds random emojis throughout the text", | |
| "Shuffle Words": "Randomly reorders words in the text", | |
| "Duplicate Letters": "Duplicates random letters based on intensity" | |
| } | |
| return descriptions.get(operation, "No description available.") | |
| This Gradio 6 application "Revert" provides: | |
| **Features:** | |
| - Text reversal (classic "revert" functionality) | |
| - Case transformations (upper, lower, title) | |
| - Random case with adjustable intensity | |
| - Alternating case patterns | |
| - Spongebob mocking text style | |
| - Leet speak conversion | |
| - Word shuffling | |
| - Letter duplication | |
| **Gradio 6 Modern Features:** | |
| - Custom theme with Soft design | |
| - Google Font integration (Inter) | |
| - Professional color scheme (indigo primary) | |
| - Responsive layout with rows and columns | |
| - Interactive sliders for intensity control | |
| - Example generation | |
| - Built-in error handling | |
| - Clean, modern UI with proper spacing and sizing | |
| **User Experience:** | |
| - Intuitive interface with clear labels | |
| - Example section for quick testing | |
| - Real-time feedback | |
| - Multiple transformation options | |
| - Adjustable intensity for fine control | |
| The app uses proper Gradio 6 syntax with theme customization in `demo.launch()` and modern component APIs. |