Download app.py from vianshah/hackops1: direct link, hf CLI and curl.
- Browser
- Download file 2.18 kB
-
https://huggingface.co/spaces/vianshah/hackops1/resolve/main/app.py
- Command line
-
hf download hf://spaces/vianshah/hackops1/app.py
-
curl -L -o app.py https://huggingface.co/spaces/vianshah/hackops1/resolve/main/app.py
2.18 kB
| 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" | |
| async def home(): | |
| return """ | |
| <html> | |
| <head> | |
| <title>Plagiarism Checker</title> | |
| </head> | |
| <body style="font-family: Arial, sans-serif; margin: 30px;"> | |
| <h1>AI Plagiarism Checker</h1> | |
| <form action="/check" method="post"> | |
| <textarea name="text" rows="10" cols="70" | |
| placeholder="Paste your text here..."></textarea><br><br> | |
| <button type="submit">Check Plagiarism</button> | |
| </form> | |
| </body> | |
| </html> | |
| """ | |
| 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""" | |
| <html> | |
| <head> | |
| <title>Result</title> | |
| </head> | |
| <body style="font-family: Arial, sans-serif; margin: 30px;"> | |
| <h1>Plagiarism Result</h1> | |
| <p><b>Plagiarism Percentage:</b> {plagiarism_percent if plagiarism_percent is not None else 'Error'}%</p> | |
| <h2>Full API Response:</h2> | |
| <pre>{result}</pre> | |
| <a href="/">Go Back</a> | |
| </body> | |
| </html> | |
| """ | |