File size: 1,470 Bytes
4105753
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
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()