diff --git a/src/api/mask.py b/src/api/mask.py index 79208d2..18239d8 100644 --- a/src/api/mask.py +++ b/src/api/mask.py @@ -6,6 +6,7 @@ from src.utils.ano_llm import find_entities as llm_find_entities from src.utils.ano_spacy import Anon_Spacy from src.utils.ano_regex import find_entities as reg_find_entities +from src.utils.env import * router = fastapi.APIRouter() @@ -17,15 +18,31 @@ class BackendType(Enum): class MaskRequest(BaseModel): text: str backendType: BackendType + llmURL: str + llmModel: str ano = Anon_Spacy() +def check_parameter(param): + if not param: # This checks if param is empty (None, '', [], etc.) + print(f"The parameter is empty. Setting to default value from ENV if existing.") + return 0 + else: + print(f"The parameter is not empty: {param}") + return 1 + @router.post("/mask", response_class=JSONResponse, include_in_schema=True) async def mask(request: MaskRequest): match request.backendType: case BackendType.LLM: - llm_entities = llm_find_entities(request.text) + if check_parameter(request.llmURL) == 0: + request.llmURL = OLLAMA_BASE_URL + + if check_parameter(request.llmModel) == 0: + request.llmModel = OLLAMA_MODEL + + llm_entities = llm_find_entities(text=request.text, base_url=request.llmURL, model=request.llmModel) return {"original_text": request.text, "entities": llm_entities['replace_dict'], "anonymized_text": llm_entities['text']} case BackendType.NER: spacy_entities = ano.find_entities(request.text) diff --git a/src/static/scripts/mask.js b/src/static/scripts/mask.js index e1ba47a..5023482 100644 --- a/src/static/scripts/mask.js +++ b/src/static/scripts/mask.js @@ -1,9 +1,29 @@ +document.getElementById('backendType').addEventListener('change', function() { + var llmInputCheckbox = document.getElementById('LLMcustomLabel'); + if (this.value === 'LLM') { + llmInputCheckbox.style.display = 'flex'; + } else { + llmInputCheckbox.style.display = 'none'; + } +}); + +document.getElementById('LLMcustom').addEventListener('change', function() { + var llmInputDiv = document.getElementById('LLMInput'); + if (this.checked === true) { + llmInputDiv.style.display = 'flex'; // Show the LLMInput div + } else { + llmInputDiv.style.display = 'none'; // Hide the LLMInput div + } +}); + document.getElementById('inputForm').addEventListener('submit', function(event) { event.preventDefault(); // Prevent the default form submission const inputData = document.getElementById('inputData').value; const backendType = document.getElementById('backendType').value; - + const inputLLMurl = document.getElementById('inputLLMurl').value; + const inputLLMmodel = document.getElementById('inputLLMmodel').value; + // Use a relative URL for the API endpoint const apiEndpoint = '/api/mask'; // Relative URL @@ -13,7 +33,7 @@ document.getElementById('inputForm').addEventListener('submit', function(event) headers: { 'Content-Type': 'application/json', }, - body: JSON.stringify({ text: inputData, "backendType": backendType }), // Send the input text as JSON + body: JSON.stringify({ text: inputData, "backendType": backendType, llmURL: inputLLMurl, llmModel: inputLLMmodel}), // Send the input text as JSON }) .then(response => { if (!response.ok) { diff --git a/src/static/styles/style.css b/src/static/styles/style.css index 191bb0b..01f7e58 100644 --- a/src/static/styles/style.css +++ b/src/static/styles/style.css @@ -36,6 +36,14 @@ footer { white-space: pre-wrap; /* Preserve whitespace */ } +#LLMInput { + display: none; /* Hide by default */ +} + +#LLMcustomLabel { + display: none; /* Hide by default */ +} + .flex-container { display: flex; /* Use flexbox to align items */ justify-content: center; /* Center the buttons horizontally */ @@ -95,3 +103,7 @@ footer { flex-direction: column; /* Stack items vertically */ } } + +.checkbox-label { + font-size: 14px; /* Font size */ +} \ No newline at end of file diff --git a/src/templates/html/mask.html b/src/templates/html/mask.html index 274c317..651fea7 100644 --- a/src/templates/html/mask.html +++ b/src/templates/html/mask.html @@ -28,7 +28,7 @@