Skip to content

Commit

Permalink
Merge pull request #46 from AI4Bharat/v1.0
Browse files Browse the repository at this point in the history
HF Link Support
  • Loading branch information
Shanks0465 authored Sep 9, 2024
2 parents 4afa87f + 0375979 commit 29e2637
Show file tree
Hide file tree
Showing 8 changed files with 66 additions and 56 deletions.
4 changes: 2 additions & 2 deletions backend/areas/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ class Dataset(models.Model):
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,null=True,blank=True)
hf_id = models.CharField(max_length=500,null=True,blank=True)
hf_link = models.URLField(max_length=500,null=True,blank=True)

def __str__(self) -> str:
return f"{self.title}"
Expand All @@ -45,7 +45,7 @@ class Model(models.Model):
website_link = models.URLField(max_length=500, null=True, blank=True)
github_link = models.URLField(max_length=500,null=True,blank=True)
colab_link = models.URLField(max_length=500,null=True,blank=True)
hf_id = models.CharField(max_length=500,null=True,blank=True)
hf_link = models.URLField(max_length=500,null=True,blank=True)
service_id = models.CharField(max_length=500, null=True, blank=True)
installation_steps_json = models.JSONField(null=True,blank=True)
usage_steps_json = models.JSONField(null=True,blank=True)
Expand Down
4 changes: 2 additions & 2 deletions backend/areas/serializers.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ class Meta:
"paper_link",
"website_link",
"github_link",
"hf_id",
"hf_link",
]


Expand All @@ -34,7 +34,7 @@ class Meta:
"website_link",
"github_link",
"service_id",
"hf_id",
"hf_link",
"installation_steps_json",
"usage_steps_json",
"testimonials_json",
Expand Down
31 changes: 25 additions & 6 deletions backend/areas/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,9 +12,8 @@
from .serializers import DatasetSerializer, ToolSerializer, ModelSerializer,NewsSerializer
from rest_framework.decorators import permission_classes
from rest_framework import permissions

from django.utils.decorators import method_decorator
from django_ratelimit.decorators import ratelimit
from django.utils.decorators import method_decorator
from django.views.decorators.cache import cache_page
from rest_framework.decorators import api_view

Expand Down Expand Up @@ -174,17 +173,24 @@ class DatasetViewSet(viewsets.ModelViewSet):
queryset = Dataset.objects.all()
serializer_class = DatasetSerializer

@method_decorator(cache_page(60*15))
def list(self, request, *args, **kwargs):
queryset = self.get_queryset()
serializer = self.get_serializer(queryset, many=True)
datasets = serializer.data
datasets.sort(key=lambda dataset: dataset.get("area"))
return Response(datasets)


class ModelViewSet(viewsets.ModelViewSet):
queryset = Model.objects.all()
serializer_class = ModelSerializer

@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)

def retrieve(self, request, *args, **kwargs):

Expand All @@ -203,9 +209,20 @@ def retrieve(self, request, *args, **kwargs):
modelData["type"] = "Model"

hfData = None
if modelData["hf_id"]!=None:
hfData = requests.get(f"https://huggingface.co/api/models/{modelData['hf_id']}")
hfData = hfData.json()
if modelData["hf_link"]!=None:
hf_link = modelData["hf_link"]
if "collections" in hf_link:
hf_link = hf_link.replace("https://huggingface.co/collections/","https://huggingface.co/api/collections/")
response = requests.get(hf_link)
items = response.json()["items"]
downloads = sum([item["downloads"] for item in items])
hfData = {'downloads':downloads}


else:
hf_link = hf_link.replace("https://huggingface.co/","https://huggingface.co/api/models/")
hfData = requests.get(hf_link)
hfData = hfData.json()

modelData["hfData"] = hfData
modelData["services"] = {}
Expand Down Expand Up @@ -324,6 +341,7 @@ def list(self, request, *args, **kwargs):

@permission_classes((permissions.AllowAny,))
class PublicationViewSet(viewsets.ViewSet):
@method_decorator(cache_page(60*15))
def list(self, request, *args, **kwargs):
datasets = Dataset.objects.all()
models = Model.objects.all()
Expand All @@ -348,6 +366,7 @@ def list(self, request, *args, **kwargs):

@permission_classes((permissions.AllowAny,))
class AreaViewSet(viewsets.ViewSet):

def list(self, request, *args, **kwargs):
area = kwargs.get("area")
datasets = Dataset.objects.filter(area=area)
Expand Down
13 changes: 11 additions & 2 deletions backend/people/views.py
Original file line number Diff line number Diff line change
@@ -1,10 +1,14 @@
from django.shortcuts import render
from rest_framework.response import Response

from .models import Member
from rest_framework import viewsets
from .serializers import MemberSerializer
from django_filters.rest_framework import DjangoFilterBackend

from django.utils.decorators import method_decorator
from django.views.decorators.cache import cache_page


