Plagiarism Detector

 import difflib

from sklearn.feature_extraction.text import TfidfVectorizer

from sklearn.metrics.pairwise import cosine_similarity


def read_file(filename):

    with open(filename, 'r', encoding='utf-8') as file:

        return file.read()


def basic_diff_score(text1, text2):

    seq = difflib.SequenceMatcher(None, text1, text2)

    return round(seq.ratio() * 100, 2)


def nlp_cosine_similarity(text1, text2):

    tfidf = TfidfVectorizer().fit_transform([text1, text2])

    score = cosine_similarity(tfidf[0:1], tfidf[1:2])

    return round(score[0][0] * 100, 2)


def main():

    file1 = input("Enter path to first file: ")

    file2 = input("Enter path to second file: ")


    text1 = read_file(file1)

    text2 = read_file(file2)


    basic_score = basic_diff_score(text1, text2)

    nlp_score = nlp_cosine_similarity(text1, text2)


    print("\n--- Plagiarism Detection Result ---")

    print(f"Simple Match (difflib): {basic_score}%")

    print(f"Semantic Match (TF-IDF Cosine Similarity): {nlp_score}%")


    if nlp_score > 80:

        print("⚠️ High similarity detected. Possible plagiarism.")

    elif nlp_score > 50:

        print("⚠️ Moderate similarity. Review recommended.")

    else:

        print("✅ Low similarity. Likely original.")


if __name__ == "__main__":

    main()


Online Exam Proctoring Tool

import cv2

import face_recognition

import datetime


def log_alert(msg):

    with open("proctoring_log.txt", "a") as f:

        f.write(f"{datetime.datetime.now()} - {msg}\n")


def main():

    cap = cv2.VideoCapture(0)


    if not cap.isOpened():

        print("Could not access webcam.")

        return


    print("[INFO] Proctoring started. Press 'q' to quit.")


    while True:

        ret, frame = cap.read()

        if not ret:

            break


        # Resize frame for faster processing

        small_frame = cv2.resize(frame, (0, 0), fx=0.25, fy=0.25)

        rgb_small_frame = small_frame[:, :, ::-1]


        # Detect all faces

        face_locations = face_recognition.face_locations(rgb_small_frame)

        face_count = len(face_locations)


        # Draw rectangles around faces

        for (top, right, bottom, left) in face_locations:

            top, right, bottom, left = top*4, right*4, bottom*4, left*4

            cv2.rectangle(frame, (left, top), (right, bottom), (0, 255, 0), 2)


        # Check for multiple faces

        if face_count > 1:

            cv2.putText(frame, "ALERT: Multiple Faces Detected!", (10, 30),

                        cv2.FONT_HERSHEY_SIMPLEX, 0.8, (0, 0, 255), 2)

            log_alert("Multiple faces detected!")


        # Show output

        cv2.imshow("Exam Proctoring Feed", frame)


        # Break on 'q' key

        if cv2.waitKey(1) & 0xFF == ord('q'):

            break


    cap.release()

    cv2.destroyAllWindows()

    print("[INFO] Proctoring ended.")


if __name__ == "__main__":

    main()