Update app.py
Browse files
app.py
CHANGED
|
@@ -4,6 +4,35 @@ import langdetect # Voor taalherkenning
|
|
| 4 |
from fuzzywuzzy import process # Voor fuzzy matching
|
| 5 |
import re # Voor regex matching
|
| 6 |
import warnings
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 7 |
|
| 8 |
# Verwijder de warning voor de Levenshtein matcher
|
| 9 |
warnings.filterwarnings("ignore", message="Using slow pure-python SequenceMatcher.")
|
|
|
|
| 4 |
from fuzzywuzzy import process # Voor fuzzy matching
|
| 5 |
import re # Voor regex matching
|
| 6 |
import warnings
|
| 7 |
+
from fastapi import FastAPI, Request, HTTPException
|
| 8 |
+
from fastapi.security import HTTPBasic, HTTPBasicCredentials
|
| 9 |
+
from starlette.responses import RedirectResponse
|
| 10 |
+
|
| 11 |
+
app = FastAPI()
|
| 12 |
+
|
| 13 |
+
security = HTTPBasic()
|
| 14 |
+
|
| 15 |
+
# Authenticatiefunctie
|
| 16 |
+
def authenticate_user(credentials: HTTPBasicCredentials):
|
| 17 |
+
if credentials.username != "admin" or credentials.password != "admin":
|
| 18 |
+
raise HTTPException(status_code=401, detail="Invalid credentials")
|
| 19 |
+
|
| 20 |
+
@app.get("/protected")
|
| 21 |
+
async def protected_route(request: Request, credentials: HTTPBasicCredentials = security):
|
| 22 |
+
authenticate_user(credentials)
|
| 23 |
+
return {"message": "Je hebt toegang tot het beschermde deel!"}
|
| 24 |
+
|
| 25 |
+
# Gradio UI
|
| 26 |
+
def protected_interface():
|
| 27 |
+
return "Beschermde interface alleen toegankelijk voor geautoriseerde gebruikers."
|
| 28 |
+
|
| 29 |
+
with gr.Blocks() as app_interface:
|
| 30 |
+
gr.Markdown("### Publieke sectie")
|
| 31 |
+
gr.Textbox("Vul iets in...")
|
| 32 |
+
app.add_route("/protected", protected_route) # Beschermde route
|
| 33 |
+
|
| 34 |
+
# Als gebruiker geauthenticeerd is, toon de interface
|
| 35 |
+
gr.Interface(protected_interface, inputs=[], outputs="text").launch()
|
| 36 |
|
| 37 |
# Verwijder de warning voor de Levenshtein matcher
|
| 38 |
warnings.filterwarnings("ignore", message="Using slow pure-python SequenceMatcher.")
|