Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Dev #569

Merged
merged 111 commits into from
Dec 5, 2023
Merged

Dev #569

Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
111 commits
Select commit Hold shift + click to select a range
75c1b45
can add multiple speaker info while update video
vipuldholariya21 Aug 2, 2023
5e1ad19
Merge branch 'dev' of https://github.com/AI4Bharat/Chitralekha-Backen…
vipuldholariya21 Aug 2, 2023
2365450
converted boolean to lower case
vipuldholariya21 Aug 2, 2023
e107931
validation for speaker info object
vipuldholariya21 Aug 2, 2023
7c20aa4
speaker_id updated for transcript
vipuldholariya21 Aug 7, 2023
99200d4
Merge branch 'dev' of https://github.com/AI4Bharat/Chitralekha-Backen…
vipuldholariya21 Aug 7, 2023
a0b8e41
added condition for video update api
vipuldholariya21 Aug 7, 2023
279ca8f
Merge branch 'dev' of https://github.com/AI4Bharat/Chitralekha-Backen…
vipuldholariya21 Aug 7, 2023
0b4a53e
Merge pull request #477 from AI4Bharat/vo_fixes
Shruti1229 Aug 22, 2023
b2be496
Merge pull request #478 from AI4Bharat/vo_fixes
Shruti1229 Aug 23, 2023
f92da08
Merge pull request #479 from AI4Bharat/vo_fixes
Shruti1229 Aug 24, 2023
76dc5ed
Merge pull request #480 from AI4Bharat/vo_fixes
Shruti1229 Aug 24, 2023
d81d3ce
Merge pull request #481 from AI4Bharat/vo_fixes
Shruti1229 Aug 24, 2023
8443bab
Merge pull request #483 from AI4Bharat/vo_fixes
Shruti1229 Aug 25, 2023
49ef0cd
Merge pull request #485 from AI4Bharat/vo_fixes
Shruti1229 Aug 29, 2023
e26a746
Merge pull request #486 from AI4Bharat/vo_fixes
Shruti1229 Aug 29, 2023
72570f6
Merge pull request #487 from AI4Bharat/vo_fixes
Shruti1229 Aug 29, 2023
3efe507
Merge pull request #489 from AI4Bharat/vo_fixes
Shruti1229 Aug 30, 2023
6061a66
Merge pull request #491 from AI4Bharat/vo_fixes
Shruti1229 Sep 3, 2023
74684ac
Merge pull request #493 from AI4Bharat/vo_fixes
Shruti1229 Sep 3, 2023
aa7a228
Merge pull request #495 from AI4Bharat/vo_fixes
Shruti1229 Sep 4, 2023
14eac56
Merge pull request #496 from AI4Bharat/vo_fixes
Shruti1229 Sep 4, 2023
08ae9aa
Merge pull request #498 from AI4Bharat/vo_fixes
Shruti1229 Sep 7, 2023
3101f95
Merge pull request #499 from AI4Bharat/vo_fixes
Shruti1229 Sep 7, 2023
7751c85
Merge pull request #501 from AI4Bharat/vo_fixes
Shruti1229 Sep 8, 2023
bfd780c
Merge pull request #502 from AI4Bharat/vo_fixes
Shruti1229 Sep 12, 2023
8d5da0d
Merge pull request #504 from AI4Bharat/issues_users
Shruti1229 Sep 12, 2023
f493fa7
Merge pull request #505 from AI4Bharat/issues_users
Shruti1229 Sep 12, 2023
c0765fe
Merge pull request #506 from AI4Bharat/issues_users
Shruti1229 Sep 12, 2023
84b2cba
Merge pull request #507 from AI4Bharat/issues_users
Shruti1229 Sep 12, 2023
bf7b170
Merge pull request #509 from AI4Bharat/vo_fixes
Shruti1229 Sep 12, 2023
8471cab
Merge pull request #512 from AI4Bharat/ratio_fail
Shruti1229 Sep 14, 2023
aab5d5f
Merge pull request #514 from AI4Bharat/ratio_fail
Shruti1229 Sep 14, 2023
6780699
Merge pull request #516 from AI4Bharat/ratio_fail
Shruti1229 Sep 14, 2023
c2a3e88
Merge pull request #517 from AI4Bharat/ratio_fail
Shruti1229 Sep 14, 2023
3280bae
Merge pull request #519 from AI4Bharat/vo_fixes
Shruti1229 Sep 15, 2023
7f9d70c
Merge pull request #520 from AI4Bharat/vo_fixes
Shruti1229 Sep 15, 2023
e5f864d
Merge pull request #521 from AI4Bharat/vo_fixes
Shruti1229 Sep 19, 2023
fdc287f
Merge pull request #522 from AI4Bharat/vo_fixes
Shruti1229 Sep 19, 2023
b4915a5
Merge pull request #523 from AI4Bharat/vo_fixes
Shruti1229 Sep 19, 2023
1a52c65
Merge pull request #527 from AI4Bharat/cl_511_task_search_by_task_id
Shruti1229 Sep 21, 2023
54fdefc
Merge pull request #528 from AI4Bharat/cl-513-eta-validation
Shruti1229 Sep 26, 2023
f03e57b
Merge pull request #529 from AI4Bharat/cl-523-inspect-queue-status-ba…
Shruti1229 Sep 26, 2023
9957c02
Merge pull request #530 from AI4Bharat/cl-523-inspect-queue-status-ba…
Shruti1229 Sep 28, 2023
b2b3b18
Merge pull request #534 from AI4Bharat/task_queue
Shruti1229 Sep 29, 2023
6795a27
Merge pull request #535 from AI4Bharat/task_queue
Shruti1229 Oct 2, 2023
0c98dd8
Key work changes in project reports
Shruti1229 Oct 16, 2023
bc054e8
Key word changes in Organization
Shruti1229 Oct 16, 2023
1ec47ea
Newsletter Feature
Shruti1229 Oct 19, 2023
d860f6e
Merge pull request #537 from AI4Bharat/b_check
Shruti1229 Oct 19, 2023
d3adb0b
Merge pull request #539 from AI4Bharat/cl_561_fix_for_tts_task_queue_…
Shruti1229 Oct 19, 2023
53054d4
Merge pull request #541 from AI4Bharat/user_fixes
Shruti1229 Oct 20, 2023
d85ff5c
Newsletter feature
Shruti1229 Oct 20, 2023
9a53dd0
Merge pull request #543 from AI4Bharat/b_check
Shruti1229 Oct 20, 2023
aa84f62
Add nl urls
Shruti1229 Oct 20, 2023
7e6369e
Merge pull request #544 from AI4Bharat/b_check
Shruti1229 Oct 20, 2023
39286dd
added auto remove dependency feature for task reopen
Chetan-Gudagamanal Nov 1, 2023
6a4128f
Merge pull request #545 from AI4Bharat/task_reopen_along_with_auto_re…
Shruti1229 Nov 2, 2023
a6e5fd2
Accet multiple templates
Shruti1229 Nov 3, 2023
0efbfb7
Merge pull request #546 from AI4Bharat/b_check
Shruti1229 Nov 3, 2023
865ea40
Fix templates
Shruti1229 Nov 6, 2023
2eefde7
Merge pull request #549 from AI4Bharat/minor_ticket
Shruti1229 Nov 8, 2023
7e68bd7
Merge pull request #550 from AI4Bharat/minor_ticket
Shruti1229 Nov 8, 2023
d282eb6
Support all formats
Shruti1229 Nov 14, 2023
3a006d2
Support all templates
Shruti1229 Nov 14, 2023
1cd13f0
Merge pull request #552 from AI4Bharat/b_check
Shruti1229 Nov 15, 2023
07ea12e
added auto remove dependency feature for task reopen
Chetan-Gudagamanal Nov 1, 2023
670360a
added condition for voiceover disable and small check for translation…
Chetan-Gudagamanal Nov 7, 2023
5347f81
Merge branch 'dev' into feature_reopen
Shruti1229 Nov 16, 2023
6901f74
Merge pull request #553 from AI4Bharat/feature_reopen
Shruti1229 Nov 16, 2023
4ee476e
Preview in newslette
Shruti1229 Nov 19, 2023
5a76508
Bug fix in subscribing
Shruti1229 Nov 20, 2023
bb0e072
Merge pull request #554 from AI4Bharat/b_check
Shruti1229 Nov 20, 2023
32f667a
Merge pull request #555 from AI4Bharat/empty_vo_issue
Shruti1229 Nov 20, 2023
dbeae64
Handle html content
Shruti1229 Nov 21, 2023
0315965
Return task count in Transcription language report
Shruti1229 Nov 21, 2023
d256810
Send Mails to org owner for signed up users
Shruti1229 Nov 21, 2023
6c8b195
Bug fix in multiple speaker
Shruti1229 Nov 21, 2023
080c77d
Merge pull request #455 from AI4Bharat/add_multiple_speaker_info
Shruti1229 Nov 21, 2023
70466c5
Merge pull request #557 from AI4Bharat/b_check
Shruti1229 Nov 21, 2023
bcf1adb
Merge pull request #558 from AI4Bharat/new_requests
Shruti1229 Nov 21, 2023
02aeab4
Merge pull request #559 from AI4Bharat/empty_vo_issue
Shruti1229 Nov 22, 2023
e3b06a7
added check for empty cards while translation complete
Chetan-Gudagamanal Nov 22, 2023
585e539
update over previous commit
Chetan-Gudagamanal Nov 23, 2023
9e75237
included check for bad sentences
Chetan-Gudagamanal Nov 24, 2023
963a1b1
minor fix
Chetan-Gudagamanal Nov 24, 2023
0b4b8ea
Merge pull request #561 from AI4Bharat/check-empty-cards
Shruti1229 Nov 27, 2023
852d5e4
Merge pull request #563 from AI4Bharat/csv_vo_issue
Shruti1229 Nov 27, 2023
a43c108
Add Transliteration API
Shruti1229 Nov 28, 2023
bdaa424
Merge branch 'dev' into transliteration_api
Shruti1229 Nov 29, 2023
e6f4ca4
Merge pull request #564 from AI4Bharat/transliteration_api
Shruti1229 Nov 29, 2023
39dc984
updated bad sentences function name called for transcription
Chetan-Gudagamanal Nov 29, 2023
aa52d9a
Merge pull request #565 from AI4Bharat/check-empty-cards
Shruti1229 Nov 29, 2023
5980d44
BG Nusic new server
Shruti1229 Nov 30, 2023
071a884
Merge pull request #566 from AI4Bharat/new_bg_music
Shruti1229 Nov 30, 2023
40daf0f
support for VO in bulk task API
Shruti1229 Dec 3, 2023
4cd868a
Fix in API call
Shruti1229 Dec 3, 2023
be2d1b8
Bug fix in task scheduler
Shruti1229 Dec 3, 2023
80619d9
Merge pull request #567 from AI4Bharat/new_bg_music
Shruti1229 Dec 3, 2023
f9855c2
Position image in the right place
Shruti1229 Dec 4, 2023
743b3af
Changes in mails
Shruti1229 Dec 4, 2023
18bd453
Merge pull request #568 from AI4Bharat/new_bg_music
Shruti1229 Dec 4, 2023
762c67b
minor update in reopen response message if dependent voiceover exists
Chetan-Gudagamanal Dec 5, 2023
e6e446d
Merge pull request #570 from AI4Bharat/reopen_response_msg_update
Shruti1229 Dec 5, 2023
719295a
Update Env File
Shruti1229 Dec 5, 2023
72ca2b5
Comment Original Source in Translation
Shruti1229 Dec 5, 2023
35006ee
Merge pull request #571 from AI4Bharat/new_bg_music
Shruti1229 Dec 5, 2023
a76b204
Modify requirements
Shruti1229 Dec 5, 2023
e783d47
Merge pull request #572 from AI4Bharat/new_bg_music
Shruti1229 Dec 5, 2023
282a5d4
Modify Image in Newsletter
Shruti1229 Dec 5, 2023
8ca9e13
Merge pull request #573 from AI4Bharat/new_bg_music
Shruti1229 Dec 5, 2023
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 7 additions & 0 deletions ai-services/background-music-api/config.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
## SECRETS ##
from dotenv import load_dotenv
import os

