bazil3814 commited on
Commit
e49167e
·
verified ·
1 Parent(s): 686eef7

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +19 -12
app.py CHANGED
@@ -4,8 +4,8 @@ import torch
4
 
5
  @st.cache_resource
6
  def load_model():
7
- tokenizer = T5Tokenizer.from_pretrained("Vamsi/T5_Paraphrase_Paws")
8
- model = T5ForConditionalGeneration.from_pretrained("Vamsi/T5_Paraphrase_Paws")
9
  return tokenizer, model
10
 
11
  def humanize_text(input_text):
@@ -13,24 +13,31 @@ def humanize_text(input_text):
13
  device = "cuda" if torch.cuda.is_available() else "cpu"
14
  model = model.to(device)
15
 
16
- text = "paraphrase: " + input_text + " </s>"
17
- encoding = tokenizer.encode_plus(text, padding="max_length", return_tensors="pt", max_length=256, truncation=True)
18
- input_ids, attention_mask = encoding["input_ids"].to(device), encoding["attention_mask"].to(device)
 
 
 
 
 
 
 
 
 
19
 
20
  output = model.generate(
21
  input_ids=input_ids,
22
  attention_mask=attention_mask,
23
- max_length=256,
24
- do_sample=True,
25
- top_k=120,
26
- top_p=0.95,
27
- early_stopping=True,
28
- num_return_sequences=1
29
  )
30
 
31
  return tokenizer.decode(output[0], skip_special_tokens=True)
32
 
33
- # Streamlit Interface
34
  st.set_page_config(page_title="Humanize AI Text", layout="centered")
35
  st.title("🧠 Humanize AI Text")
36
  st.write("Make AI-generated text sound more human to evade detection.")
 
4
 
5
  @st.cache_resource
6
  def load_model():
7
+ tokenizer = T5Tokenizer.from_pretrained("ramsrigouthamg/t5_paraphraser")
8
+ model = T5ForConditionalGeneration.from_pretrained("ramsrigouthamg/t5_paraphraser")
9
  return tokenizer, model
10
 
11
  def humanize_text(input_text):
 
13
  device = "cuda" if torch.cuda.is_available() else "cpu"
14
  model = model.to(device)
15
 
16
+ prompt = f"paraphrase this text to make it sound more human and natural: {input_text} </s>"
17
+
18
+ encoding = tokenizer.encode_plus(
19
+ prompt,
20
+ padding="max_length",
21
+ return_tensors="pt",
22
+ max_length=512,
23
+ truncation=True
24
+ )
25
+
26
+ input_ids = encoding["input_ids"].to(device)
27
+ attention_mask = encoding["attention_mask"].to(device)
28
 
29
  output = model.generate(
30
  input_ids=input_ids,
31
  attention_mask=attention_mask,
32
+ max_length=512,
33
+ num_beams=5,
34
+ no_repeat_ngram_size=3,
35
+ early_stopping=True
 
 
36
  )
37
 
38
  return tokenizer.decode(output[0], skip_special_tokens=True)
39
 
40
+ # Streamlit UI
41
  st.set_page_config(page_title="Humanize AI Text", layout="centered")
42
  st.title("🧠 Humanize AI Text")
43
  st.write("Make AI-generated text sound more human to evade detection.")