Skip to content

Commit

Permalink
Merge pull request #12 from AI4Bharat/react-django
Browse files Browse the repository at this point in the history
Added Base Tryouts and General UI Fixes
  • Loading branch information
Shanks0465 authored Aug 31, 2024
2 parents bf9034f + e4e6666 commit 6795259
Show file tree
Hide file tree
Showing 15 changed files with 816 additions and 213 deletions.
2 changes: 2 additions & 0 deletions backend/areas/admin.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@
# Register your models here.
from .models import Dataset, Tool, Model,News



class NewsAdmin(admin.ModelAdmin):
search_fields=["title"]

Expand Down
12 changes: 7 additions & 5 deletions backend/areas/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,25 +2,26 @@
from datetime import date



class Area(models.TextChoices):
ASR = "ASR"
NMT = "NMT"
TTS = "TTS"
OCR = "OCR"
XLIT = "XLIT"
LLM = "LLM"


# Create your models here.
class Dataset(models.Model):
id = models.AutoField(primary_key=True)
title = models.CharField(max_length=500)
area = models.CharField(choices=Area.choices, max_length=3)
area = models.CharField(choices=Area.choices, max_length=10)
published_on = models.DateField(default=date.today)
conference = models.CharField(max_length=20, null=True, blank=True)
description = models.TextField()
paper_link = models.URLField(max_length=500)
website_link = models.URLField(max_length=500, null=True, blank=True)
github_link = models.URLField(max_length=500)
github_link = models.URLField(max_length=500,null=True,blank=True)
hf_id = models.CharField(max_length=500,null=True,blank=True)

def __str__(self) -> str:
Expand All @@ -30,13 +31,13 @@ def __str__(self) -> str:
class Model(models.Model):
id = models.AutoField(primary_key=True)
title = models.CharField(max_length=500)
area = models.CharField(choices=Area.choices, max_length=3)
area = models.CharField(choices=Area.choices, max_length=10)
published_on = models.DateField(default=date.today)
conference = models.CharField(max_length=20, null=True, blank=True)
description = models.TextField()
paper_link = models.URLField(max_length=500)
website_link = models.URLField(max_length=500, null=True, blank=True)
github_link = models.URLField(max_length=500)
github_link = models.URLField(max_length=500,null=True,blank=True)
hf_id = models.CharField(max_length=500,null=True,blank=True)
service_id = models.CharField(max_length=500, null=True, blank=True)

Expand Down Expand Up @@ -72,6 +73,7 @@ class News(models.Model):
description = models.TextField()
published_on = models.DateField(default=date.today)
image = models.ImageField(upload_to=image_directory_path,null=True,blank=True)
related_link = models.URLField(max_length=500, null=True, blank=True)

def __str__(self) -> str:
return f"{self.title}"
131 changes: 113 additions & 18 deletions backend/areas/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,35 @@ class InferenceView(APIView):
def post(self, request, format=None):
body = request.data
task = body["task"]
if task=="translation":
if task=="transliteration":
INFERENCE_API = "https://api.dhruva.ekstep.ai/services/inference/transliteration"
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": ""
},
"isSentence": True,
"numSuggestions": 0
},
"input": [
{
"source": body["input"]
}
]
})
return Response(inferenceResult.json(),status=status.HTTP_200_OK)

elif task=="translation":
INFERENCE_API = "https://api.dhruva.ekstep.ai/services/inference/translation"
inferenceResult = requests.post(INFERENCE_API,headers=
{'x-auth-source': 'API_KEY',
Expand All @@ -50,6 +78,38 @@ def post(self, request, format=None):
})
return Response(inferenceResult.json(),status=status.HTTP_200_OK)

elif task == "tts":
INFERENCE_API = "https://api.dhruva.ekstep.ai/services/inference/tts"

inferenceResult = requests.post(INFERENCE_API,headers=
{'x-auth-source': 'API_KEY',
'Authorization': DHRUVA_API_KEY},
json={
"controlConfig": {
"dataTracking": True
},
"config": {
"serviceId": body["serviceId"],
"gender": body["gender"],
"samplingRate": body["samplingRate"],
"audioFormat": "wav",
"language": {
"sourceLanguage": body["sourceLanguage"],
"sourceScriptCode": ""
}
},
"input": [
{
"source": body["input"],
"audioDuration": 0
}
]
})

return Response(inferenceResult.json(),status=status.HTTP_200_OK)



elif task == "asr":

INFERENCE_API = "https://api.dhruva.ekstep.ai/services/inference/asr"
Expand Down Expand Up @@ -126,24 +186,58 @@ def retrieve(self, request, *args, **kwargs):
raise NotFound("Model with the given title does not exist.")

serializer = self.get_serializer(model)

modelData = serializer.data
hfData = requests.get(f"https://huggingface.co/api/models/{modelData['hf_id']}")
dhruvaModelData = requests.post(DHRUVA_MODEL_VIEW_URL,
headers=
{'x-auth-source': 'API_KEY',
'Authorization': DHRUVA_API_KEY},
json={'serviceId':modelData["service_id"]}).json()["model"]

languages = dhruvaModelData["languages"]
hfData = {}
if modelData["hf_id"]!=None:
hfData = requests.get(f"https://huggingface.co/api/models/{modelData['hf_id']}")
hfData = hfData.json()

if "service_id" in modelData and modelData["service_id"]!=None:
serviceId = modelData["service_id"]
modelData["services"] = {}
if "," not in serviceId:
dhruvaModelData = requests.post(DHRUVA_MODEL_VIEW_URL,
headers=
{'x-auth-source': 'API_KEY',
'Authorization': DHRUVA_API_KEY},
json={'serviceId':serviceId}).json()["model"]

