Skip to content

Commit

Permalink
created a proxy endpoint for xlit api
Browse files Browse the repository at this point in the history
  • Loading branch information
kartikvirendrar committed Oct 9, 2024
1 parent d510c26 commit 4256239
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 0 deletions.
6 changes: 6 additions & 0 deletions backend/tasks/urls.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
AnnotationViewSet,
PredictionViewSet,
get_celery_tasks,
TransliterationAPIView,
)

router = routers.DefaultRouter()
Expand All @@ -15,4 +16,9 @@

urlpatterns = [
path("get_celery_tasks/", get_celery_tasks),
path(
"xlit-api/generic/transliteration/<str:target_language>/<str:data>",
TransliterationAPIView.as_view(),
name="transliteration-api",
),
] + router.urls
14 changes: 14 additions & 0 deletions backend/tasks/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,7 @@
import sacrebleu

from utils.date_time_conversions import utc_to_ist
from rest_framework.views import APIView

# Create your views here.

Expand Down Expand Up @@ -2642,3 +2643,16 @@ def get_celery_tasks(request):
page_size = int(request.GET.get("page_size", 10))
data = paginate_queryset(filtered_tasks, page_number, page_size)
return JsonResponse(data["results"], safe=False)


class TransliterationAPIView(APIView):
permission_classes = [IsAuthenticated]

def get(self, request, target_language, data, *args, **kwargs):
response_transliteration = requests.get(
os.getenv("TRANSLITERATION_URL") + target_language + "/" + data,
headers={"Authorization": "Bearer " + os.getenv("TRANSLITERATION_KEY")},
)

transliteration_output = response_transliteration.json()
return Response(transliteration_output, status=status.HTTP_200_OK)

0 comments on commit 4256239

Please sign in to comment.