File size: 6,377 Bytes
34328d4
 
cff8e7f
34328d4
 
 
 
 
 
cff8e7f
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
34328d4
 
 
cff8e7f
34328d4
 
 
 
 
cff8e7f
 
 
 
 
34328d4
 
 
cff8e7f
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
34328d4
 
 
 
cff8e7f
 
 
 
 
 
34328d4
 
cff8e7f
 
 
 
34328d4
 
cff8e7f
34328d4
 
cff8e7f
 
 
 
 
 
 
34328d4
 
 
cff8e7f
 
 
34328d4
 
 
cff8e7f
34328d4
cff8e7f
 
 
 
 
 
34328d4
 
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
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
"""
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("""<div class="title">Traductor RNN UAC</div><div class="subtitle">Seq2Seq LSTM - CRISP-ML(Q)</div>""")
    with gr.Row():
        inp = gr.Textbox(label="Texto", placeholder="Escribe...", lines=4)
        direction = gr.Radio(["EN -> ES", "ES -> EN"], label="Direccion", value="EN -> ES")
    btn = gr.Button("Traducir", variant="primary", elem_classes="btn")
    out = gr.Textbox(label="Traduccion", lines=4)
    btn.click(fn=translate, inputs=[inp, direction], outputs=out)
    inp.submit(fn=translate, inputs=[inp, direction], outputs=out)

demo.launch()