vikigitonga11 commited on
Commit
b282d46
·
verified ·
1 Parent(s): 4105753

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +48 -44
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, max_length, 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
- result = paraphrase_pipeline(
14
- text,
15
- max_length=max_length,
16
- temperature=temperature, # Adds randomness to prevent repetition
17
- top_k=50, # Consider top-k tokens for variation
18
- do_sample=True # Enable sampling
19
- )
20
- return result[0]["generated_text"]
21
-
22
- # Define Gradio Interface
23
- description = """
24
- ## ✨ AI Paraphrasing Tool
25
- Enter a sentence and let AI generate a paraphrased version!
26
- - Adjust **max length** for longer outputs.
27
- - Tune **temperature** for more creative results.
28
- """
29
-
30
- demo = gr.Interface(
31
- fn=generate_paraphrase,
32
- inputs=[
33
- gr.Textbox(label="Enter text", placeholder="Type a sentence to paraphrase..."),
34
- gr.Slider(20, 100, value=50, step=5, label="Max Output Length"),
35
- gr.Slider(0.5, 1.5, value=1.0, step=0.1, label="Creativity (Temperature)"),
36
- ],
37
- outputs=gr.Textbox(label="Paraphrased Text"),
38
- title="📝 AI Paraphraser",
39
- description=description,
40
- theme="huggingface",
41
- live=True,
42
- )
43
-
44
- demo.launch()
 
 
 
 
 
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()