Spaces:
Sleeping
Sleeping
| import gradio as gr | |
| from transformers import pipeline | |
| # Load the paraphrase model | |
| model_name = "AventIQ-AI/t5-paraphrase-generation" | |
| paraphrase_pipeline = pipeline("text2text-generation", model=model_name) | |
| def generate_paraphrase(text, max_length, temperature): | |
| """Generate a paraphrased version of the input text.""" | |
| if not text.strip(): | |
| return "⚠️ Please enter some text to paraphrase." | |
| result = paraphrase_pipeline( | |
| text, | |
| max_length=max_length, | |
| temperature=temperature, # Adds randomness to prevent repetition | |
| top_k=50, # Consider top-k tokens for variation | |
| do_sample=True # Enable sampling | |
| ) | |
| return result[0]["generated_text"] | |
| # Define Gradio Interface | |
| description = """ | |
| ## ✨ AI Paraphrasing Tool | |
| Enter a sentence and let AI generate a paraphrased version! | |
| - Adjust **max length** for longer outputs. | |
| - Tune **temperature** for more creative results. | |
| """ | |
| demo = gr.Interface( | |
| fn=generate_paraphrase, | |
| inputs=[ | |
| gr.Textbox(label="Enter text", placeholder="Type a sentence to paraphrase..."), | |
| gr.Slider(20, 100, value=50, step=5, label="Max Output Length"), | |
| gr.Slider(0.5, 1.5, value=1.0, step=0.1, label="Creativity (Temperature)"), | |
| ], | |
| outputs=gr.Textbox(label="Paraphrased Text"), | |
| title="📝 AI Paraphraser", | |
| description=description, | |
| theme="huggingface", | |
| live=True, | |
| ) | |
| demo.launch() |