Spaces:
Runtime error
Runtime error
added utils
Browse files
utils.py
ADDED
|
@@ -0,0 +1,19 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
from transformers import pipeline
|
| 2 |
+
from sentence_transformers import SentenceTransformer, util
|
| 3 |
+
|
| 4 |
+
# Load models once
|
| 5 |
+
summarizer = pipeline("summarization", model="sshleifer/distilbart-cnn-12-6")
|
| 6 |
+
grammar_tool = language_tool_python.LanguageTool('en-US')
|
| 7 |
+
similarity_model = SentenceTransformer('all-MiniLM-L6-v2')
|
| 8 |
+
|
| 9 |
+
def get_summary(text):
|
| 10 |
+
return summarizer(text, max_length=150, min_length=30, do_sample=False)[0]['summary_text']
|
| 11 |
+
|
| 12 |
+
def check_grammar(text):
|
| 13 |
+
matches = grammar_tool.check(text)
|
| 14 |
+
return language_tool_python.utils.correct(text, matches)
|
| 15 |
+
|
| 16 |
+
def detect_plagiarism(text1, text2):
|
| 17 |
+
embeddings = similarity_model.encode([text1, text2])
|
| 18 |
+
cosine_sim = util.cos_sim(embeddings[0], embeddings[1]).item()
|
| 19 |
+
return f"Similarity score: {cosine_sim:.4f}"
|