storage_account_key = ""
connection_string = ""
container_name = ""
175 changes: 175 additions & 0 deletions ai-services/background-music-api/main.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,175 @@
import os
from yt_dlp import YoutubeDL
from yt_dlp.utils import DownloadError
from yt_dlp.extractor import get_info_extractor
from moviepy.editor import VideoFileClip, AudioFileClip, concatenate_audioclips
from spleeter.separator import Separator
import shutil
from moviepy.video.io.ffmpeg_tools import ffmpeg_extract_subclip
from azure.storage.blob import BlobServiceClient
from config import (
storage_account_key,
connection_string,
container_name,
)
import urllib.parse
from fastapi import FastAPI
from fastapi.middleware.cors import CORSMiddleware
from pydantic import BaseModel
import math
from pydub import AudioSegment

app = FastAPI()
export_type = "flac"


def utils_add_bg_music(file_path, video_link):
file_name = file_path.replace(".flac", "")
ydl = YoutubeDL({"format": "best"})
with YoutubeDL(
{"format": "best", "outtmpl": "{}.%(ext)s".format(file_name)}
) as ydl:
ydl.download([video_link])

video = VideoFileClip(file_name + ".mp4")
audio = video.audio

audio_file = file_name + ".wav"
audio.write_audiofile(audio_file)
audio = AudioFileClip(audio_file)
count = 1
duration_of_clip = 60 # in seconds, duration of final audio clip
src_duration = math.ceil(
audio.duration
) # in seconds, the duration of the original audio
audio_file_paths_bg = []

