Spaces:
Sleeping
Sleeping
Download main.py from simrantanwar977/plagiarism-engine: direct link, hf CLI and curl.
- Browser
- Download file 1.74 kB
-
https://huggingface.co/spaces/simrantanwar977/plagiarism-engine/resolve/main/main.py
- Command line
-
hf download hf://spaces/simrantanwar977/plagiarism-engine/main.py
-
curl -L -o main.py https://huggingface.co/spaces/simrantanwar977/plagiarism-engine/resolve/main/main.py
1.74 kB
| from fastapi import FastAPI, HTTPException | |
| from fastapi.middleware.cors import CORSMiddleware | |
| from pydantic import BaseModel, Field | |
| from typing import List, Optional | |
| import os | |
| import asyncio | |
| from engine import run_plagiarism_check | |
| app = FastAPI(title="Plagiarism Engine", version="1.0.0") | |
| app.add_middleware( | |
| CORSMiddleware, | |
| allow_origins=["*"], | |
| allow_methods=["POST", "GET", "OPTIONS"], | |
| allow_headers=["*"], | |
| ) | |
| class CheckRequest(BaseModel): | |
| text: str = Field(..., min_length=100, max_length=15000) | |
| include_academic: bool = True | |
| include_web: bool = True | |
| max_sources: int = Field(10, ge=3, le=20) | |
| class MatchSource(BaseModel): | |
| url: str | |
| title: Optional[str] = None | |
| matched_text: str | |
| similarity: float | |
| source_type: str # "web" | "academic" | |
| class FlaggedSentence(BaseModel): | |
| sentence: str | |
| sentence_index: int | |
| best_similarity: float | |
| sources: List[MatchSource] | |
| class CheckResponse(BaseModel): | |
| overall_plag_percent: float | |
| flagged_sentences: List[FlaggedSentence] | |
| total_sentences: int | |
| queries_made: int | |
| error: Optional[str] = None | |
| async def root(): | |
| return {"status": "ok", "service": "plagiarism-engine"} | |
| async def health(): | |
| return {"status": "healthy"} | |
| async def check(req: CheckRequest): | |
| try: | |
| result = await run_plagiarism_check( | |
| text=req.text, | |
| include_academic=req.include_academic, | |
| include_web=req.include_web, | |
| max_sources=req.max_sources, | |
| ) | |
| return result | |
| except Exception as e: | |
| raise HTTPException(status_code=500, detail=f"Plagiarism check failed: {str(e)}") | |