asd
Browse files
app.py
CHANGED
@@ -180,7 +180,6 @@
|
|
180 |
|
181 |
# # Launch the interface
|
182 |
# iface.launch()
|
183 |
-
|
184 |
import os
|
185 |
import json
|
186 |
import gradio as gr
|
@@ -229,7 +228,6 @@ def correct_grammar(text):
|
|
229 |
inputs = grammar_tokenizer(f'Fix grammatical errors in this sentence: {text}', return_tensors="pt").input_ids.to(device)
|
230 |
outputs = grammar_model.generate(inputs, max_length=256)
|
231 |
corrected_text = grammar_tokenizer.decode(outputs[0], skip_special_tokens=True)
|
232 |
-
print(corrected_text)
|
233 |
return corrected_text
|
234 |
|
235 |
@spaces.GPU
|
@@ -303,16 +301,18 @@ def generate_paraphrases(text, setting, output_format):
|
|
303 |
|
304 |
paraphrases = paraphraser_tokenizer.batch_decode(outputs, skip_special_tokens=True)
|
305 |
|
|
|
|
|
306 |
formatted_output += f"Original sentence {i+1}: {sentence}\n"
|
307 |
-
for j, paraphrase in enumerate(
|
308 |
formatted_output += f" Paraphrase {j}: {paraphrase}\n"
|
309 |
|
310 |
json_output["paraphrased_versions"].append({
|
311 |
f"original_sentence_{i+1}": sentence,
|
312 |
-
"paraphrases":
|
313 |
})
|
314 |
|
315 |
-
all_sentence_paraphrases.append(
|
316 |
formatted_output += "\n"
|
317 |
|
318 |
all_combinations = list(product(*all_sentence_paraphrases))
|
@@ -328,12 +328,11 @@ def generate_paraphrases(text, setting, output_format):
|
|
328 |
# Classify combined versions
|
329 |
human_versions = []
|
330 |
for i, version in enumerate(combined_versions, 1):
|
331 |
-
|
332 |
-
|
333 |
-
formatted_output += f"Version {i}:\n{corrected_version}\n"
|
334 |
formatted_output += f"Classification: {label} (confidence: {score:.2%})\n\n"
|
335 |
if label == "human-produced" or (label == "machine-generated" and score < 0.98):
|
336 |
-
human_versions.append((
|
337 |
|
338 |
formatted_output += "\nHuman-like or Less Confident Machine-generated versions:\n"
|
339 |
for i, (version, label, score) in enumerate(human_versions, 1):
|
|
|
180 |
|
181 |
# # Launch the interface
|
182 |
# iface.launch()
|
|
|
183 |
import os
|
184 |
import json
|
185 |
import gradio as gr
|
|
|
228 |
inputs = grammar_tokenizer(f'Fix grammatical errors in this sentence: {text}', return_tensors="pt").input_ids.to(device)
|
229 |
outputs = grammar_model.generate(inputs, max_length=256)
|
230 |
corrected_text = grammar_tokenizer.decode(outputs[0], skip_special_tokens=True)
|
|
|
231 |
return corrected_text
|
232 |
|
233 |
@spaces.GPU
|
|
|
301 |
|
302 |
paraphrases = paraphraser_tokenizer.batch_decode(outputs, skip_special_tokens=True)
|
303 |
|
304 |
+
corrected_paraphrases = [correct_grammar(paraphrase) for paraphrase in paraphrases]
|
305 |
+
|
306 |
formatted_output += f"Original sentence {i+1}: {sentence}\n"
|
307 |
+
for j, paraphrase in enumerate(corrected_paraphrases, 1):
|
308 |
formatted_output += f" Paraphrase {j}: {paraphrase}\n"
|
309 |
|
310 |
json_output["paraphrased_versions"].append({
|
311 |
f"original_sentence_{i+1}": sentence,
|
312 |
+
"paraphrases": corrected_paraphrases
|
313 |
})
|
314 |
|
315 |
+
all_sentence_paraphrases.append(corrected_paraphrases)
|
316 |
formatted_output += "\n"
|
317 |
|
318 |
all_combinations = list(product(*all_sentence_paraphrases))
|
|
|
328 |
# Classify combined versions
|
329 |
human_versions = []
|
330 |
for i, version in enumerate(combined_versions, 1):
|
331 |
+
label, score = classify_text(version)
|
332 |
+
formatted_output += f"Version {i}:\n{version}\n"
|
|
|
333 |
formatted_output += f"Classification: {label} (confidence: {score:.2%})\n\n"
|
334 |
if label == "human-produced" or (label == "machine-generated" and score < 0.98):
|
335 |
+
human_versions.append((version, label, score))
|
336 |
|
337 |
formatted_output += "\nHuman-like or Less Confident Machine-generated versions:\n"
|
338 |
for i, (version, label, score) in enumerate(human_versions, 1):
|