vikigitonga11 commited on
Commit
3f7d7a9
·
verified ·
1 Parent(s): 7086523

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +10 -10
app.py CHANGED
@@ -30,21 +30,21 @@ def paraphrase_text(text):
30
 
31
  sentences = split_sentences(text)
32
 
33
- # Apply T5 paraphrasing with more creativity
34
  paraphrased_results = paraphrase_pipeline(
35
  [f"paraphrase: {sentence} </s>" for sentence in sentences if sentence],
36
- max_length=50,
37
  do_sample=True,
38
- temperature=0.9,
39
- top_p=0.92,
40
  top_k=50,
41
- num_return_sequences=2, # Generate 2 variations per sentence
 
42
  batch_size=8
43
  )
44
 
45
- # Fix: Unpack the nested list correctly
46
- paraphrased_sentences = [result['generated_text'] for results in paraphrased_results for result in results]
47
-
48
  return " ".join(paraphrased_sentences)
49
 
50
  # Define Gradio Interface
@@ -52,8 +52,8 @@ demo = gr.Interface(
52
  fn=paraphrase_text,
53
  inputs=gr.Textbox(label="Enter text", placeholder="Type your text to paraphrase...", lines=10),
54
  outputs=gr.Textbox(label="Paraphrased Text", lines=10),
55
- title="🎨 Creative T5 Paraphraser",
56
- description="Enter text and let AI generate a more creative paraphrased version using T5!",
57
  theme="huggingface"
58
  )
59
 
 
30
 
31
  sentences = split_sentences(text)
32
 
33
+ # Apply T5 paraphrasing with controlled creativity
34
  paraphrased_results = paraphrase_pipeline(
35
  [f"paraphrase: {sentence} </s>" for sentence in sentences if sentence],
36
+ max_length=80,
37
  do_sample=True,
38
+ temperature=0.7, # More controlled creativity
39
+ top_p=0.85, # Reduce randomness
40
  top_k=50,
41
+ repetition_penalty=1.2, # Avoid excessive repetition
42
+ num_return_sequences=1, # Only one paraphrase per sentence
43
  batch_size=8
44
  )
45
 
46
+ # Extract and join paraphrased sentences
47
+ paraphrased_sentences = [result['generated_text'] for result in paraphrased_results]
 
48
  return " ".join(paraphrased_sentences)
49
 
50
  # Define Gradio Interface
 
52
  fn=paraphrase_text,
53
  inputs=gr.Textbox(label="Enter text", placeholder="Type your text to paraphrase...", lines=10),
54
  outputs=gr.Textbox(label="Paraphrased Text", lines=10),
55
+ title="🎨 Controlled T5 Paraphraser",
56
+ description="Enter text and get a well-structured paraphrased version without randomness!",
57
  theme="huggingface"
58
  )
59