vikigitonga11 commited on
Commit
f11cf0b
·
verified ·
1 Parent(s): 01693b3

Create app.py

Browse files
Files changed (1) hide show
  1. app.py +22 -0
app.py ADDED
@@ -0,0 +1,22 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import gradio as gr
2
+ from transformers import AutoTokenizer, AutoModelForSeq2SeqLM, pipeline
3
+
4
+ # Load PEGASUS model
5
+ model_name = "tuner007/pegasus_paraphrase"
6
+ tokenizer = AutoTokenizer.from_pretrained(model_name)
7
+ model = AutoModelForSeq2SeqLM.from_pretrained(model_name)
8
+
9
+ # Initialize pipeline
10
+ paraphrase_pipeline = pipeline("text2text-generation", model=model, tokenizer=tokenizer, truncation=True)
11
+
12
+ # Paraphrase function
13
+ def paraphrase_text(text):
14
+ sentences = text.split(". ") # Simple sentence split
15
+ paraphrased_sentences = [paraphrase_pipeline(sentence, max_length=60, do_sample=False)[0]['generated_text'] for sentence in sentences]
16
+ return " ".join(paraphrased_sentences)
17
+
18
+ # Gradio interface
19
+ demo = gr.Interface(fn=paraphrase_text, inputs="text", outputs="text", title="Text Paraphraser")
20
+
21
+ # Launch app
22
+ demo.launch()