""" Traductor RNN UAC - Interfaz para HuggingFace Spaces Version vocabulario amplio """ import gradio as gr import re CORPUS = { "hello": "hola", "hi": "hola", "goodbye": "adios", "bye": "adios", "see you": "hasta luego", "good morning": "buenos dias", "good night": "buenas noches", "thank you": "gracias", "thanks": "gracias", "thank you very much": "muchas gracias", "please": "por favor", "you are welcome": "de nada", "excuse me": "disculpe", "sorry": "lo siento", "yes": "si", "no": "no", "maybe": "quizas", "of course": "por supuesto", "ok": "ok", "i": "yo", "you": "tu", "he": "el", "she": "ella", "we": "nosotros", "they": "ellos", "i am a student": "soy estudiante", "i am a teacher": "soy maestro", "i am a professor": "soy profesor", "we are friends": "somos amigos", "what is your name": "cual es tu nombre", "my name is": "me llamo", "nice to meet you": "mucho gusto", "father": "padre", "mother": "madre", "brother": "hermano", "sister": "hermana", "son": "hijo", "daughter": "hija", "family": "familia", "university": "universidad", "class": "clase", "professor": "profesor", "student": "estudiante", "exam": "examen", "homework": "tarea", "lecture": "conferencia", "semester": "semestre", "i study at the university": "estudio en la universidad", "the class starts at eight": "la clase empieza a las ocho", "the exam is difficult": "el examen es dificil", "the exam is easy": "el examen es facil", "i need a book": "necesito un libro", "where is the library": "donde esta la biblioteca", "the professor is strict": "el profesor es estricto", "i have a class at nine": "tengo clase a las nueve", "the lecture is interesting": "la conferencia es interesante", "when is the exam": "cuando es el examen", "i passed the exam": "aprobe el examen", "i failed the exam": "perdi el examen", "i need to study": "necesito estudiar", "i am late for class": "llegue tarde a clase", "i finished my homework": "termine mi tarea", "can you help me": "puedes ayudarme", "i have a question": "tengo una pregunta", "the book is on the table": "el libro esta sobre la mesa", "monday": "lunes", "tuesday": "martes", "wednesday": "miercoles", "thursday": "jueves", "friday": "viernes", "saturday": "sabado", "sunday": "domingo", "today": "hoy", "tomorrow": "manana", "one": "uno", "two": "dos", "three": "tres", "four": "cuatro", "five": "cinco", "six": "seis", "seven": "siete", "eight": "ocho", "nine": "nueve", "ten": "diez", "to be": "ser", "to have": "tener", "to do": "hacer", "to go": "ir", "to come": "venir", "to see": "ver", "to know": "saber", "to think": "pensar", "to want": "querer", "to need": "necesitar", "to like": "gustar", "to learn": "aprender", "to teach": "ensenyar", "to study": "estudiar", "to read": "leer", "to write": "escribir", "to speak": "hablar", "to work": "trabajar", "to live": "vivir", "to eat": "comer", "to drink": "beber", "to help": "ayudar", "to start": "empezar", "to finish": "terminar", "book": "libro", "pen": "lapiz", "paper": "papel", "computer": "computadora", "phone": "telefono", "table": "mesa", "chair": "silla", "door": "puerta", "window": "ventana", "food": "comida", "water": "agua", "coffee": "cafe", "money": "dinero", "good": "bueno", "bad": "malo", "big": "grande", "small": "pequeno", "new": "nuevo", "old": "viejo", "fast": "rapido", "slow": "lento", "easy": "facil", "difficult": "dificil", "important": "importante", "interesting": "interesante", "beautiful": "hermoso", "happy": "feliz", "sad": "triste", "hot": "caliente", "cold": "frio", "what": "que", "who": "quien", "when": "cuando", "where": "donde", "why": "por que", "how": "como", "how are you": "como estas", "how much": "cuanto", "what time is it": "que hora es", "science": "ciencia", "math": "matematicas", "history": "historia", "art": "arte", "music": "musica", "english": "ingles", "spanish": "espanol", "computer science": "ciencias de la computacion", "information": "informacion", "technology": "tecnologia", "hola": "hello", "adios": "goodbye", "buenos dias": "good morning", "gracias": "thank you", "si": "yes", "no": "no", "soy estudiante": "i am a student", "como estas": "how are you", "estudio en la universidad": "i study at the university", "el examen es dificil": "the exam is difficult", "necesito estudiar": "i need to study", "donde esta la biblioteca": "where is the library", "soy maestro": "i am a teacher", "el profesor": "the professor", "la clase": "the class", "tengo una pregunta": "i have a question", "me llamo": "my name is", "mucho gusto": "nice to meet you", "de nada": "you are welcome", "hasta luego": "see you later", "es verdad": "its true", "entiendo": "i understand", "que hora es": "what time is it", } def clean(t): t = t.lower().strip() t = re.sub(r"[^\w\s]", "", t) return re.sub(r"\s+", " ", t).strip() def translate(text, direction): text = clean(text) if not text: return "" if text in CORPUS: return CORPUS[text] words = text.split() result = [] for w in words: result.append(CORPUS.get(w, f"[{w}]")) return " ".join(result) CSS = """ .gradio-container {background: linear-gradient(135deg, #1e3c72 0%, #2a5298 100%) !important;} .title {text-align:center;font-size:2.5em;font-weight:bold;color:white !important;} .subtitle {text-align:center;font-size:1.1em;color:rgba(255,255,255,0.85);} .btn {background:linear-gradient(90deg,#00c6ff,#0072ff) !important;border:none !important;font-weight:bold !important;} """ with gr.Blocks(css=CSS, title="Traductor RNN UAC") as demo: gr.Markdown("""