|
import warnings |
|
warnings.filterwarnings("ignore") |
|
|
|
import os |
|
import numpy as np |
|
import pandas as pd |
|
from typing import Iterable |
|
|
|
import gradio as gr |
|
from gradio.themes.base import Base |
|
from gradio.themes.utils import colors, fonts, sizes |
|
import requests |
|
import torch |
|
import shutil |
|
import librosa |
|
import torch.nn.functional as F |
|
|
|
|
|
from fetch_img import download_images, scientific_to_species_code |
|
|
|
|
|
from audio_class_predictor import predict_class |
|
from bird_ast_model import birdast_preprocess, birdast_inference |
|
from bird_ast_seq_model import birdast_seq_preprocess, birdast_seq_inference |
|
|
|
from utils import plot_wave, plot_mel, download_model, bandpass_filter |
|
|
|
|
|
def load_markdown_from_url(url): |
|
response = requests.get(url) |
|
response.raise_for_status() |
|
return response.text |
|
|
|
|
|
markdown_url = 'https://github.com/AmroAbdrabo/amroa/raw/main/img/desc.md' |
|
markdown_content = load_markdown_from_url(markdown_url) |
|
|
|
DESCRIPTION = markdown_content |
|
|
|
|
|
css = """ |
|
#gradio-animation { |
|
font-size: 2em; |
|
font-weight: bold; |
|
text-align: center; |
|
margin-bottom: 20px; |
|
} |
|
#gallery { |
|
align: center; |
|
margin: auto; |
|
} |
|
.gr-gallery-item img { |
|
display: block; |
|
margin-left: auto; |
|
margin-right: auto; |
|
} |
|
.logo-container img { |
|
width: 14%; /* Adjust width as necessary */ |
|
display: block; |
|
margin: auto; |
|
} |
|
.number-input { |
|
height: 100%; |
|
padding-bottom: 60px; /* Adust the value as needed for more or less space */ |
|
} |
|
.full-height { |
|
height: 100%; |
|
} |
|
.column-container { |
|
height: 100%; |
|
} |
|
.section-divider { |
|
align: center; |
|
font-size: 100% !important; |
|
color: blue !important; |
|
} |
|
""" |
|
|
|
|
|
class Seafoam(Base): |
|
def __init__( |
|
self, |
|
*, |
|
primary_hue: colors.Color | str = colors.emerald, |
|
secondary_hue: colors.Color | str = colors.blue, |
|
neutral_hue: colors.Color | str = colors.gray, |
|
spacing_size: sizes.Size | str = sizes.spacing_md, |
|
radius_size: sizes.Size | str = sizes.radius_md, |
|
text_size: sizes.Size | str = sizes.text_lg, |
|
font: fonts.Font |
|
| str |
|
| Iterable[fonts.Font | str] = ( |
|
fonts.GoogleFont("Poppins"), |
|
"ui-sans-serif", |
|
"sans-serif", |
|
), |
|
font_mono: fonts.Font |
|
| str |
|
| Iterable[fonts.Font | str] = ( |
|
fonts.GoogleFont("IBM Plex Mono"), |
|
"ui-monospace", |
|
"monospace", |
|
), |
|
): |
|
super().__init__( |
|
primary_hue=primary_hue, |
|
secondary_hue=secondary_hue, |
|
neutral_hue=neutral_hue, |
|
spacing_size=spacing_size, |
|
radius_size=radius_size, |
|
text_size=text_size, |
|
font=font, |
|
font_mono=font_mono, |
|
) |
|
|
|
|
|
seafoam = Seafoam() |
|
|
|
|
|
js = """ |
|
function createGradioAnimation() { |
|
var container = document.getElementById('gradio-animation'); |
|
var text = 'Voice of Jungle'; |
|
for (var i = 0; i < text.length; i++) { |
|
(function(i){ |
|
setTimeout(function(){ |
|
var letter = document.createElement('span'); |
|
letter.style.opacity = '0'; |
|
letter.style.transition = 'opacity 0.5s'; |
|
letter.innerText = text[i]; |
|
container.appendChild(letter); |
|
setTimeout(function() { |
|
letter.style.opacity = '1'; |
|
}, 50); |
|
}, i * 250); |
|
})(i); |
|
} |
|
} |
|
""" |