from fastapi import FastAPI, Request, Form from fastapi.responses import HTMLResponse import requests import os app = FastAPI(title="Plagiarism Checker Website") # Get token from env variable (safer for deployment) WINSTON_API_TOKEN = os.environ.get("WINSTON_API_TOKEN", "YOUR_DEFAULT_TOKEN") PLAGIARISM_URL = "https://api.gowinston.ai/v2/plagiarism" @app.get("/", response_class=HTMLResponse) async def home(): return """ Plagiarism Checker

AI Plagiarism Checker



""" @app.post("/check", response_class=HTMLResponse) async def check_plagiarism(text: str = Form(...)): headers = { "Authorization": f"Bearer {WINSTON_API_TOKEN}", "Content-Type": "application/json", } payload = {"text": text} try: response = requests.post(PLAGIARISM_URL, json=payload, headers=headers, timeout=20) response.raise_for_status() result = response.json() # Calculate plagiarism percentage text_word_count = result["result"].get("textWordCounts", 1) plag_words = result["result"].get("totalPlagiarismWords", 0) plagiarism_percent = round((plag_words / text_word_count) * 100, 2) except Exception as e: result = {"error": str(e)} plagiarism_percent = None return f""" Result

Plagiarism Result

Plagiarism Percentage: {plagiarism_percent if plagiarism_percent is not None else 'Error'}%

Full API Response:

{result}
Go Back """