for i in range(0, src_duration, duration_of_clip):
ffmpeg_extract_subclip(
audio_file, i, i + 60, targetname=f"{file_name}_{count}.wav"
)
audio_file_paths_bg.append(f"{file_name}_{count}.wav")
count += 1

separator = Separator(
"spleeter:2stems"
) # Load the 2stems (vocals/accompaniment) model
bg_music = []
for a_file in audio_file_paths_bg:
# Use Spleeter to separate vocals and accompaniment
separation = separator.separate_to_file(a_file, "output")
temp_file_path = os.path.join(
"output", a_file.split("/")[-1].replace(".wav", "")
)
bg_music.append(temp_file_path + "/accompaniment.wav")

final_paths = []
concatenated_bg_audios = audio_file.replace(".wav", "_bg_final.wav")
clips = [AudioFileClip(c) for c in bg_music]
final_clip_1 = concatenate_audioclips(clips)
final_clip_1.write_audiofile(concatenated_bg_audios)

sound1 = AudioSegment.from_file(concatenated_bg_audios)
AudioSegment.from_file(file_path.split("/")[-1]).export(
file_path.replace(".flac", ".wav"), format="wav"
)
sound2 = AudioSegment.from_file(
os.path.join(
file_path.split("/")[-1].replace(".flac", ".wav"),
)
)
audio1 = sound1
audio2 = sound2 + 2
combined = sound2.overlay(audio1)

