Spaces:
Running
Running
File size: 1,393 Bytes
9d861ad | 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 | # Utility functions for the Gradio application
# This file contains helper functions that can be used in the main app
def validate_input(text: str) -> bool:
"""
Validate that the input text is not empty.
Args:
text: The text to validate
Returns:
bool: True if text is not empty, False otherwise
"""
return bool(text.strip())
def sanitize_text(text: str) -> str:
"""
Sanitize input text by removing leading/trailing whitespace.
Args:
text: The text to sanitize
Returns:
str: The sanitized text
"""
return text.strip()
def format_greeting(name: str, language: str = "ru") -> str:
"""
Format a greeting message based on the selected language.
Args:
name: The name to greet
language: The language code ('ru' for Russian, 'en' for English)
Returns:
str: The formatted greeting message
"""
if language == "ru":
return f"Привет, {name}! Добро пожаловать!"
else:
return f"Hello, {name}! Welcome!"
def calculate_word_count(text: str) -> int:
"""
Calculate the number of words in the text.
Args:
text: The text to analyze
Returns:
int: The word count
"""
if not text:
return 0
words = text.split()
return len(words) |