eradhea commited on
Commit
312d685
·
1 Parent(s): 74d9916

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +17 -3
app.py CHANGED
@@ -1,6 +1,8 @@
1
  from transformers import BlenderbotTokenizer, BlenderbotForConditionalGeneration, pipeline
2
  import gradio as gr
3
 
 
 
4
  mname = "facebook/blenderbot-400M-distill"
5
 
6
  model = BlenderbotForConditionalGeneration.from_pretrained(mname)
@@ -11,20 +13,32 @@ to_english = pipeline('translation', model='Helsinki-NLP/opus-mt-es-en')
11
 
12
  to_spanish = pipeline('translation', model='Helsinki-NLP/opus-mt-en-es')
13
 
14
- def chat(message, history):
 
 
 
15
 
16
  history = history or []
17
- mensaje = message
18
  MESSAGE = to_english(mensaje)
 
19
  inputs = tokenizer([MESSAGE[0]['translation_text']], return_tensors="pt")
 
20
  reply_ids = model.generate(**inputs)
 
21
  respuesta = to_spanish(tokenizer.batch_decode(reply_ids))
22
- history.append((msg,respuesta[0]['translation_text']))
 
 
23
 
24
  return history, history
25
 
 
 
26
  chatbot = gr.Chatbot().style(color_map=("red", "blue"))
27
 
 
 
28
  gr.Interface(
29
  chat,
30
  ["text", "state"],
 
1
  from transformers import BlenderbotTokenizer, BlenderbotForConditionalGeneration, pipeline
2
  import gradio as gr
3
 
4
+
5
+
6
  mname = "facebook/blenderbot-400M-distill"
7
 
8
  model = BlenderbotForConditionalGeneration.from_pretrained(mname)
 
13
 
14
  to_spanish = pipeline('translation', model='Helsinki-NLP/opus-mt-en-es')
15
 
16
+
17
+
18
+
19
+ def chat(mensaje, history):
20
 
21
  history = history or []
22
+
23
  MESSAGE = to_english(mensaje)
24
+
25
  inputs = tokenizer([MESSAGE[0]['translation_text']], return_tensors="pt")
26
+
27
  reply_ids = model.generate(**inputs)
28
+
29
  respuesta = to_spanish(tokenizer.batch_decode(reply_ids))
30
+
31
+ history.append((msg, respuesta[0]['translation_text']))
32
+
33
 
34
  return history, history
35
 
36
+
37
+
38
  chatbot = gr.Chatbot().style(color_map=("red", "blue"))
39
 
40
+
41
+
42
  gr.Interface(
43
  chat,
44
  ["text", "state"],