Skip to content

Commit

Permalink
Merge pull request #82 from AI4Bharat/v1.0
Browse files Browse the repository at this point in the history
Track Default
  • Loading branch information
Shanks0465 authored Sep 17, 2024
2 parents c6632ba + ecff891 commit d8fc4ef
Show file tree
Hide file tree
Showing 4 changed files with 18 additions and 15 deletions.
27 changes: 15 additions & 12 deletions backend/areas/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
import shutil
import httpx


timeout = httpx.Timeout(None, read=None)

# Create your views here.
from .models import Dataset, Tool, Model,News,ModelFeedback,Publication
Expand Down Expand Up @@ -57,7 +57,7 @@ async def translate(request):
}
payload = {
"controlConfig": {
"dataTracking": True
"dataTracking": body["track"]
},
"config": {
"serviceId": body["serviceId"],
Expand All @@ -76,7 +76,7 @@ async def translate(request):
}

async with httpx.AsyncClient() as client:
inference_result = await client.post(url, headers=headers, json=payload)
inference_result = await client.post(url, headers=headers, json=payload,timeout=timeout)

if inference_result.status_code != 200:
return Response({"message": "Inference Failed"}, status=status.HTTP_503_SERVICE_UNAVAILABLE)
Expand Down Expand Up @@ -114,7 +114,7 @@ async def transcribe(request):
headers = {'x-auth-source': 'API_KEY','Authorization': os.getenv('DHRUVA_API_KEY')}
payload = {
"controlConfig": {
"dataTracking": True
"dataTracking": body["track"]
},
"config": {
"audioFormat": "wav",
Expand All @@ -141,7 +141,7 @@ async def transcribe(request):
}

async with httpx.AsyncClient() as client:
inferenceResult = await client.post(os.getenv("DHRUVA_ASR_ENDPOINT"),headers=headers,json=payload)
inferenceResult = await client.post(os.getenv("DHRUVA_ASR_ENDPOINT"),headers=headers,json=payload,timeout=timeout)

os.remove(webmPath)
os.remove(wavPath)
Expand All @@ -165,7 +165,7 @@ async def convertToAudio(request):

json_payload = {
"controlConfig": {
"dataTracking": True
"dataTracking": body["track"]
},
"config": {
"serviceId": body["serviceId"],
Expand All @@ -186,7 +186,7 @@ async def convertToAudio(request):
}

async with httpx.AsyncClient() as client:
inference_result = await client.post(url, headers=headers, json=json_payload)
inference_result = await client.post(url, headers=headers, json=json_payload,timeout=timeout)

if inference_result.status_code != 200:
return Response({"message": "Inference Failed"}, status=status.HTTP_503_SERVICE_UNAVAILABLE)
Expand Down Expand Up @@ -246,7 +246,8 @@ def create(self, request, *args, **kwargs):

modelInput = hashlib.sha256(wav_base64.encode())
modelInput = modelInput.hexdigest()
shutil.copy2(wavPath,f"/home/ai4bharat/ai4b-website/backend/media/audio/{modelInput}.wav")
if body["track"]:
shutil.copy2(wavPath,f"/home/ai4bharat/ai4b-website/backend/media/audio/{modelInput}.wav")
os.remove(webmPath)
os.remove(wavPath)

Expand All @@ -269,7 +270,7 @@ class DatasetViewSet(viewsets.ModelViewSet):
queryset = Dataset.objects.all()
serializer_class = DatasetSerializer

@method_decorator(cache_page(60*15))
# @method_decorator(cache_page(60*15))
def list(self, request, *args, **kwargs):
queryset = self.get_queryset()
serializer = self.get_serializer(queryset, many=True)
Expand All @@ -281,13 +282,14 @@ class ModelViewSet(viewsets.ModelViewSet):
queryset = Model.objects.all()
serializer_class = ModelSerializer

@method_decorator(cache_page(60*15))
# @method_decorator(cache_page(60*15))
def list(self, request, *args, **kwargs):
queryset = self.get_queryset()
serializer = self.get_serializer(queryset, many=True)
models = serializer.data
return Response(models)


@method_decorator(cache_page(60*15))
def retrieve(self, request, *args, **kwargs):


Expand Down Expand Up @@ -394,7 +396,8 @@ def list(self, request, *args, **kwargs):
for item in data
]
return Response(filtered_data)


@method_decorator(cache_page(60*15))
def retrieve(self, request, *args, **kwargs):
title = kwargs.get("title")
try:
Expand Down
2 changes: 1 addition & 1 deletion frontend/components/TryOut/ASR.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -105,7 +105,7 @@ export default function ASR({ services }: { services: any }) {

const [success, setSuccess] = useState(false);
const [isLoading, setIsLoading] = useState(false);
const [tracking, setTracking] = useState(false);
const [tracking, setTracking] = useState(true);

const toast = useToast();

Expand Down
2 changes: 1 addition & 1 deletion frontend/components/TryOut/NMT.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ export default function NMT({ services }: { services: any }) {
const [outputText, setOutputText] = useState("");
const [success, setSuccess] = useState(false);
const [isLoading, setIsLoading] = useState(false);
const [tracking, setTracking] = useState(false);
const [tracking, setTracking] = useState(true);

const toast = useToast();

Expand Down
2 changes: 1 addition & 1 deletion frontend/components/TryOut/TTS.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@ export default function TTS({ services }: { services: any }) {
const [inputText, setInputText] = useState("");
const [output, setOutput] = useState("");
const [isLoading, setIsLoading] = useState(false);
const [tracking, setTracking] = useState(false);
const [tracking, setTracking] = useState(true);

const [success, setSuccess] = useState(false);

Expand Down

0 comments on commit d8fc4ef

Please sign in to comment.