update: look at todo

main
Thamognya Kodi 2022-12-28 23:37:10 +07:00
parent f3f672dfc2
commit 01b701625c
10 changed files with 70 additions and 2664 deletions

View File

@ -1,4 +1,8 @@
.env
*.env
*.pkl
.env-fish
*.env*
# Created by https://www.gitignore.io/api/osx,python,pycharm,windows,visualstudio,visualstudiocode # Created by https://www.gitignore.io/api/osx,python,pycharm,windows,visualstudio,visualstudiocode
# Edit at https://www.gitignore.io/?templates=osx,python,pycharm,windows,visualstudio,visualstudiocode # Edit at https://www.gitignore.io/?templates=osx,python,pycharm,windows,visualstudio,visualstudiocode

3
.github/TODO.md vendored
View File

@ -1 +1,2 @@
- IMP IMP work on API_KEY fixing config or use .env - Get package to use .env from django
- [x] IMP IMP work on API_KEY fixing config or use .env

2
.gitignore vendored
View File

@ -1,6 +1,8 @@
.env .env
*.env *.env
*.pkl *.pkl
.env-fish
*.env*
# Created by https://www.gitignore.io/api/osx,python,pycharm,windows,visualstudio,visualstudiocode # Created by https://www.gitignore.io/api/osx,python,pycharm,windows,visualstudio,visualstudiocode
# Edit at https://www.gitignore.io/?templates=osx,python,pycharm,windows,visualstudio,visualstudiocode # Edit at https://www.gitignore.io/?templates=osx,python,pycharm,windows,visualstudio,visualstudiocode

View File

@ -0,0 +1,3 @@
env/
.env
.env-fish

View File

@ -0,0 +1,9 @@
{% extends "rest_framework/base.html" %} {% block bootstrap_theme %}
<link
rel="stylesheet"
href="https://bootswatch.com/5/flatly/bootstrap.css"
type="text/css"
/>
{% endblock %} {% block bootstrap_navbar_variant %}{% endblock %} {% block branding %}
<h2><a href="">Internet-ML's NLP Question Answering</a></h2>
{% endblock %}

View File

@ -1,7 +1,48 @@
import json
from django.views.generic.base import TemplateView from django.views.generic.base import TemplateView
from dotenv import load_dotenv
from rest_framework import status
from rest_framework.response import Response
from rest_framework.views import APIView
# Create your views here. from internet_ml.NLP.no_context import QA
load_dotenv()
class QAView(TemplateView): class QAView(APIView):
template_name = "index.question_answer.dj.html" def post(self, request, format=None):
"""
{"question": "Who is Elon Musk?"}
{
"error": "",
"response": {
'score': VAL,
'start': VAL,
'end': VAL,
'answer': 'THE_ANSWER'
},
"resources": [
'SOME_LINKS_HERE'
]
}
or
{
"error": "",
"status": "",
"detail": "",
}
so check error if it exists first and then for other stuff
"""
try:
answer = QA.answer(request.POST.get("question"))
content = json.dumps(
{"error": "", "response": answer[0], "resources": answer[1]}
)
return Response(content, status=status.HTTP_200_OK)
except:
content = json.dumps(
{"error": "Google API key not present in .env or environment"}
)
return Response(content, status=status.HTTP_500_INTERNAL_SERVER_ERROR)

View File

@ -40,10 +40,13 @@ INSTALLED_APPS: list[str] = [
"django.contrib.messages", "django.contrib.messages",
"django.contrib.staticfiles", "django.contrib.staticfiles",
"rest_framework", "rest_framework",
"internet_ml",
"api", "api",
"api.question_answer", "api.question_answer",
] ]
REST_FRAMEWORK = {"DEFAULT_METADATA_CLASS": "rest_framework.metadata.SimpleMetadata"}
MIDDLEWARE: list[str] = [ MIDDLEWARE: list[str] = [
"django.middleware.security.SecurityMiddleware", "django.middleware.security.SecurityMiddleware",
"django.contrib.sessions.middleware.SessionMiddleware", "django.contrib.sessions.middleware.SessionMiddleware",

File diff suppressed because it is too large Load Diff

View File

@ -13,9 +13,9 @@ packages = [{include = "internet_ml_server"}]
[tool.poetry.dependencies] [tool.poetry.dependencies]
python = "^3.10" python = "^3.10"
django = "^4.1.4" django = "^4.1.4"
internet-ml = "^0.2.11"
django-stubs = "^1.13.1" django-stubs = "^1.13.1"
djangorestframework = "^3.14.0" djangorestframework = "^3.14.0"
python-dotenv = "^0.21.0"
[tool.mypy] [tool.mypy]
plugins = ["mypy_django_plugin.main"] plugins = ["mypy_django_plugin.main"]