combined.export(file_path.replace(".wav", "_final.wav"), format="wav")
for fname in audio_file_paths_bg:
if os.path.isfile(fname):
os.remove(fname)

try:
shutil.rmtree("output")
os.remove(concatenated_bg_audios)
os.remove(
os.path.join(
file_path.split("/")[-1].replace(".flac", ".wav"),
)
)
os.remove(file_path.replace(".flac", "") + ".mp4")
except OSError as e:
print("Error: %s - %s." % (e.filename, e.strerror))
return file_path.replace(".wav", "_final.wav")

def upload_audio_to_azure_blob(file_path, export_type, export):
blob_service_client = BlobServiceClient.from_connection_string(connection_string)
if export == False:
AudioSegment.from_wav(file_path + "final.wav").export(
file_path + "final.flac", format="flac"
)
full_path_audio = file_path + "final.flac"
blob_client_audio = blob_service_client.get_blob_client(
container=container_name, blob=file_path.split("/")[-1] + ".flac"
)
else:
full_path_audio = file_path.replace(".flac", "") + "." + export_type
blob_client_audio = blob_service_client.get_blob_client(
container=container_name,
blob=file_path.split("/")[-1].replace(".flac", "") + "." + export_type,
)
with open(full_path_audio, "rb") as data:
try:
if not blob_client_audio.exists():
blob_client_audio.upload_blob(data)
print("Audio uploaded successfully!")
print(blob_client_audio.url)
else:
blob_client_audio.delete_blob()
print("Old Audio deleted successfully!")
blob_client_audio.upload_blob(data)
print("New audio uploaded successfully!")
except Exception as e:
print("This audio can't be uploaded")
return blob_client_audio.url


