Skip to content

Commit

Permalink
Merge branch 'master' of github.com:AI4Bharat/ai4b-website
Browse files Browse the repository at this point in the history
  • Loading branch information
Shanks0465 committed Dec 1, 2024
2 parents 366b939 + febc7e4 commit 542cee4
Show file tree
Hide file tree
Showing 52 changed files with 3,446 additions and 873 deletions.
4 changes: 3 additions & 1 deletion backend/.gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -31,4 +31,6 @@ Caddyfile

/static/

data_dump.json
data_dump.json
db_bkp.json
website_db.json
20 changes: 19 additions & 1 deletion backend/areas/admin.py
Original file line number Diff line number Diff line change
@@ -1,13 +1,26 @@
from django.contrib import admin

# Register your models here.
from .models import Dataset, Tool, Model,News
from .models import Dataset, Tool, Model,News,ModelFeedback,Publication

from import_export import resources

from import_export.admin import ImportExportModelAdmin

class FeedbackResource(resources.ModelResource):

class Meta:
model = ModelFeedback


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

class ModelFeedbackAdmin(ImportExportModelAdmin):
resource_classes = [FeedbackResource]
list_filter = ["task", "serviceId","postedOn","liked","sourceLanguage","targetLanguage","domain"]
search_fields = ["serviceId"]

class DatasetAdmin(admin.ModelAdmin):
list_filter = ["area", "conference"]
search_fields = ["title"]
Expand All @@ -21,8 +34,13 @@ class ModelAdmin(admin.ModelAdmin):
class ToolAdmin(admin.ModelAdmin):
search_fields = ["title"]

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


admin.site.register(Dataset, DatasetAdmin)
admin.site.register(Tool, ToolAdmin)
admin.site.register(Model, ModelAdmin)
admin.site.register(News,NewsAdmin)
admin.site.register(ModelFeedback,ModelFeedbackAdmin)
admin.site.register(Publication,PublicationAdmin)
70 changes: 66 additions & 4 deletions backend/areas/models.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,11 @@
from django.db import models
from datetime import date
from django.dispatch import receiver
import os
import github
from dotenv import load_dotenv

load_dotenv(dotenv_path="/home/ai4bharat/ai4b-website/backend/.env")


class Area(models.TextChoices):
Expand All @@ -22,27 +27,61 @@ 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}"


class ModelFeedback(models.Model):
id = models.AutoField(primary_key=True)
serviceId = models.CharField(max_length=500)
task = models.CharField(max_length=500)
postedOn = models.DateField(default=date.today)
modelInput = models.TextField()
modelResponse = models.TextField()
liked = models.BooleanField(default=False)
comment = models.TextField()
sourceLanguage = models.CharField(max_length=100,null=True,blank=True)
targetLanguage = models.CharField(max_length=100,null=True,blank=True)
domain = models.CharField(max_length=100,null=True,blank=True)

def __str__(self) -> str:
return f"{self.id}_{self.serviceId}"



class Model(models.Model):
id = models.AutoField(primary_key=True)
title = models.CharField(max_length=500)
area = models.CharField(choices=Area.choices, max_length=10)
published_on = models.DateField(default=date.today)
latest = models.BooleanField(default=False)
conference = models.CharField(max_length=20, null=True, blank=True)
description = models.TextField()
paper_link = models.URLField(max_length=500)
paper_link = models.URLField(max_length=500,null=True,blank=True)
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)
colab_link = models.URLField(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)
testimonials_json = models.JSONField(null=True,blank=True)

def __str__(self) -> str:
return f"{self.title}"

@receiver(models.signals.post_save, sender=Model)
def execute_after_model_save(sender, instance, created, *args, **kwargs):
g = github.Github(login_or_token=os.getenv("GITHUB_WORKFLOW_TOKEN"))
repo = g.get_repo("AI4Bharat/ai4b-website")
workflow_name = "nextjs.yml"
workflow = repo.get_workflow(workflow_name)
ref = repo.get_branch("master")
workflow.create_dispatch(ref=ref)
print("New Model Deploy Triggered")



