vianshah commited on
Commit
f25bf25
·
verified ·
1 Parent(s): 82e1ae6

Create app.py

Browse files
Files changed (1) hide show
  1. app.py +67 -0
app.py ADDED
@@ -0,0 +1,67 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ from fastapi import FastAPI, Request, Form
2
+ from fastapi.responses import HTMLResponse
3
+ import requests
4
+ import os
5
+
6
+ app = FastAPI(title="Plagiarism Checker Website")
7
+
8
+ # Get token from env variable (safer for deployment)
9
+ WINSTON_API_TOKEN = os.environ.get("WINSTON_API_TOKEN", "YOUR_DEFAULT_TOKEN")
10
+ PLAGIARISM_URL = "https://api.gowinston.ai/v2/plagiarism"
11
+
12
+
13
+ @app.get("/", response_class=HTMLResponse)
14
+ async def home():
15
+ return """
16
+ <html>
17
+ <head>
18
+ <title>Plagiarism Checker</title>
19
+ </head>
20
+ <body style="font-family: Arial, sans-serif; margin: 30px;">
21
+ <h1>AI Plagiarism Checker</h1>
22
+ <form action="/check" method="post">
23
+ <textarea name="text" rows="10" cols="70"
24
+ placeholder="Paste your text here..."></textarea><br><br>
25
+ <button type="submit">Check Plagiarism</button>
26
+ </form>
27
+ </body>
28
+ </html>
29
+ """
30
+
31
+
32
+ @app.post("/check", response_class=HTMLResponse)
33
+ async def check_plagiarism(text: str = Form(...)):
34
+ headers = {
35
+ "Authorization": f"Bearer {WINSTON_API_TOKEN}",
36
+ "Content-Type": "application/json",
37
+ }
38
+ payload = {"text": text}
39
+
40
+ try:
41
+ response = requests.post(PLAGIARISM_URL, json=payload, headers=headers, timeout=20)
42
+ response.raise_for_status()
43
+ result = response.json()
44
+
45
+ # Calculate plagiarism percentage
46
+ text_word_count = result["result"].get("textWordCounts", 1)
47
+ plag_words = result["result"].get("totalPlagiarismWords", 0)
48
+ plagiarism_percent = round((plag_words / text_word_count) * 100, 2)
49
+
50
+ except Exception as e:
51
+ result = {"error": str(e)}
52
+ plagiarism_percent = None
53
+
54
+ return f"""
55
+ <html>
56
+ <head>
57
+ <title>Result</title>
58
+ </head>
59
+ <body style="font-family: Arial, sans-serif; margin: 30px;">
60
+ <h1>Plagiarism Result</h1>
61
+ <p><b>Plagiarism Percentage:</b> {plagiarism_percent if plagiarism_percent is not None else 'Error'}%</p>
62
+ <h2>Full API Response:</h2>
63
+ <pre>{result}</pre>
64
+ <a href="/">Go Back</a>
65
+ </body>
66
+ </html>
67
+ """