if __name__ == "__main__":
os.mkdir("temporary_audio_storage")

class BGMusicRequest(BaseModel):
azure_audio_url: str
youtube_url:str

def download_from_azure_blob(file_path):
blob_service_client = BlobServiceClient.from_connection_string(connection_string)
encoded_file_path = file_path.split("/")[-1]
encoded_url_path = urllib.parse.unquote(encoded_file_path)
blob_client = blob_service_client.get_blob_client(
container=container_name, blob=encoded_url_path
)
with open(file=file_path.split("/")[-1], mode="wb") as sample_blob:
download_stream = blob_client.download_blob()
sample_blob.write(download_stream.readall())


@app.post("/add_background_music")
async def add_background_music(audio_request: BGMusicRequest):
url = audio_request.azure_audio_url
youtube_url = audio_request.youtube_url
print("Downloading")
download_from_azure_blob(str(url))
print("Downloaded")
file_path = url.split("/")[-1]
file_path_music = utils_add_bg_music(file_path, youtube_url)
AudioSegment.from_file(file_path_music).export(
file_path.split("/")[-1].replace(".flac", "") + "." + export_type,
format=export_type,
)
azure_url_audio = upload_audio_to_azure_blob(
file_path, export_type, export=True
)
try:
os.remove(file_path)
os.remove(file_path.split("/")[-1].replace(".flac", "") + "." + export_type)
except:
print("Error in removing files")
return {"status": "Success", "output": azure_url_audio}
11 changes: 11 additions & 0 deletions ai-services/background-music-api/requirements.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
pydub
webvtt-py
yt-dlp
ffmpeg
gevent
webrtcvad
fastapi[all]
azure-storage-blob
pydub
moviepy
spleeter
29 changes: 16 additions & 13 deletions backend/.env.example
Original file line number Diff line number Diff line change
@@ -1,40 +1,43 @@
DEBUG=true
SECRET_KEY=
ALLOWED_HOSTS=
FRONTEND_URL=
DOMAIN=
DEBUG=false
SECRET_KEY=''
ALLOWED_HOSTS=backend.chitralekha.ai4bharat.org
FRONTEND_URL=https://chitralekha.ai4bharat.org
DOMAIN="chitralekha.ai4bharat.org/#"

ENABLE_CORS=true
CORS_TRUSTED_ORIGINS=
CORS_TRUSTED_ORIGINS=https://*.ai4bharat.org

POSTGRES_DB_NAME='postgres' # Insert your database name here
POSTGRES_DB_USERNAME='postgres' # Insert your PostgreSQL username here
POSTGRES_DB_PASSWORD='password' #Insert your PostgreSQL password here.
POSTGRES_DB_HOST='db'
POSTGRES_DB_PORT='5432'

DEFAULT_FROM_EMAIL=
EMAIL_HOST=
SMTP_USERNAME=
SMTP_PASSWORD=
DEFAULT_FROM_EMAIL=""
EMAIL_HOST=""
SMTP_USERNAME=""
SMTP_PASSWORD=""

CELERY_BROKER_URL="redis://redis:6379"
# FLOWER_BASIC_AUTH=username:password
FLOWER_BASIC_AUTH=username:password
FLOWER_URL="http://flower:5555"

DHRUVA_KEY=""
# ASR_API_URL=""

