Spaces:
Running
Running
Upload 3 files
Browse files- README.md +25 -12
- app.py +49 -0
- requirements.txt +4 -0
README.md
CHANGED
|
@@ -1,12 +1,25 @@
|
|
| 1 |
-
|
| 2 |
-
|
| 3 |
-
|
| 4 |
-
|
| 5 |
-
|
| 6 |
-
|
| 7 |
-
|
| 8 |
-
|
| 9 |
-
|
| 10 |
-
|
| 11 |
-
|
| 12 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
# 🎓 Chat PT-EN com Tradução Simultânea
|
| 2 |
+
|
| 3 |
+
Este projeto implementa um **chat bilíngue** em tempo real:
|
| 4 |
+
- Funcionário escreve em **Português** → tradução automática para **Inglês**.
|
| 5 |
+
- Estudante escreve em **Inglês** → tradução automática para **Português**.
|
| 6 |
+
- Cada lado tem seu **campo de input e botão próprio**.
|
| 7 |
+
|
| 8 |
+
---
|
| 9 |
+
|
| 10 |
+
## 🚀 Como usar
|
| 11 |
+
1. O **Funcionário** digita sua mensagem em português e clica em **Enviar Funcionário**.
|
| 12 |
+
2. O **Estudante** digita em inglês e clica em **Enviar Estudante**.
|
| 13 |
+
3. O histórico do chat mostra a mensagem no idioma original + tradução correspondente.
|
| 14 |
+
|
| 15 |
+
---
|
| 16 |
+
|
| 17 |
+
## 🛠️ Tecnologias
|
| 18 |
+
- [Gradio](https://www.gradio.app/) para a interface.
|
| 19 |
+
- [Transformers](https://huggingface.co/docs/transformers) para tradução.
|
| 20 |
+
- Modelos da **Unicamp-DL**:
|
| 21 |
+
- [unicamp-dl/translation-pt-en-t5-large-v2](https://huggingface.co/unicamp-dl/translation-pt-en-t5-large-v2)
|
| 22 |
+
- [unicamp-dl/translation-en-pt-t5-large-v2](https://huggingface.co/unicamp-dl/translation-en-pt-t5-large-v2)
|
| 23 |
+
|
| 24 |
+
---
|
| 25 |
+
|
app.py
ADDED
|
@@ -0,0 +1,49 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
#Esboço de App de Tradução
|
| 2 |
+
import gradio as gr
|
| 3 |
+
from transformers import pipeline
|
| 4 |
+
|
| 5 |
+
# Carregar modelos de tradução
|
| 6 |
+
pt_en_translator = pipeline("translation", model="unicamp-dl/translation-pt-en-t5-large-v2")
|
| 7 |
+
en_pt_translator = pipeline("translation", model="unicamp-dl/translation-en-pt-t5-large-v2")
|
| 8 |
+
|
| 9 |
+
def traduzir_pt_en(texto):
|
| 10 |
+
return pt_en_translator(texto, max_length=512)[0]["translation_text"]
|
| 11 |
+
|
| 12 |
+
def traduzir_en_pt(texto):
|
| 13 |
+
return en_pt_translator(texto, max_length=512)[0]["translation_text"]
|
| 14 |
+
|
| 15 |
+
def enviar_funcionario(msg_pt, history):
|
| 16 |
+
traducao = traduzir_pt_en(msg_pt)
|
| 17 |
+
resposta = f"Funcionário (PT): {msg_pt}\n*(Translation: {traducao})*"
|
| 18 |
+
history = history + [(msg_pt, resposta)]
|
| 19 |
+
return "", history
|
| 20 |
+
|
| 21 |
+
def enviar_estudante(msg_en, history):
|
| 22 |
+
traducao = traduzir_en_pt(msg_en)
|
| 23 |
+
resposta = f"Student (EN): {msg_en}\n*(Tradução: {traducao})*"
|
| 24 |
+
history = history + [(msg_en, resposta)]
|
| 25 |
+
return "", history
|
| 26 |
+
|
| 27 |
+
with gr.Blocks() as demo:
|
| 28 |
+
gr.Markdown("## 🎓 Chat PT-EN com Tradução Simultânea")
|
| 29 |
+
gr.Markdown("Dois usuários podem conversar: **Funcionário (PT)** ↔ **Estudante (EN)**. Cada fala aparece com tradução automática.")
|
| 30 |
+
|
| 31 |
+
chatbot = gr.Chatbot(label="Chat Funcionário ↔ Estudante", bubble_full_width=False)
|
| 32 |
+
|
| 33 |
+
with gr.Row():
|
| 34 |
+
with gr.Column():
|
| 35 |
+
msg_func = gr.Textbox(label="Mensagem do Funcionário (PT)", placeholder="Digite em Português...")
|
| 36 |
+
btn_func = gr.Button("Enviar Funcionário")
|
| 37 |
+
with gr.Column():
|
| 38 |
+
msg_est = gr.Textbox(label="Mensagem do Estudante (EN)", placeholder="Digite em Inglês...")
|
| 39 |
+
btn_est = gr.Button("Enviar Estudante")
|
| 40 |
+
|
| 41 |
+
clear = gr.Button("Limpar conversa")
|
| 42 |
+
|
| 43 |
+
btn_func.click(enviar_funcionario, [msg_func, chatbot], [msg_func, chatbot])
|
| 44 |
+
btn_est.click(enviar_estudante, [msg_est, chatbot], [msg_est, chatbot])
|
| 45 |
+
clear.click(lambda: None, None, chatbot, queue=False)
|
| 46 |
+
|
| 47 |
+
if __name__ == "__main__":
|
| 48 |
+
demo.launch()
|
| 49 |
+
|
requirements.txt
ADDED
|
@@ -0,0 +1,4 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
gradio
|
| 2 |
+
transformers
|
| 3 |
+
torch
|
| 4 |
+
sentencepiece
|