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

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +10 -8
app.py CHANGED
@@ -3,15 +3,15 @@ import re
3
  import torch
4
  from transformers import AutoTokenizer, AutoModelForSeq2SeqLM, pipeline
5
 
6
- # Load T5 paraphrase model (faster than PEGASUS)
7
  model_name = "Vamsi/T5_Paraphrase_Paws"
8
  tokenizer = AutoTokenizer.from_pretrained(model_name)
9
  model = AutoModelForSeq2SeqLM.from_pretrained(model_name, torch_dtype=torch.float16) # Use fp16 for speed
10
 
11
- # Move model to CPU (remove if using GPU)
12
  model.to("cpu")
13
 
14
- # Initialize paraphrase pipeline with optimized settings
15
  paraphrase_pipeline = pipeline(
16
  "text2text-generation",
17
  model=model,
@@ -35,14 +35,16 @@ def paraphrase_text(text):
35
  [f"paraphrase: {sentence} </s>" for sentence in sentences if sentence],
36
  max_length=50,
37
  do_sample=True,
38
- temperature=0.9, # Increase randomness
39
- top_p=0.92, # Nucleus sampling
40
- top_k=50, # Limits next-word options
41
  num_return_sequences=2, # Generate 2 variations per sentence
42
- batch_size=8 # Faster processing
43
  )
44
 
45
- paraphrased_sentences = [result['generated_text'] for result in paraphrased_results]
 
 
46
  return " ".join(paraphrased_sentences)
47
 
48
  # Define Gradio Interface
 
3
  import torch
4
  from transformers import AutoTokenizer, AutoModelForSeq2SeqLM, pipeline
5
 
6
+ # Load T5 paraphrase model
7
  model_name = "Vamsi/T5_Paraphrase_Paws"
8
  tokenizer = AutoTokenizer.from_pretrained(model_name)
9
  model = AutoModelForSeq2SeqLM.from_pretrained(model_name, torch_dtype=torch.float16) # Use fp16 for speed
10
 
11
+ # Move model to CPU
12
  model.to("cpu")
13
 
14
+ # Initialize paraphrase pipeline
15
  paraphrase_pipeline = pipeline(
16
  "text2text-generation",
17
  model=model,
 
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