Eaz123 commited on
Commit
fe5d04a
·
verified ·
1 Parent(s): 658ed6e

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +26 -26
app.py CHANGED
@@ -1,40 +1,40 @@
1
- # app.py
2
-
3
  import gradio as gr
4
- from transformers import AutoTokenizer, AutoModelForSeq2SeqLM
5
 
6
- model_name = "Vamsi/T5_Paraphrase_Paws"
7
- tokenizer = AutoTokenizer.from_pretrained(model_name)
8
- model = AutoModelForSeq2SeqLM.from_pretrained(model_name)
 
9
 
10
- def paraphrase(text):
11
  if not text.strip():
12
- return "No input provided."
13
-
14
- input_ids = tokenizer(
15
- "paraphrase: " + text,
16
- return_tensors="pt",
17
- padding="longest",
18
- truncation=True,
19
- max_length=256,
20
- ).input_ids
21
-
22
- outputs = model.generate(
23
- input_ids,
24
  max_length=256,
25
- num_return_sequences=1,
26
  num_beams=5,
27
- temperature=1.5,
 
 
28
  )
29
 
30
- return tokenizer.decode(outputs[0], skip_special_tokens=True)
 
31
 
 
32
  iface = gr.Interface(
33
- fn=paraphrase,
34
- inputs=gr.Textbox(lines=4, label="Enter Text to Paraphrase"),
35
  outputs=gr.Textbox(label="Paraphrased Text"),
36
- title="Paraphraser Tool",
37
- allow_flagging="never",
38
  )
39
 
40
  iface.launch()
 
 
 
1
  import gradio as gr
2
+ from transformers import T5ForConditionalGeneration, T5Tokenizer
3
 
4
+ # Load the model
5
+ model_name = "ramsrigouthamg/t5_paraphraser"
6
+ tokenizer = T5Tokenizer.from_pretrained(model_name)
7
+ model = T5ForConditionalGeneration.from_pretrained(model_name)
8
 
9
+ def paraphrase_text(text):
10
  if not text.strip():
11
+ return "Please enter some text to paraphrase."
12
+
13
+ # Preprocess input
14
+ input_text = "paraphrase: " + text + " </s>"
15
+ encoding = tokenizer.encode_plus(input_text, max_length=256, padding="max_length", return_tensors="pt", truncation=True)
16
+
17
+ # Generate paraphrased output
18
+ generated_ids = model.generate(
19
+ input_ids=encoding["input_ids"],
20
+ attention_mask=encoding["attention_mask"],
 
 
21
  max_length=256,
 
22
  num_beams=5,
23
+ num_return_sequences=1,
24
+ no_repeat_ngram_size=2,
25
+ early_stopping=True
26
  )
27
 
28
+ paraphrased_text = tokenizer.decode(generated_ids[0], skip_special_tokens=True)
29
+ return paraphrased_text
30
 
31
+ # Gradio Interface
32
  iface = gr.Interface(
33
+ fn=paraphrase_text,
34
+ inputs=gr.Textbox(lines=6, placeholder="Enter your text here...", label="Original Text"),
35
  outputs=gr.Textbox(label="Paraphrased Text"),
36
+ title="AI Paraphraser",
37
+ description="An advanced paraphrasing tool using the T5 transformer model."
38
  )
39
 
40
  iface.launch()