Skip to content

Commit

Permalink
swtich to fastapi uvicorn
Browse files Browse the repository at this point in the history
Signed-off-by: Steve Taylor <[email protected]>
  • Loading branch information
sbtaylor15 committed Apr 23, 2024
1 parent b6fb31d commit cbc7a51
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 13 deletions.
2 changes: 1 addition & 1 deletion Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -11,4 +11,4 @@ RUN dnf install -y --releasever 2023.4.20240416 python3.11; \
dnf upgrade -y --releasever 2023.4.20240416; \
dnf clean all

ENTRYPOINT ["python3.11", "main.py"]
ENTRYPOINT ["uvicorn", "main:app", "--host", "0.0.0.0", "--port", "8080"]
25 changes: 13 additions & 12 deletions main.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,17 +15,17 @@
# pylint: disable=E0401,E0611
# pyright: reportMissingImports=false,reportMissingModuleSource=false

import argparse
import json
import os
import re
import json
import sys

import joblib
import stanza
import uvicorn
from fastapi import FastAPI, Response
from pydantic import BaseModel # pylint: disable=E0611
from mitreattack.stix20 import MitreAttackData
from pydantic import BaseModel # pylint: disable=E0611
from sklearn.feature_extraction.text import TfidfVectorizer
from sklearn.metrics.pairwise import cosine_similarity

Expand Down Expand Up @@ -70,9 +70,11 @@
debug=True,
)


class CveText(BaseModel):
cvetext: str


def preprocess(text):
text = text.replace("<code>", " ").replace("</code>", " ")
text = text.replace("XSS", "Cross-Site Scripting")
Expand Down Expand Up @@ -173,18 +175,17 @@ def mitremap(data: CveText):

sorted_dict = dict(sorted(sorted_dict.items(), key=lambda item: item[1], reverse=True))
json_str = json.dumps(sorted_dict, indent=4, default=str)
return Response(content=json_str, media_type='application/json')

return Response(content=json_str, media_type="application/json")

if __name__ == "__main__":

parser = argparse.ArgumentParser(description="--loaddata: load the data only and not run the flask endpoint")
parser.add_argument("--loaddata", action="store_true", help="Load data")
args = parser.parse_args()
loaddata = False
if "--loaddata" in sys.argv:
loaddata = True

mitre_data_file = "mitre.joblib"
mitre_data = load_mitre(nlp, mitre_data_file)
mitre_data_file = "mitre.joblib"
mitre_data = load_mitre(nlp, mitre_data_file)

if __name__ == "__main__":
# Check if --loaddata flag is provided
if not args.loaddata:
if not loaddata:
uvicorn.run(app, port=8080)

0 comments on commit cbc7a51

Please sign in to comment.