CarlosUFPE commited on
Commit
966f537
·
verified ·
1 Parent(s): 65ac9bc

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +15 -14
app.py CHANGED
@@ -1,10 +1,9 @@
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")
7
- en_pt_translator = pipeline("translation", model="unicamp-dl/translation-en-pt-t5")
8
 
9
  def traduzir_pt_en(texto):
10
  return pt_en_translator(texto, max_length=512)[0]["translation_text"]
@@ -14,7 +13,7 @@ def traduzir_en_pt(texto):
14
 
15
  def enviar_funcionario(msg_pt, history):
16
  traducao = traduzir_pt_en(msg_pt)
17
- resposta = f"Patrícia (PT): {msg_pt}\n*(Translation: {traducao})*"
18
  history = history + [(msg_pt, resposta)]
19
  return "", history
20
 
@@ -24,26 +23,28 @@ def enviar_estudante(msg_en, history):
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 de Patrícia (PT)", placeholder="Digite em Português...")
36
- btn_func = gr.Button("Enviar mensagem")
37
  with gr.Column():
38
- msg_est = gr.Textbox(label="Student's message (EN)", placeholder="Type in English...")
39
- btn_est = gr.Button("Send message")
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
-
 
 
1
  import gradio as gr
2
  from transformers import pipeline
3
 
4
  # Carregar modelos de tradução
5
+ pt_en_translator = pipeline("translation", model="unicamp-dl/translation-pt-en-t5-large-v2")
6
+ en_pt_translator = pipeline("translation", model="unicamp-dl/translation-en-pt-t5-large-v2")
7
 
8
  def traduzir_pt_en(texto):
9
  return pt_en_translator(texto, max_length=512)[0]["translation_text"]
 
13
 
14
  def enviar_funcionario(msg_pt, history):
15
  traducao = traduzir_pt_en(msg_pt)
16
+ resposta = f"Funcionário (PT): {msg_pt}\n*(Translation: {traducao})*"
17
  history = history + [(msg_pt, resposta)]
18
  return "", history
19
 
 
23
  history = history + [(msg_en, resposta)]
24
  return "", history
25
 
26
+ with gr.Blocks(theme='soft', css="button { background-color: #4F7D51; color: white; padding: 10px 20px; } .gradio-chatbot { background-color: #B8CCD6; } input[type='text'] { border: 1px solid #ccc; padding: 8px; background-color: #fff; }") as demo:
27
+ gr.Markdown("# 🎓 Chat PT-EN com Tradução Simultânea")
28
+ gr.Markdown("### 🎓 PT-EN Chat with Simultaneous Translation")
29
+ gr.Markdown("### Dois usuários podem conversar: **Funcionário (PT)** ↔ **Estudante (EN)**. Cada fala aparece com tradução automática.")
30
+
31
+ # Update chatbot to use type='messages' // Antes havia: bubble_full_width=False
32
+ chatbot = gr.Chatbot(label="Chat Funcionário ↔ Estudante", type='messages')
33
 
34
  with gr.Row():
35
  with gr.Column():
36
+ msg_func = gr.Textbox(label="Mensagem do Funcionário (PT)", placeholder="Digite em Português...")
37
+ btn_func = gr.Button("Enviar (Funcionário)")
38
  with gr.Column():
39
+ msg_est = gr.Textbox(label="Student's Message (EN)", placeholder="Type in English...")
40
+ btn_est = gr.Button("Send (Student)")
41
 
42
  clear = gr.Button("Limpar conversa")
43
 
44
+ # Update click methods to pass chatbot history
45
  btn_func.click(enviar_funcionario, [msg_func, chatbot], [msg_func, chatbot])
46
  btn_est.click(enviar_estudante, [msg_est, chatbot], [msg_est, chatbot])
47
  clear.click(lambda: None, None, chatbot, queue=False)
48
 
49
  if __name__ == "__main__":
50
  demo.launch()