diff --git a/backend/areas/urls.py b/backend/areas/urls.py index e545111..a8b285c 100644 --- a/backend/areas/urls.py +++ b/backend/areas/urls.py @@ -3,7 +3,7 @@ from areas import views from django.conf.urls.static import static from django.conf import settings -from .views import PublicationViewSet, PublicationFilterOptions, AreaViewSet,NewsViewSet +from .views import PublicationViewSet, PublicationFilterOptions, AreaViewSet,InferenceView router = DefaultRouter() router.register(r"datasets", views.DatasetViewSet) @@ -40,7 +40,8 @@ "area//", AreaViewSet.as_view({"get":"list"}), name="area-list" - ) + ), + path("inference/",InferenceView.as_view(),name="inference"), ] # Add static file serving if needed if settings.DEBUG: diff --git a/backend/areas/views.py b/backend/areas/views.py index b6fcf71..6af3be0 100644 --- a/backend/areas/views.py +++ b/backend/areas/views.py @@ -5,15 +5,48 @@ # Create your views here. from .models import Dataset, Tool, Model,News -from rest_framework import viewsets +from rest_framework import viewsets,status from .serializers import DatasetSerializer, ToolSerializer, ModelSerializer,NewsSerializer from rest_framework.decorators import permission_classes from rest_framework import permissions +from rest_framework.views import APIView + DHRUVA_MODEL_VIEW_URL = "https://api.dhruva.ekstep.ai/services/details/view_service" DHRUVA_API_KEY = "0aaef7ff-86f3-4bb0-a30b-9f50f3de1a52" -from datetime import datetime +@permission_classes((permissions.AllowAny,)) +class InferenceView(APIView): + def post(self, request, format=None): + body = request.data + task = body["task"] + if task=="translation": + INFERENCE_API = "https://api.dhruva.ekstep.ai/services/inference/translation" + inferenceResult = requests.post(INFERENCE_API,headers= + {'x-auth-source': 'API_KEY', + 'Authorization': DHRUVA_API_KEY}, + json={ + "controlConfig": { + "dataTracking": True + }, + "config": { + "serviceId": body["serviceId"], + "language": { + "sourceLanguage": body["sourceLanguage"], + "sourceScriptCode": "", + "targetLanguage": body["targetLanguage"], + "targetScriptCode": "" + } + }, + "input": [ + { + "source": body["input"] + } + ] + }) + + return Response(inferenceResult.json(),status=status.HTTP_200_OK) + class NewsViewSet(viewsets.ModelViewSet): queryset = News.objects.all() @@ -25,8 +58,6 @@ class DatasetViewSet(viewsets.ModelViewSet): serializer_class = DatasetSerializer - - class ModelViewSet(viewsets.ModelViewSet): queryset = Model.objects.all() serializer_class = ModelSerializer @@ -44,7 +75,7 @@ def retrieve(self, request, *args, **kwargs): dhruvaModelData = requests.post(DHRUVA_MODEL_VIEW_URL, headers= {'x-auth-source': 'API_KEY', - 'Authorization': '0aaef7ff-86f3-4bb0-a30b-9f50f3de1a52'}, + 'Authorization': DHRUVA_API_KEY}, json={'serviceId':modelData["service_id"]}).json()["model"] languages = dhruvaModelData["languages"] @@ -161,3 +192,5 @@ def list(self, request, *args, **kwargs): publications.sort(key=lambda pub: pub.get("published_on")) return Response(publications) + + diff --git a/backend/backend/settings.py b/backend/backend/settings.py index f3799f7..0d8c399 100644 --- a/backend/backend/settings.py +++ b/backend/backend/settings.py @@ -161,7 +161,7 @@ "accept", "origin", "authorization", - "ngrok-skip-browser-warning", ) -CSRF_TRUSTED_ORIGINS = ["https://e5e4-91-203-135-89.ngrok-free.app"] \ No newline at end of file + +DEBUG_PROPAGATE_EXCEPTIONS = True \ No newline at end of file