languages = dhruvaModelData["languages"]

sourceLanguages = list(set([x["sourceLanguage"] for x in languages]))
if "targetLanguage" in languages[0]:
targetLanguages = list(set([x["targetLanguage"] for x in languages]))
else:
targetLanguages = []

modelData["services"][serviceId] = {"service_id":serviceId,"languageFilters":{"sourceLanguages":sourceLanguages,"targetLanguages":targetLanguages}}
else:
serviceIds = modelData["service_id"].split(",")
services = {}
for serviceId in serviceIds:
serviceData = {"service_id":serviceId}

dhruvaModelData = requests.post(DHRUVA_MODEL_VIEW_URL,
headers=
{'x-auth-source': 'API_KEY',
'Authorization': DHRUVA_API_KEY},
json={'serviceId':serviceId}).json()["model"]

languages = dhruvaModelData["languages"]

sourceLanguages = list(set([x["sourceLanguage"] for x in languages]))
if "targetLanguage" in languages[0]:
targetLanguages = list(set([x["targetLanguage"] for x in languages]))
else:
targetLanguages = []

sourceLanguages = list(set([x["sourceLanguage"] for x in languages]))
if "targetLanguage" in languages[0]:
targetLanguages = list(set([x["targetLanguage"] for x in languages]))
else:
targetLanguages = []
serviceData["languageFilters"] = {"sourceLanguages":sourceLanguages,"targetLanguages":targetLanguages}
services[serviceId] = serviceData
modelData["services"] = services

modelData["hfData"] = hfData.json()
modelData["languageFilters"] = {"sourceLanguages":sourceLanguages,"targetLanguages":targetLanguages}
modelData["hfData"] = hfData

return Response(modelData)


Expand Down Expand Up @@ -223,7 +317,7 @@ def list(self, request, *args, **kwargs):
if publication in model_serializer.data:
publication["type"] = "Model"

publications.sort(key=lambda pub: pub.get("published_on"))
publications.sort(key=lambda pub: pub.get("published_on"),reverse=True)

return Response(publications)

Expand All @@ -248,7 +342,8 @@ def list(self, request, *args, **kwargs):
if publication in model_serializer.data:
publication["type"] = "Model"

publications.sort(key=lambda pub: pub.get("published_on"))
publications.sort(key=lambda pub: pub.get("published_on"),reverse=True)


return Response(publications)

Expand Down
28 changes: 22 additions & 6 deletions frontend/components/AreaTimeline.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,12 @@ const AreaTimeline = ({ data }: { data: Array<Publication> }) => {
const isDesktop = useBreakpointValue({ base: false, md: true });

return (
<Container maxWidth="7xl" p={{ base: 1, sm: 5 }}>
<Container
height={isMobile ? 500 : "auto"}
overflowY={"scroll"}
maxWidth="7xl"
p={{ base: 1, sm: 5 }}
>
<chakra.h3 fontSize="4xl" fontWeight="bold" mb={18} textAlign="center">
Timeline
</chakra.h3>
Expand Down Expand Up @@ -186,16 +191,27 @@ const Card = ({
</chakra.h1>
<ExpandableText noOfLines={2} text={description} />
<HStack>
<Link target="_blank" href={github_link}>
<FaGithub size={25} />
</Link>
{github_link ? (
<Link target="_blank" href={github_link}>
<FaGithub size={25} />
</Link>
) : (
<></>
)}
<Link target="_blank" href={paper_link}>
<FaPaperclip size={25} />
</Link>
{hf_id === null ? (
<></>
) : (
<Link target="_blank" href={`https://huggingface.co/${hf_id}`}>
<Link
target="_blank"
href={
type === "Model"
? `https://huggingface.co/${hf_id}`
: `https://huggingface.co/datasets/${hf_id}`
}
>
<img
src="https://huggingface.co/front/assets/huggingface_logo-noborder.svg"
alt="Hugging Face"
Expand All @@ -214,7 +230,7 @@ const Card = ({
color={"a4borange"}
fontSize={15}
>
Try it Out!
Learn More
</Button>
) : (
<></>
Expand Down
11 changes: 9 additions & 2 deletions frontend/components/Datasets.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ import {
SkeletonText,
Link,
Image as ChakraImage,
useBreakpointValue,
} from "@chakra-ui/react";
import Image from "next/image";
import axios from "axios";
Expand Down Expand Up @@ -87,6 +88,7 @@ const fetchDatasets = async () => {
};

export default function Datasets() {
const isMobile = useBreakpointValue({ base: true, md: false });
const [datasets, setDatasets] = useState([]);
const { isLoading, error, data } = useQuery("fetchDatasets", fetchDatasets);

Expand Down Expand Up @@ -170,7 +172,7 @@ export default function Datasets() {
</Stack>
{isLoading ? (
<SimpleGrid columns={{ base: 1, md: 3 }} spacing={10}>
{Array.from({ length: 1 }, (_, index) => (
{Array.from({ length: 13 }, (_, index) => (
<Card
key={index}
border={"solid"}
Expand All @@ -186,7 +188,12 @@ export default function Datasets() {
))}
</SimpleGrid>
) : (
<SimpleGrid columns={{ base: 1, md: 3 }} spacing={10}>
<SimpleGrid
height={isMobile ? 500 : "auto"}
columns={{ base: 1, md: 3 }}
spacing={10}
overflowY={"scroll"}
>
{datasets.map((dataset: Dataset) => (
<Card key={dataset.title} border={"solid"} borderColor={"orange"}>
<CardBody>
Expand Down
Loading

0 comments on commit 6795259

Please sign in to comment.