-
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.
Merge pull request #11 from baloise/main
Add GUI
- Loading branch information
Showing
4 changed files
with
89 additions
and
11 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
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,14 +1,54 @@ | ||
<!DOCTYPE html> | ||
<html> | ||
<html lang="en"> | ||
<head> | ||
<title>Simple Form</title> | ||
<meta charset="UTF-8"> | ||
<meta name="viewport" content="width=device-width, initial-scale=1.0"> | ||
<title>YoYo MaskR</title> | ||
</head> | ||
<body> | ||
<h1>upload text to mask</h1> | ||
<form method="post"> | ||
<label for="name">Input:</label><br> | ||
<input type="text" id="ipunt" name="input"><br><br> | ||
<input type="submit" value="Submit"> | ||
<h3>Input:</h3> | ||
<form id="inputForm"> | ||
<input type="text" id="inputData" placeholder="Enter text to anonymize" required> | ||
<input type="submit" value="Submit"> | ||
</form> | ||
|
||
<h3>Response:</h3> | ||
<textarea id="responseField" rows="10" cols="50" readonly></textarea> | ||
|
||
<script> | ||
document.getElementById('inputForm').addEventListener('submit', function(event) { | ||
event.preventDefault(); // Prevent the default form submission | ||
|
||
const inputData = document.getElementById('inputData').value; | ||
|
||
// Use a relative URL for the API endpoint | ||
const apiEndpoint = '/api/mask'; // Relative URL | ||
|
||
// Send a POST request to the API | ||
fetch(apiEndpoint, { | ||
method: 'POST', | ||
headers: { | ||
'Content-Type': 'application/json', | ||
}, | ||
body: JSON.stringify({ text: inputData }), // Send the input data as JSON | ||
}) | ||
.then(response => { | ||
if (!response.ok) { | ||
throw new Error('Network response was not ok'); | ||
} | ||
return response.json(); // Parse the JSON response | ||
}) | ||
.then(data => { | ||
console.log('Success:', data); // Handle the success response | ||
// Display the response in the textarea | ||
document.getElementById('responseField').value = JSON.stringify(data, null, 2); // Format the JSON response | ||
}) | ||
.catch((error) => { | ||
console.error('Error:', error); // Handle any errors | ||
// Optionally display the error in the textarea | ||
document.getElementById('responseField').value = 'Error: ' + error.message; | ||
}); | ||
}); | ||
</script> | ||
</body> | ||
</html> | ||
</html> |
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,36 @@ | ||
import pytest | ||
from src.utils.llm import llm_find_entities | ||
|
||
def test_llm_find_entities_basic(): | ||
text = "Tony Stark and Peter Parker walk through New York where Peter wants to show Tony the Broadway." | ||
expected_output = {'#person_1#': {'Tony Stark', 'Tony'}, '#person_2#': {'Peter Parker', 'Peter'}, '#place_1#': {'New York'}, '#place_2#': {'Broadway'}} | ||
result = llm_find_entities(text) | ||
assert result == expected_output | ||
assert result == expected_output | ||
|
||
def test_llm_find_entities_no_entities(): | ||
text = "This is a text without any names of persons or places." | ||
expected_output = {} | ||
result = llm_find_entities(text) | ||
assert result == expected_output | ||
|
||
def test_llm_find_entities_repeated_names(): | ||
text = "Alice and Bob went to Wonderland. Alice met Bob at the Wonderland park." | ||
expected_output = { | ||
"#person_1#": ["Alice"], | ||
"#person_2#": ["Bob"], | ||
"#place_1#": ["Wonderland"], | ||
'#place_2#': ['Wonderland park'] | ||
} | ||
result = llm_find_entities(text) | ||
|
||
def test_llm_find_entities_raw_output(): | ||
text = "Tony Stark and Peter Parker walk through New York where Peter wants to show Tony the Broadway." | ||
result = llm_find_entities(text, raw=True) | ||
print("result") | ||
print(result) | ||
assert isinstance(result, str) | ||
assert "Tony Stark" in result | ||
assert "Peter Parker" in result | ||
assert "New York" in result | ||
assert "Broadway" in result |