Update app.py
Browse files
app.py
CHANGED
@@ -1,44 +1,48 @@
|
|
1 |
-
import gradio as gr
|
2 |
-
from transformers import pipeline
|
3 |
-
|
4 |
-
# Load the paraphrase model
|
5 |
-
model_name = "AventIQ-AI/t5-paraphrase-generation"
|
6 |
-
paraphrase_pipeline = pipeline("text2text-generation", model=model_name)
|
7 |
-
|
8 |
-
def generate_paraphrase(text,
|
9 |
-
"""Generate a paraphrased version of the input text."""
|
10 |
-
if not text.strip():
|
11 |
-
return "⚠️ Please enter some text to paraphrase."
|
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 |
-
|
|
|
|
|
|
|
|
|
|
1 |
+
import gradio as gr
|
2 |
+
from transformers import pipeline
|
3 |
+
|
4 |
+
# Load the paraphrase model
|
5 |
+
model_name = "AventIQ-AI/t5-paraphrase-generation"
|
6 |
+
paraphrase_pipeline = pipeline("text2text-generation", model=model_name)
|
7 |
+
|
8 |
+
def generate_paraphrase(text, temperature):
|
9 |
+
"""Generate a paraphrased version of the input text."""
|
10 |
+
if not text.strip():
|
11 |
+
return "⚠️ Please enter some text to paraphrase."
|
12 |
+
|
13 |
+
# Limit input to 700 words
|
14 |
+
words = text.split()
|
15 |
+
if len(words) > 700:
|
16 |
+
return "⚠️ Please enter a maximum of 700 words."
|
17 |
+
|
18 |
+
result = paraphrase_pipeline(
|
19 |
+
text,
|
20 |
+
temperature=temperature, # Adds randomness to prevent repetition
|
21 |
+
top_k=50, # Consider top-k tokens for variation
|
22 |
+
do_sample=True # Enable sampling
|
23 |
+
)
|
24 |
+
|
25 |
+
return result[0]["generated_text"]
|
26 |
+
|
27 |
+
# Define Gradio Interface
|
28 |
+
description = """
|
29 |
+
## ✨ AI Paraphrasing Tool
|
30 |
+
Enter text and let AI generate a paraphrased version!
|
31 |
+
- **Creativity (Temperature)** controls how varied the output is.
|
32 |
+
- **Input is limited to 700 words.**
|
33 |
+
"""
|
34 |
+
|
35 |
+
demo = gr.Interface(
|
36 |
+
fn=generate_paraphrase,
|
37 |
+
inputs=[
|
38 |
+
gr.Textbox(label="Enter text", placeholder="Type your text to paraphrase...", lines=5),
|
39 |
+
gr.Slider(0.5, 1.5, value=1.0, step=0.1, label="Creativity (Temperature)"),
|
40 |
+
],
|
41 |
+
outputs=gr.Textbox(label="Paraphrased Text"),
|
42 |
+
title="📝 AI Paraphraser",
|
43 |
+
description=description,
|
44 |
+
theme="huggingface",
|
45 |
+
live=True,
|
46 |
+
)
|
47 |
+
|
48 |
+
demo.launch()
|