-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
17 changed files
with
436 additions
and
73 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
import fastapi | ||
from fastapi.responses import JSONResponse | ||
from fastapi import Request | ||
from pydantic import BaseModel | ||
from src.utils.replacer import revert_replacements | ||
|
||
router = fastapi.APIRouter() | ||
|
||
class MaskRequest(BaseModel): | ||
text: str | ||
entities: dict | ||
|
||
@router.post("/demask", response_class=JSONResponse, include_in_schema=True) | ||
async def mask(request: MaskRequest): | ||
deanontext = revert_replacements(request.text, request.entities) | ||
return {"deanonymized_text": deanontext} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
import fastapi | ||
from fastapi.responses import HTMLResponse | ||
from fastapi import Request, routing | ||
from fastapi.templating import Jinja2Templates | ||
|
||
templates = Jinja2Templates(directory="src/templates/html") | ||
|
||
router = fastapi.APIRouter() | ||
|
||
@router.get("/demask", response_class=HTMLResponse, include_in_schema=False) | ||
def landing(request: Request): | ||
return templates.TemplateResponse( | ||
request=request, name="demask.html", context={"id": id} | ||
) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
import fastapi | ||
from fastapi.responses import HTMLResponse | ||
from fastapi import Request, routing | ||
from fastapi.templating import Jinja2Templates | ||
|
||
templates = Jinja2Templates(directory="src/templates/html") | ||
|
||
router = fastapi.APIRouter() | ||
|
||
@router.get("/mask", response_class=HTMLResponse, include_in_schema=False) | ||
def landing(request: Request): | ||
return templates.TemplateResponse( | ||
request=request, name="mask.html", context={"id": id} | ||
) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
document.getElementById('inputForm').addEventListener('submit', function(event) { | ||
event.preventDefault(); // Prevent the default form submission | ||
|
||
const inputData = document.getElementById('inputData').value; | ||
const inputDataEntities = JSON.parse(document.getElementById('responseFieldEntities').value); | ||
|
||
// Use a relative URL for the API endpoint | ||
const apiEndpoint = '/api/demask'; // Relative URL | ||
|
||
// Send a POST request to the API | ||
fetch(apiEndpoint, { | ||
method: 'POST', | ||
headers: { | ||
'Content-Type': 'application/json', | ||
}, | ||
body: JSON.stringify({ text: inputData, entities: inputDataEntities}), // Send the input text as JSON | ||
}) | ||
.then(response => { | ||
if (!response.ok) { | ||
throw new Error('Network response was not ok'); | ||
} | ||
return response.json(); // Parse the JSON response | ||
}) | ||
.then(text => { | ||
// Display the response in the textarea | ||
document.getElementById('responseFieldText').value = inputData; // Format the JSON response | ||
document.getElementById('responseFieldDeanonText').value = text.deanonymized_text; // Format the string response | ||
}) | ||
.catch((error) => { | ||
console.error('Error:', error); // Handle any errors | ||
// Optionally display the error in the textarea | ||
document.getElementById('responseFieldDeanonText').value = 'Error: ' + error.message + '\nEntities: ' + inputDataEntities + '\nText: ' + inputData; | ||
}); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
document.getElementById('downloadBtnDemask').addEventListener('click', function() { | ||
// Get the content of the textarea | ||
const Text = document.getElementById('responseFieldDeanonText').value; | ||
|
||
// Create a Blob from the textarea content | ||
const blobText = new Blob([Text], { type: 'text/plain' }); | ||
|
||
// Create a link element | ||
const link = document.createElement('a'); | ||
link.href = URL.createObjectURL(blobText); | ||
link.download = 'yoyo-text.txt'; // Specify the file name | ||
|
||
// Programmatically click the link to trigger the download | ||
link.click(); | ||
|
||
// Clean up and revoke the object URL | ||
URL.revokeObjectURL(link.href); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,47 @@ | ||
document.getElementById('uploadButton').addEventListener('click', function() { | ||
const fileInput = document.getElementById('fileInput'); | ||
const output = document.getElementById('inputData'); | ||
|
||
if (fileInput.files.length === 0) { | ||
output.textContent = 'Please select a file to upload.'; | ||
return; | ||
} | ||
|
||
const file = fileInput.files[0]; | ||
const reader = new FileReader(); | ||
|
||
reader.onload = function(e) { | ||
const fileContent = e.target.result; | ||
output.value = fileContent; // Display the content of the file | ||
}; | ||
|
||
reader.onerror = function(e) { | ||
output.textContent = 'Error reading file: ' + e.target.error; | ||
}; | ||
|
||
reader.readAsText(file); // Read the file as text | ||
}); | ||
|
||
document.getElementById('uploadButtonE').addEventListener('click', function() { | ||
const fileInputE = document.getElementById('fileInputE'); | ||
const output = document.getElementById('responseFieldEntities'); | ||
|
||
if (fileInputE.files.length === 0) { | ||
output.textContent = 'Please select a file to upload.'; | ||
return; | ||
} | ||
|
||
const fileE = fileInputE.files[0]; | ||
const reader = new FileReader(); | ||
|
||
reader.onload = function(e) { | ||
const fileContentE = e.target.result; | ||
output.textContent = fileContentE; // Display the content of the file | ||
}; | ||
|
||
reader.onerror = function(e) { | ||
output.textContent = 'Error reading file: ' + e.target.error; | ||
}; | ||
|
||
reader.readAsText(fileE); // Read the file as text | ||
}); |
File renamed without changes.
File renamed without changes.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,4 @@ | ||
:root { | ||
--background-body: rgb(240, 238, 238); | ||
--background-button: rgb(158, 158, 158); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,93 @@ | ||
<!DOCTYPE html> | ||
<html lang="en"> | ||
<head> | ||
<meta charset="UTF-8"> | ||
<meta name="viewport" content="width=device-width, initial-scale=1.0"> | ||
<title>YoYo MaskЯ</title> | ||
<link rel="icon" type="image/svg+xml" href="/static/public/favicon.svg"> | ||
<link rel="stylesheet" href="/static/styles/colors.css"> | ||
<link rel="stylesheet" href="/static/styles/style.css"> | ||
</head> | ||
<body> | ||
<header> | ||
<div> | ||
<h1>YoYo MaskЯ</h1> | ||
<a href="/"> | ||
<img class="logo" id="AppLogo" src="/static/public/yo-yo-maskr-logo.svg" alt="YoYo MaskR Logo"> | ||
</a> | ||
</div> | ||
</header> | ||
|
||
<main> | ||
<div class="flex-container"> | ||
|
||
<div class="flex-item"> | ||
<h3>Input</h3> | ||
</div> | ||
<div class="flex-item"> | ||
<form id="inputForm"> | ||
<input type="text" id="inputData" placeholder="Enter text to deanonymize or load text from a file" required> | ||
<div class="flex-container"> | ||
<div class="flex-item"> | ||
<input type="submit" value="Submit"> | ||
</div> | ||
</div> | ||
</form> | ||
</div> | ||
|
||
<div class="flex-item"> | ||
<h3>Load from text file</h3> | ||
</div> | ||
<div class="flex-item"> | ||
<input type="file" id="fileInput" accept=".txt"> | ||
<button id="uploadButton">Load</button> | ||
</div> | ||
|
||
<div class="flex-item"> | ||
<h3>Masked Text</h3> | ||
</div> | ||
<div class="flex-item"> | ||
<textarea id="responseFieldText" rows="10" cols="50" readonly></textarea> | ||
</div> | ||
|
||
<div class="flex-item"> | ||
<h3>Entities</h3> | ||
</div> | ||
<div class="flex-item"> | ||
<textarea id="responseFieldEntities" rows="10" cols="50" readonly></textarea> | ||
</div> | ||
|
||
<div class="flex-item"> | ||
<h3>Load entities from text file</h3> | ||
</div> | ||
<div class="flex-item"> | ||
<input type="file" id="fileInputE" accept=".json"> | ||
<button id="uploadButtonE">Load</button> | ||
</div> | ||
|
||
<div class="flex-item"> | ||
<h3>DeMasked text</h3> | ||
</div> | ||
<div class="flex-item"> | ||
<textarea id="responseFieldDeanonText" rows="10" cols="50" readonly></textarea> | ||
</div> | ||
|
||
<div class="flex-item"> | ||
<button id="downloadBtnDemask">Download File</button> | ||
</div> | ||
</main> | ||
|
||
<footer> | ||
<div> | ||
<a href="https://github.com/baloise/yo-yo-maskr"> | ||
<img src="/static/public/github-mark.svg" alt="GitHub" width="30" height="30"> | ||
</a> | ||
</div> | ||
</footer> | ||
|
||
<!-- Link to the external JavaScript file --> | ||
<script src="/static/scripts/demask.js"></script> | ||
<script src="/static/scripts/fileLoader.js"></script> | ||
<script src="/static/scripts/demask_downloader.js"></script> | ||
</body> | ||
</html> |
Oops, something went wrong.