ENGLISH_ASR_API_URL=""
INDIC_ASR_API_URL=""
SERVICE_ID_HINDI=""
SERVICE_ID_INDO_ARYAN=""
SERVICE_ID_DRAVIDIAN=""

NMT_API_URL=""
MISC_TTS_API_URL=""
INDO_ARYAN_TTS_API_URL=""
DRAVIDIAN_TTS_API_URL=""
TRANSLITERATION_URL=""
ALIGN_JSON_URL=
BG_MUSIC_API_URL=""

ALIGN_JSON_URL=""

AZURE_STORAGE_ACCOUNT_KEY=""
AZURE_STORAGE_CONNECTION_STRING=""
Expand Down
12 changes: 12 additions & 0 deletions backend/backend/celery.py
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,18 @@
"task": "send_new_tasks_mail",
"schedule": crontab(minute=0, hour=1), # execute everyday at 1 am
},
"Send_mail_to_org_owners": {
"task": "send_new_users_to_org_owner",
"schedule": crontab(minute=1, hour=1), # execute everyday at 1 am
},
"Send_mail_to_users": {
"task": "send_eta_reminders",
"schedule": crontab(minute=2, hour=1), # execute everyday at 1 am
},
"Send_newsletters": {
"task": "send_newsletter",
"schedule": crontab(minute=3, hour=1), # execute everyday at 1 am
},
}

celery_app.autodiscover_tasks()
1 change: 1 addition & 0 deletions backend/backend/settings.py
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,7 @@
"users",
"voiceover",
"youtube",
"newsletter",
]

MIDDLEWARE = [
Expand Down
8 changes: 8 additions & 0 deletions backend/backend/urls.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,8 @@
from drf_yasg.views import get_schema_view
from drf_yasg import openapi
from drf_yasg.generators import OpenAPISchemaGenerator
from video.views import TransliterationAPIView


## Utility Classes
class BothHttpAndHttpsSchemaGenerator(OpenAPISchemaGenerator):
Expand Down Expand Up @@ -68,6 +70,12 @@ def get_schema(self, request=None, public=False):
path("transcript/", include("transcript.urls")),
path("voiceover/", include("voiceover.urls")),
path("youtube/", include("youtube.urls")),
path(
"api/generic/transliteration/<str:target_language>/<str:data>/",
TransliterationAPIView.as_view(),
name="transliteration-api",
),
path("newsletter/", include("newsletter.urls")),
re_path(
r"^swagger(?P<format>\.json|\.yaml)$",
schema_view.without_ui(cache_timeout=0),
Expand Down
1 change: 1 addition & 0 deletions backend/config.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
youtube_api_key = os.getenv("YOUTUBE_API_KEY")
align_json_url = os.getenv("ALIGN_JSON_URL")
transliteration_url = os.getenv("TRANSLITERATION_URL")
bg_music_url = os.getenv("BG_MUSIC_API_URL")

storage_account_key = os.getenv("AZURE_STORAGE_ACCOUNT_KEY")
connection_string = os.getenv("AZURE_STORAGE_CONNECTION_STRING")
Expand Down
Empty file added backend/newsletter/__init__.py
Empty file.
30 changes: 30 additions & 0 deletions backend/newsletter/admin.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
from django.contrib import admin

from .models import Newsletter, SubscribedUsers


# Show particular fields in the admin panel
class NewsletterAdmin(admin.ModelAdmin):
"""
YoutubeAdmin class to render the youtube admin panel.
"""

list_display = (
"newsletter_uuid",
"submitter_id",
"content",
"category",
"created_at",
)


class SubscribedUsersAdmin(admin.ModelAdmin):
"""
YoutubeAdmin class to render the youtube admin panel.
"""

list_display = ("user", "subscribed_categories")


admin.site.register(Newsletter, NewsletterAdmin)
admin.site.register(SubscribedUsers, SubscribedUsersAdmin)
6 changes: 6 additions & 0 deletions backend/newsletter/apps.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
from django.apps import AppConfig


class NewsletterConfig(AppConfig):
default_auto_field = "django.db.models.BigAutoField"
name = "newsletter"
Loading
Loading