Spaces:
Running
Running
File size: 2,011 Bytes
1286e81 |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 |
from rest_framework.views import APIView
from adrf.views import APIView as AsyncAPIView
import tempfile, os
from rest_framework.response import Response
from _utils.resumo_completo_cursor import (
get_llm_summary_answer_by_cursor_complete,
)
from .serializer import (
ResumoCursorCompeltoSerializer,
)
from rest_framework.parsers import MultiPartParser
from drf_spectacular.utils import extend_schema
class ResumoSimplesCursorCompletoView(AsyncAPIView):
parser_classes = [MultiPartParser]
@extend_schema(
request=ResumoCursorCompeltoSerializer,
)
async def post(self, request):
serializer = ResumoCursorCompeltoSerializer(data=request.data)
if serializer.is_valid(raise_exception=True):
print("\n\n\n")
listaPDFs = []
data = serializer.validated_data
print("\nserializer.validated_data: ", serializer.validated_data)
for file in serializer.validated_data["files"]:
file.seek(0)
with tempfile.NamedTemporaryFile(
delete=False, suffix=".pdf"
) as temp_file: # Create a temporary file to save the uploaded PDF
for (
chunk
) in (
file.chunks()
): # Write the uploaded file content to the temporary file
temp_file.write(chunk)
temp_file_path = (
temp_file.name
) # Get the path of the temporary file
listaPDFs.append(temp_file_path)
print("listaPDFs: ", listaPDFs)
resposta_llm = await get_llm_summary_answer_by_cursor_complete(
data, listaPDFs
)
final = resposta_llm
print("\n\n\n")
print("final: ", final)
for file in listaPDFs:
os.remove(file)
return Response({"resposta": final})
|