class Tool(models.Model):
Expand All @@ -54,11 +93,24 @@ class Tool(models.Model):
release_timeline_json = models.JSONField()
feature_cards_json = models.JSONField()
contributor_cards_json = models.JSONField()
installation_steps_json = models.JSONField()
installation_steps_json = models.JSONField(null=True,blank=True)

def __str__(self) -> str:
return f"{self.title}"

@receiver(models.signals.post_save, sender=Tool)
def execute_after_tool_save(sender, instance, created, *args, **kwargs):
if created:
g = github.Github(login_or_token=os.getenv("GITHUB_WORKFLOW_TOKEN"))
repo = g.get_repo("AI4Bharat/ai4b-website")
workflow_name = "nextjs.yml"
workflow = repo.get_workflow(workflow_name)
ref = repo.get_branch("master")
workflow.create_dispatch(ref=ref)
print("New Tool Deploy Triggered")
else:
print("Tool Updated")


def image_directory_path(instance, filename):

Expand All @@ -74,6 +126,16 @@ class News(models.Model):
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)
markdown_content = models.TextField(null=True,blank=True)

def __str__(self) -> str:
return f"{self.title}"

class Publication(models.Model):
id = models.AutoField(primary_key=True)
title = models.CharField(max_length=200)
dataset = models.ManyToManyField(Dataset,null=True,blank=True)
model = models.ManyToManyField(Model,null=True,blank=True,)

def __str__(self) -> str:
return f"{self.title}"
33 changes: 29 additions & 4 deletions backend/areas/serializers.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
from rest_framework.serializers import ModelSerializer
from .models import Dataset, Tool, Model,News
from .models import Dataset, Tool, Model,News,ModelFeedback,Publication


class DatasetSerializer(ModelSerializer):
Expand All @@ -15,9 +15,13 @@ class Meta:
"paper_link",
"website_link",
"github_link",
"hf_id",
"hf_link",
]

class ModelFeedbackSerializer(ModelSerializer):
class Meta:
model = ModelFeedback
fields = ['id','serviceId','task','modelInput','modelResponse','comment','liked','postedOn','sourceLanguage','targetLanguage','domain']

class ModelSerializer(ModelSerializer):
class Meta:
Expand All @@ -30,10 +34,15 @@ class Meta:
"conference",
"description",
"paper_link",
"colab_link",
"website_link",
"github_link",
"service_id",
"hf_id",
"hf_link",
"installation_steps_json",
"usage_steps_json",
"testimonials_json",
"latest"
]


Expand All @@ -60,5 +69,21 @@ class Meta:
"title",
"description",
"published_on",
"image"
"image",
"related_link",
"markdown_content"
]

class PublicationSerializer(ModelSerializer):
model = ModelSerializer(many=True)
dataset = DatasetSerializer(many=True)
class Meta:
model = Publication
fields = [
"id",
"title",
"model",
"dataset",
]


12 changes: 10 additions & 2 deletions backend/areas/urls.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,16 @@
from areas import views
from django.conf.urls.static import static
from django.conf import settings
from .views import PublicationViewSet, PublicationFilterOptions, AreaViewSet,InferenceView
from .views import PublicationViewSet, PublicationFilterOptions, AreaViewSet,translate,transcribe,convertToAudio




router = DefaultRouter()
router.register(r"datasets", views.DatasetViewSet)
router.register(r"news",views.NewsViewSet)
router.register(r"feedback",views.ModelFeedbackViewSet)
router.register(r"pubs",views.PubViewSet)
# Do not register the ToolViewSet with the router, as we need custom routes

# The API URLs are now determined automatically by the router.
Expand Down Expand Up @@ -41,7 +46,10 @@
AreaViewSet.as_view({"get":"list"}),
name="area-list"
),
path("inference/",InferenceView.as_view(),name="inference"),
path("inference/translate",translate,name="translate"),
path("inference/transcribe",transcribe,name="asr"),
path("inference/convert",convertToAudio,name="tts")
# path("inference/",InferenceView.as_view(),name="inference"),
]
# Add static file serving if needed
if settings.DEBUG:
Expand Down
Loading

0 comments on commit 542cee4

Please sign in to comment.