Spaces:
Sleeping
Sleeping
albin
commited on
Commit
·
70e9963
1
Parent(s):
0bc5b30
add html and main
Browse files- Dockerfile +20 -0
- main.py +32 -0
- requirements.txt +18 -0
- templates/index.html +94 -0
Dockerfile
ADDED
|
@@ -0,0 +1,20 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
FROM python:3.9
|
| 2 |
+
|
| 3 |
+
WORKDIR /code
|
| 4 |
+
|
| 5 |
+
COPY ./requirements.txt /code/requirements.txt
|
| 6 |
+
|
| 7 |
+
RUN pip install --no-cache-dir --upgrade -r /code/requirements.txt
|
| 8 |
+
|
| 9 |
+
RUN useradd -m -u 1000 user
|
| 10 |
+
|
| 11 |
+
USER user
|
| 12 |
+
|
| 13 |
+
ENV HOME=/home/user \
|
| 14 |
+
PATH=/home/user/.local/bin:$PATH
|
| 15 |
+
|
| 16 |
+
WORKDIR $HOME/app
|
| 17 |
+
|
| 18 |
+
COPY --chown=user . $HOME/app
|
| 19 |
+
|
| 20 |
+
CMD ["uvicorn", "main:app", "--host", "0.0.0.0", "--port", "7860"]
|
main.py
ADDED
|
@@ -0,0 +1,32 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
#!/usr/bin/env python
|
| 2 |
+
# encoding: utf-8
|
| 3 |
+
|
| 4 |
+
from fastapi import FastAPI, Form, Depends, Request
|
| 5 |
+
from fastapi.templating import Jinja2Templates
|
| 6 |
+
from pydantic import BaseModel
|
| 7 |
+
import pickle
|
| 8 |
+
import json
|
| 9 |
+
|
| 10 |
+
app = FastAPI()
|
| 11 |
+
|
| 12 |
+
templates = Jinja2Templates(directory="templates")
|
| 13 |
+
|
| 14 |
+
class Msg(BaseModel):
|
| 15 |
+
msg: str
|
| 16 |
+
|
| 17 |
+
class Req(BaseModel):
|
| 18 |
+
url: str
|
| 19 |
+
|
| 20 |
+
@app.get("/welcomeMessage")
|
| 21 |
+
async def welcome():
|
| 22 |
+
return {"message": "Hello, Welcome to the final project from Albin Tardivel"}
|
| 23 |
+
|
| 24 |
+
@app.get("/")
|
| 25 |
+
async def root(request: Request):
|
| 26 |
+
return templates.TemplateResponse(
|
| 27 |
+
"index.html",
|
| 28 |
+
{
|
| 29 |
+
"request": request,
|
| 30 |
+
"label": "",
|
| 31 |
+
}
|
| 32 |
+
)
|
requirements.txt
ADDED
|
@@ -0,0 +1,18 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
anyio>=3.7.1
|
| 2 |
+
click==8.1.7
|
| 3 |
+
fastapi==0.103.2
|
| 4 |
+
h11==0.14.0
|
| 5 |
+
httptools==0.6.0
|
| 6 |
+
idna==3.4
|
| 7 |
+
pydantic==2.4.2
|
| 8 |
+
python-dotenv==1.0.0
|
| 9 |
+
python-multipart==0.0.6
|
| 10 |
+
PyYAML==6.0.1
|
| 11 |
+
sniffio==1.3.0
|
| 12 |
+
starlette>=0.27.0
|
| 13 |
+
typing_extensions==4.8.0
|
| 14 |
+
uvicorn==0.23.2
|
| 15 |
+
watchfiles==0.20.0
|
| 16 |
+
websockets==11.0.3
|
| 17 |
+
scikit-learn
|
| 18 |
+
jinja2
|
templates/index.html
ADDED
|
@@ -0,0 +1,94 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
<!DOCTYPE html>
|
| 2 |
+
<html lang="en">
|
| 3 |
+
<head>
|
| 4 |
+
<meta charset="UTF-8" />
|
| 5 |
+
<meta http-equiv="X-UA-Compatible" content="IE=edge" />
|
| 6 |
+
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
|
| 7 |
+
<link href="https://unpkg.com/tailwindcss@^2/dist/tailwind.min.css" rel="stylesheet" />
|
| 8 |
+
<script src="https://code.jquery.com/jquery-3.6.0.min.js"></script>
|
| 9 |
+
<title>Prediction URL Legitimate or Phishing</title>
|
| 10 |
+
</head>
|
| 11 |
+
|
| 12 |
+
<body>
|
| 13 |
+
<div id="Model1" class="Model bg-gradient-to-r from-purple-400 to-purple-700 text-gray-800">
|
| 14 |
+
<section class="flex flex-col justify-between item-center p-8 min-h-screen md:flex-row">
|
| 15 |
+
<main class="bg-white p-16 rounded-lg">
|
| 16 |
+
<h1 class="text-3xl font-bold mb-8">Test if your URL is Phinshing or Legitimate:</h1>
|
| 17 |
+
|
| 18 |
+
<form enctype="multipart/form-data" class="flex flex-col" id="upload_form">
|
| 19 |
+
<label for="url" class="mb-2">Write your URL</label>
|
| 20 |
+
<input type="text" name="url" placeholder="URL" required="required" class="p-4 bg-gray-100 rounded-md" />
|
| 21 |
+
|
| 22 |
+
<button type="submit" class="flex justify-center align-center mt-8 p-4 bg-gradient-to-r from-purple-400 to-purple-700 text-white rounded-md">
|
| 23 |
+
TEST URL<svg xmlns="http://www.w3.org/2000/svg" width="24" height="24" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" class="feather feather-arrow-right ml-4">
|
| 24 |
+
<line x1="5" y1="12" x2="19" y2="12"></line>
|
| 25 |
+
<polyline points="12 5 19 12 12 19"></polyline>
|
| 26 |
+
</svg>
|
| 27 |
+
</button>
|
| 28 |
+
</form>
|
| 29 |
+
</main>
|
| 30 |
+
<section class="mt-8 h-full flex-auto rounded-lg md:mt-0 md:ml-8">
|
| 31 |
+
<div class="bg-white p-16 rounded-lg">
|
| 32 |
+
<h1 class="text-2xl mb-8">Your URL is:</h1>
|
| 33 |
+
<h2 class="text-5xl font-bold">$<span id="label">response</span></h2>
|
| 34 |
+
<div class="mt-8">
|
| 35 |
+
<p id="respUrl"></p>
|
| 36 |
+
</div>
|
| 37 |
+
</div>
|
| 38 |
+
<div class="flex justify-around p-16 rounded-lg mt-8">
|
| 39 |
+
<img class="h-24 md:h-28" src="https://elib.its.ac.id/conf/cyberdas/public/assets/img/img_navbar.svg" alt="logo-dts" />
|
| 40 |
+
</div>
|
| 41 |
+
</section>
|
| 42 |
+
</section>
|
| 43 |
+
</div>
|
| 44 |
+
|
| 45 |
+
<style>
|
| 46 |
+
.active {
|
| 47 |
+
background-color: rgb(124 58 237);
|
| 48 |
+
}
|
| 49 |
+
</style>
|
| 50 |
+
</body>
|
| 51 |
+
|
| 52 |
+
<script>
|
| 53 |
+
function openModel(evt, modelName) {
|
| 54 |
+
var i, x, tablinks;
|
| 55 |
+
x = document.getElementsByClassName("Model");
|
| 56 |
+
for (i = 0; i < x.length; i++) {
|
| 57 |
+
x[i].style.display = "none";
|
| 58 |
+
}
|
| 59 |
+
tablinks = document.getElementsByClassName("tablink");
|
| 60 |
+
for (i = 0; i < x.length; i++) {
|
| 61 |
+
tablinks[i].className = tablinks[i].className.replace(" active", "");
|
| 62 |
+
}
|
| 63 |
+
document.getElementById(modelName).style.display = "block";
|
| 64 |
+
evt.currentTarget.className += " active";
|
| 65 |
+
}
|
| 66 |
+
</script>
|
| 67 |
+
<script>
|
| 68 |
+
$(document).ready(function () {
|
| 69 |
+
$("#upload_form").submit(function (event) {
|
| 70 |
+
event.preventDefault(); // Prevent the default form submission
|
| 71 |
+
// Get the form data
|
| 72 |
+
var formData = new FormData(this);
|
| 73 |
+
// Make the Ajax request
|
| 74 |
+
$.ajax({
|
| 75 |
+
type: "POST",
|
| 76 |
+
url: "https://binoubinks-adsp-finalprojectback.hf.space",
|
| 77 |
+
data: formData,
|
| 78 |
+
processData: false,
|
| 79 |
+
contentType: false,
|
| 80 |
+
success: function (response) {
|
| 81 |
+
// Handle the response data
|
| 82 |
+
$('#respUrl').html("<strong>Url:</strong> " + response.url);
|
| 83 |
+
$('#label').html(response.label);
|
| 84 |
+
console.log(response);
|
| 85 |
+
},
|
| 86 |
+
error: function (error) {
|
| 87 |
+
console.error("Error:", error);
|
| 88 |
+
}
|
| 89 |
+
});
|
| 90 |
+
});
|
| 91 |
+
});
|
| 92 |
+
</script>
|
| 93 |
+
</body>
|
| 94 |
+
</html>
|