Eaz123 commited on
Commit
da8ccad
·
verified ·
1 Parent(s): 5d61bbd

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +23 -24
app.py CHANGED
@@ -1,31 +1,30 @@
1
  import gradio as gr
2
- from transformers import AutoTokenizer, AutoModelForSeq2SeqLM
3
 
4
- model_name = "ramsrigouthamg/t5_paraphraser"
5
- tokenizer = AutoTokenizer.from_pretrained(model_name)
6
- model = AutoModelForSeq2SeqLM.from_pretrained(model_name)
 
7
 
8
- def paraphrase_text(text):
9
- input_text = f"paraphrase: {text} </s>"
10
- encoding = tokenizer.encode_plus(input_text, padding=True, return_tensors="pt")
11
- outputs = model.generate(
12
- input_ids=encoding["input_ids"],
13
- attention_mask=encoding["attention_mask"],
14
- max_length=256,
15
- num_return_sequences=1,
16
- do_sample=True,
17
- top_k=120,
18
- top_p=0.95,
19
- early_stopping=True
20
- )
21
- return tokenizer.decode(outputs[0], skip_special_tokens=True)
22
 
23
- iface = gr.Interface(
 
24
  fn=paraphrase_text,
25
- inputs=gr.Textbox(lines=8, label="Enter Text"),
26
- outputs=gr.Textbox(label="Paraphrased Text"),
27
- title="AI Paraphraser Tool",
28
- description="This tool uses T5 to paraphrase your input text."
29
  )
30
 
31
- iface.launch()
 
 
1
  import gradio as gr
2
+ from transformers import T5Tokenizer, T5ForConditionalGeneration
3
 
4
+ # Load pretrained T5 model for paraphrasing
5
+ model_name = "Vamsi/T5_Paraphrase_Paws"
6
+ tokenizer = T5Tokenizer.from_pretrained(model_name)
7
+ model = T5ForConditionalGeneration.from_pretrained(model_name)
8
 
9
+ def paraphrase_text(input_text):
10
+ # Prepare input text
11
+ input_ids = tokenizer.encode("paraphrase: " + input_text + " </s>", return_tensors="pt", max_length=512, truncation=True)
12
+
13
+ # Generate paraphrase
14
+ outputs = model.generate(input_ids, max_length=256, num_return_sequences=1, temperature=1.5)
15
+
16
+ # Decode output
17
+ paraphrased_text = tokenizer.decode(outputs[0], skip_special_tokens=True)
18
+ return paraphrased_text
 
 
 
 
19
 
20
+ # Create Gradio interface
21
+ demo = gr.Interface(
22
  fn=paraphrase_text,
23
+ inputs=gr.Textbox(lines=5, placeholder="Enter text to paraphrase..."),
24
+ outputs="text",
25
+ title="AI Paraphraser",
26
+ description="Paste any English text to get a paraphrased version using T5 model."
27
  )
28
 
29
+ # Expose /run/predict endpoint
30
+ demo.launch()