mirror of
https://github.com/Ai-hack-MAGNUM-OPUS/backend.git
synced 2024-11-24 09:13:44 +03:00
added paragraph score, inited word api
This commit is contained in:
parent
f06651d1a9
commit
cdf082415c
|
@ -24,8 +24,8 @@ class RetireDocxSerializer(APIView):
|
||||||
def get(self, request, uuid):
|
def get(self, request, uuid):
|
||||||
doc = get_object_or_404(Docx, uuid=uuid)
|
doc = get_object_or_404(Docx, uuid=uuid)
|
||||||
res = {}
|
res = {}
|
||||||
paragraphs = ParagraphType.objects.filter(paragraphs__docx=doc)
|
paragraphs = ParagraphType.objects.all()
|
||||||
for p in paragraphs:
|
for p in paragraphs:
|
||||||
res[p.name] = [x.text for x in p.paragraphs.filter(docx=doc)]
|
res[p.name] = [(x.text, x.score) for x in p.paragraphs.filter(docx=doc)]
|
||||||
return Response(res)
|
return Response(res)
|
||||||
|
|
||||||
|
|
|
@ -1,4 +1,6 @@
|
||||||
import uuid as uuid
|
import uuid as uuid
|
||||||
|
|
||||||
|
from django.core.validators import MinValueValidator, MaxValueValidator
|
||||||
from django.db import models
|
from django.db import models
|
||||||
|
|
||||||
# Create your models here.
|
# Create your models here.
|
||||||
|
@ -30,6 +32,7 @@ class ParagraphType(models.Model):
|
||||||
|
|
||||||
|
|
||||||
class Paragraph(models.Model):
|
class Paragraph(models.Model):
|
||||||
|
score = models.IntegerField(default=0, validators=[MinValueValidator(0), MaxValueValidator(100)])
|
||||||
text = models.TextField()
|
text = models.TextField()
|
||||||
type = models.ForeignKey(
|
type = models.ForeignKey(
|
||||||
ParagraphType, related_name="paragraphs", on_delete=models.CASCADE
|
ParagraphType, related_name="paragraphs", on_delete=models.CASCADE
|
||||||
|
|
|
@ -25,12 +25,18 @@ def process_file(pk: int):
|
||||||
dct = {x: vals[x] for x in range(len(vals))}
|
dct = {x: vals[x] for x in range(len(vals))}
|
||||||
|
|
||||||
x = requests.post("http://109.248.175.223:5000/api", json=dct)
|
x = requests.post("http://109.248.175.223:5000/api", json=dct)
|
||||||
for el_id, type_id in x.json().items():
|
if x.status_code == 200:
|
||||||
Paragraph.objects.create(type_id=type_id, docx=file, text=dct[int(el_id)])
|
for el_id, dat in x.json().items():
|
||||||
|
type_id, score = dat
|
||||||
|
Paragraph.objects.create(
|
||||||
|
type_id=type_id, docx=file, text=dct[int(el_id)], score=score
|
||||||
|
)
|
||||||
|
|
||||||
counter += len(vals)
|
counter += len(vals)
|
||||||
print(f"processing {uuid}, {counter}/{len_c}")
|
print(f"processing {uuid}, {counter}/{len_c}")
|
||||||
file.paragraphs_processed = counter
|
file.paragraphs_processed = counter
|
||||||
file.save(update_fields=["paragraphs_processed"])
|
file.save(update_fields=["paragraphs_processed"])
|
||||||
|
else:
|
||||||
|
print(f"AI server error, {x.status_code}")
|
||||||
|
|
||||||
return f"ok, {pk}"
|
return f"ok, {pk}"
|
||||||
|
|
|
@ -4,7 +4,32 @@ from checker.api.views import ListCreateDocxApiView, RetireDocxSerializer, GetDo
|
||||||
|
|
||||||
urlpatterns = [
|
urlpatterns = [
|
||||||
path("health/", include("health_check.urls")),
|
path("health/", include("health_check.urls")),
|
||||||
path("docx/", ListCreateDocxApiView.as_view(), name="list_create_docx"),
|
path(
|
||||||
path("docx/<uuid:uuid>", RetireDocxSerializer.as_view(), name="get_docx"),
|
"site/",
|
||||||
path("state/<uuid:uuid>", GetDocxState.as_view(), name="get_state_docx"),
|
include(
|
||||||
|
[
|
||||||
|
path("docx/", ListCreateDocxApiView.as_view(), name="list_create_docx"),
|
||||||
|
path(
|
||||||
|
"docx/<uuid:uuid>", RetireDocxSerializer.as_view(), name="get_docx"
|
||||||
|
),
|
||||||
|
path(
|
||||||
|
"state/<uuid:uuid>", GetDocxState.as_view(), name="get_state_docx"
|
||||||
|
),
|
||||||
|
]
|
||||||
|
),
|
||||||
|
),
|
||||||
|
path(
|
||||||
|
"word/",
|
||||||
|
include(
|
||||||
|
[
|
||||||
|
path("docx/", ListCreateDocxApiView.as_view(), name="list_create_word"),
|
||||||
|
path(
|
||||||
|
"docx/<uuid:uuid>", RetireDocxSerializer.as_view(), name="get_word"
|
||||||
|
),
|
||||||
|
path(
|
||||||
|
"state/<uuid:uuid>", GetDocxState.as_view(), name="get_state_word"
|
||||||
|
),
|
||||||
|
]
|
||||||
|
),
|
||||||
|
),
|
||||||
]
|
]
|
||||||
|
|
Loading…
Reference in New Issue
Block a user