class MemberViewSet(viewsets.ModelViewSet):
"""
Expand All @@ -13,5 +17,10 @@ class MemberViewSet(viewsets.ModelViewSet):

queryset = Member.objects.all()
serializer_class = MemberSerializer
filter_backends = [DjangoFilterBackend]
filterset_fields = ["language", "team"]

@method_decorator(cache_page(60*15))
def list(self, request, *args, **kwargs):
queryset = self.get_queryset()
serializer = self.get_serializer(queryset, many=True)
members = serializer.data
return Response(members)
21 changes: 7 additions & 14 deletions frontend/components/AreaTimeline.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ interface Publication {
area: string;
conference: string;
published_on: string;
hf_id: string;
hf_link: string;
paper_link: string;
github_link: string;
colab_link: string;
Expand Down Expand Up @@ -105,7 +105,7 @@ interface CardProps {
area: string;
published_on: string;
conference: string;
hf_id: string;
hf_link: string;
paper_link: string;
github_link: string;
website_link: string;
Expand Down Expand Up @@ -153,7 +153,7 @@ const Card = ({
area,
published_on,
conference,
hf_id,
hf_link,
paper_link,
github_link,
website_link,
Expand Down Expand Up @@ -252,23 +252,16 @@ const Card = ({
) : (
<></>
)}
{hf_id === null ? (
<></>
) : (
<Link
target="_blank"
href={
type === "Model"
? `https://huggingface.co/${hf_id}`
: `https://huggingface.co/datasets/${hf_id}`
}
>
{hf_link ? (
<Link target="_blank" href={hf_link}>
<img
src="https://huggingface.co/front/assets/huggingface_logo-noborder.svg"
alt="Hugging Face"
style={{ width: "25px", height: "25px" }}
/>
</Link>
) : (
<></>
)}
</HStack>
</VStack>
Expand Down
19 changes: 6 additions & 13 deletions frontend/components/Models.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ interface Model {
installation_steps_json: Array<any>;
usage_steps_json: Array<any>;
type: string;
hf_id: string;
hf_link: string;
}

const renderTryOut = ({ area, services }: { area: string; services: any }) => {
Expand Down Expand Up @@ -88,7 +88,7 @@ export default function ModelView({
installation_steps_json: Array<any>;
usage_steps_json: Array<any>;
type: string;
hf_id: string;
hf_link: string;
}>({
title: "",
description: "",
Expand All @@ -104,7 +104,7 @@ export default function ModelView({
installation_steps_json: [],
usage_steps_json: [],
type: "",
hf_id: "",
hf_link: "",
});

const {
Expand All @@ -130,7 +130,7 @@ export default function ModelView({
installation_steps_json: [],
usage_steps_json: [],
type: "",
hf_id: "",
hf_link: "",
});
} else {
setModel(modelData);
Expand Down Expand Up @@ -252,15 +252,8 @@ export default function ModelView({
) : (
<></>
)}
{model.hf_id ? (
<Link
target="_blank"
href={
model.type === "Model"
? `https://huggingface.co/${model.hf_id}`
: `https://huggingface.co/datasets/${model.hf_id}`
}
>
{model.hf_link ? (
<Link target="_blank" href={model.hf_link}>
<HStack
borderRadius={50}
p={1}
Expand Down
5 changes: 4 additions & 1 deletion frontend/components/TryOut/NMT.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ import {
VStack,
} from "@chakra-ui/react";
import axios from "axios";
import { useEffect, useState } from "react";
import { useState } from "react";
import Feedback from "../Feedback";

const fetchTranslation = async ({
Expand Down Expand Up @@ -58,6 +58,7 @@ export default function NMT({ services }: { services: any }) {
const [transliteration, setTransliteration] = useState(true);
const [inputText, setInputText] = useState("");
const [outputText, setOutputText] = useState("");
const [success, setSuccess] = useState(false);

const toast = useToast();

Expand Down Expand Up @@ -153,6 +154,7 @@ export default function NMT({ services }: { services: any }) {
<Button
onClick={async () => {
setOutputText("");
setSuccess(false);
if (inputText === "") {
toast({
title: "Input Error",
Expand All @@ -179,6 +181,7 @@ export default function NMT({ services }: { services: any }) {
duration: 4000,
isClosable: true,
});
setSuccess(true);
} else if (response.status === 403) {
setOutputText("");
toast({
Expand Down
25 changes: 9 additions & 16 deletions frontend/src/app/publications/page.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -126,7 +126,7 @@ interface Publication {
conference: string;
published_on: string;
colab_link: string;
hf_id: string;
hf_link: string;
paper_link: string;
github_link: string;
type: string;
Expand Down Expand Up @@ -284,7 +284,7 @@ interface Publication {
// categories={[pub.area, pub.conference]}
// description={pub.description}
// date={new Date(pub.published_on)}
// hf_id={pub.hf_id}
// hf_link={pub.hf_link}
// paper_link={pub.paper_link}
// github_link={pub.github_link}
// colab_link={pub.colab_link}
Expand Down Expand Up @@ -481,7 +481,7 @@ const Publications = () => {
categories={[pub.area, pub.conference]}
description={pub.description}
date={new Date(pub.published_on)}
hf_id={pub.hf_id}
hf_link={pub.hf_link}
paper_link={pub.paper_link}
github_link={pub.github_link}
colab_link={pub.colab_link}
Expand All @@ -502,7 +502,7 @@ interface CardProps {
categories: string[];
description: string;
date: Date;
hf_id: string;
hf_link: string;
paper_link: string;
github_link: string;
colab_link: string;
Expand All @@ -514,7 +514,7 @@ const Card = ({
categories,
description,
date,
hf_id,
hf_link,
paper_link,
github_link,
colab_link,
Expand Down Expand Up @@ -585,23 +585,16 @@ const Card = ({
) : (
<></>
)}
{hf_id === null ? (
<></>
) : (
<Link
target="_blank"
href={
type === "Model"
? `https://huggingface.co/${hf_id}`
: `https://huggingface.co/datasets/${hf_id}`
}
>
{hf_link ? (
<Link href={hf_link} target="_blank">
<img
src="https://huggingface.co/front/assets/huggingface_logo-noborder.svg"
alt="Hugging Face"
style={{ width: "50px", height: "50px" }}
/>
</Link>
) : (
<></>
)}
</HStack>
</VStack>
Expand Down

0 comments on commit 29e2637

Please sign in to comment.