NoaiGPT commited on
Commit
d9aa266
1 Parent(s): 2663a06
Files changed (1) hide show
  1. app.py +25 -11
app.py CHANGED
@@ -1,8 +1,8 @@
1
  import gradio as gr
2
  from transformers import AutoTokenizer, AutoModelForSeq2SeqLM
3
  from sentence_splitter import SentenceSplitter
 
4
  import spaces
5
-
6
  device = "cuda"
7
 
8
  tokenizer = AutoTokenizer.from_pretrained("NoaiGPT/777")
@@ -30,33 +30,47 @@ def process_and_generate(text):
30
  return tokenizer.batch_decode(outputs, skip_special_tokens=True)
31
 
32
  paragraphs = text.split('\n\n')
33
- results = []
34
- final_paragraphs = []
35
 
36
  for paragraph in paragraphs:
37
  sentences = splitter.split(paragraph)
38
  paragraph_results = []
39
- final_sentences = []
40
 
41
  for sentence in sentences:
42
  titles = generate_title(sentence)
43
  paragraph_results.append(f"Original: {sentence}\nParaphrases:\n" + "\n".join(titles))
44
- final_sentences.append(titles[0]) # Use the first paraphrase for the final paragraph
 
 
 
 
 
 
 
 
 
 
 
 
 
 
45
 
46
- results.append("\n\n".join(paragraph_results))
47
- final_paragraphs.append(" ".join(final_sentences))
 
48
 
49
- detailed_output = "\n\n---\n\n".join(results)
50
- final_text = "\n\n".join(final_paragraphs)
51
 
52
- return detailed_output, final_text
53
 
54
  iface = gr.Interface(
55
  fn=process_and_generate,
56
  inputs=gr.Textbox(lines=10, label="Input Text"),
57
  outputs=[
58
  gr.Textbox(lines=20, label="Detailed Paraphrases"),
59
- gr.Textbox(lines=10, label="Final Paraphrased Text")
60
  ],
61
  title="Diverse Paraphrase Generator",
62
  description="Generate multiple diverse paraphrases for each sentence in the input text using NoaiGPT/777 model."
 
1
  import gradio as gr
2
  from transformers import AutoTokenizer, AutoModelForSeq2SeqLM
3
  from sentence_splitter import SentenceSplitter
4
+ import itertools
5
  import spaces
 
6
  device = "cuda"
7
 
8
  tokenizer = AutoTokenizer.from_pretrained("NoaiGPT/777")
 
30
  return tokenizer.batch_decode(outputs, skip_special_tokens=True)
31
 
32
  paragraphs = text.split('\n\n')
33
+ detailed_results = []
34
+ all_paraphrases = []
35
 
36
  for paragraph in paragraphs:
37
  sentences = splitter.split(paragraph)
38
  paragraph_results = []
39
+ paragraph_paraphrases = []
40
 
41
  for sentence in sentences:
42
  titles = generate_title(sentence)
43
  paragraph_results.append(f"Original: {sentence}\nParaphrases:\n" + "\n".join(titles))
44
+ paragraph_paraphrases.append(titles)
45
+
46
+ detailed_results.append("\n\n".join(paragraph_results))
47
+ all_paraphrases.append(paragraph_paraphrases)
48
+
49
+ detailed_output = "\n\n---\n\n".join(detailed_results)
50
+
51
+ # Generate all possible combinations of paraphrases for each paragraph
52
+ all_paragraph_combinations = []
53
+ for paragraph_paraphrases in all_paraphrases:
54
+ paragraph_combinations = list(itertools.product(*paragraph_paraphrases))
55
+ all_paragraph_combinations.append([" ".join(combo) for combo in paragraph_combinations])
56
+
57
+ # Join the paragraphs to create full text variations
58
+ all_text_variations = ["\n\n".join(variation) for variation in itertools.product(*all_paragraph_combinations)]
59
 
60
+ # Limit the number of variations to prevent overwhelming output
61
+ max_variations = 10
62
+ all_text_variations = all_text_variations[:max_variations]
63
 
64
+ final_output = "All Paraphrase Combinations:\n\n" + "\n\n---\n\n".join(all_text_variations)
 
65
 
66
+ return detailed_output, final_output
67
 
68
  iface = gr.Interface(
69
  fn=process_and_generate,
70
  inputs=gr.Textbox(lines=10, label="Input Text"),
71
  outputs=[
72
  gr.Textbox(lines=20, label="Detailed Paraphrases"),
73
+ gr.Textbox(lines=20, label="All Paraphrase Combinations")
74
  ],
75
  title="Diverse Paraphrase Generator",
76
  description="Generate multiple diverse paraphrases for each sentence in the input text using NoaiGPT/777 model."