Simon Salmon commited on
Commit
449de4f
·
1 Parent(s): 07bf672

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +7 -3
app.py CHANGED
@@ -1,12 +1,16 @@
1
  import torch
2
  from transformers import T5ForConditionalGeneration,T5Tokenizer, AutoTokenizer, AutoModelForSeq2SeqLM
3
  import streamlit as st
 
4
  model_name = st.text_input("Pick a Model", "seduerr/t5-pawraphrase")
5
  model = AutoModelForSeq2SeqLM.from_pretrained(model_name)
6
  tokenizer = AutoTokenizer.from_pretrained("t5-base")
7
 
8
  device = torch.device("cuda" if torch.cuda.is_available() else "cpu")
9
  model = model.to(device)
 
 
 
10
  def translate_to_english(model, tokenizer, text):
11
  translated_text = []
12
  text = "paraphrase: " + text + " </s>"
@@ -16,10 +20,11 @@ def translate_to_english(model, tokenizer, text):
16
  input_ids=input_ids, attention_mask=attention_masks,
17
  do_sample=True,
18
  max_length=256,
 
19
  top_k=120,
20
  top_p=0.98,
21
  early_stopping=True,
22
- num_return_sequences=10
23
  )
24
  for beam_output in beam_outputs:
25
  sent = tokenizer.decode(beam_output, skip_special_tokens=True,clean_up_tokenization_spaces=True)
@@ -27,11 +32,10 @@ def translate_to_english(model, tokenizer, text):
27
  translated_text.append(sent)
28
  return translated_text
29
 
30
- st.title("Auto Translate (To English)")
31
  text = st.text_input("Okay")
32
  st.text("What you wrote: ")
33
  st.write(text)
34
- st.text("English Translation: ")
35
  if text:
36
  translated_text = translate_to_english(model, tokenizer, text)
37
  st.write(translated_text if translated_text else "No translation found")
 
1
  import torch
2
  from transformers import T5ForConditionalGeneration,T5Tokenizer, AutoTokenizer, AutoModelForSeq2SeqLM
3
  import streamlit as st
4
+ st.title("Paraphrase")
5
  model_name = st.text_input("Pick a Model", "seduerr/t5-pawraphrase")
6
  model = AutoModelForSeq2SeqLM.from_pretrained(model_name)
7
  tokenizer = AutoTokenizer.from_pretrained("t5-base")
8
 
9
  device = torch.device("cuda" if torch.cuda.is_available() else "cpu")
10
  model = model.to(device)
11
+ temp = st.sidebar.slider("Temperature", 0.7, 1.5)
12
+ number_of_outputs = st.sidebar.slider("Number of Outputs", 1, 10)
13
+
14
  def translate_to_english(model, tokenizer, text):
15
  translated_text = []
16
  text = "paraphrase: " + text + " </s>"
 
20
  input_ids=input_ids, attention_mask=attention_masks,
21
  do_sample=True,
22
  max_length=256,
23
+ temperature = temp,
24
  top_k=120,
25
  top_p=0.98,
26
  early_stopping=True,
27
+ num_return_sequences=number_of_outputs,
28
  )
29
  for beam_output in beam_outputs:
30
  sent = tokenizer.decode(beam_output, skip_special_tokens=True,clean_up_tokenization_spaces=True)
 
32
  translated_text.append(sent)
33
  return translated_text
34
 
 
35
  text = st.text_input("Okay")
36
  st.text("What you wrote: ")
37
  st.write(text)
38
+ st.text("Output: ")
39
  if text:
40
  translated_text = translate_to_english(model, tokenizer, text)
41
  st.write(translated_text if translated_text else "No translation found")