asd
Browse files
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 |
-
|
34 |
-
|
35 |
|
36 |
for paragraph in paragraphs:
|
37 |
sentences = splitter.split(paragraph)
|
38 |
paragraph_results = []
|
39 |
-
|
40 |
|
41 |
for sentence in sentences:
|
42 |
titles = generate_title(sentence)
|
43 |
paragraph_results.append(f"Original: {sentence}\nParaphrases:\n" + "\n".join(titles))
|
44 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
45 |
|
46 |
-
|
47 |
-
|
|
|
48 |
|
49 |
-
|
50 |
-
final_text = "\n\n".join(final_paragraphs)
|
51 |
|
52 |
-
return detailed_output,
|
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=
|
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."
|