-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* add dockerfile and deploy.yml * remove groq_api_key from env_var * add footer; improve readme, page title and subheader * render a default state for sidebar content * cleanup * allow traffic on first creation * reset no_traffic to true for preview urls * remove the footer file * rename service to audiora * revert no_traffic * set concurrency to 80 * set max-instances to 10 * add .env.example; cleanup * create a storage service; define bucket_name env variable * use a call abstraction for gcs methods * add logic to store an audio to gcs * fix bug with audio enhancement logic; cleanup
- Loading branch information
1 parent
3822b58
commit 3b2f163
Showing
10 changed files
with
127 additions
and
42 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
PROJECT_ID="your-project-id" | ||
GOOGLE_APPLICATION_CREDENTIALS="path/to/your/serviceAccount.json" | ||
|
||
OPENAI_API_KEY="your-openai-api-key" | ||
ANTHROPIC_API_KEY="your-anthropic-api-key" | ||
GEMINI_API_KEY="your-gemini-api-key" | ||
ELEVENLABS_API_KEY="your-elevenlabs-api-key" | ||
|
||
BUCKET_NAME="your-bucket-name" | ||
APP_URL=http://localhost:8501 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -8,3 +8,5 @@ __pycache__ | |
!.env.example | ||
|
||
reference_code | ||
|
||
keys/ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
[browser] | ||
gatherUsageStats = false |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,77 @@ | ||
from dataclasses import dataclass | ||
from io import BytesIO | ||
from pathlib import Path | ||
from typing import Any, Dict | ||
from uuid import uuid4 | ||
|
||
from google.cloud import storage | ||
|
||
from src.env_var import BUCKET_NAME | ||
|
||
storage_client = storage.Client() | ||
bucket = storage_client.bucket(BUCKET_NAME) | ||
BLOB_BASE_URI = "audiora/assets" | ||
|
||
|
||
def listBlobs(prefix): | ||
blobs = bucket.list_blobs(prefix=prefix) | ||
return [blob for blob in blobs] | ||
|
||
|
||
def check_file_exists(root_path: str, filename: str): | ||
"""check if a file exists in the bucket""" | ||
blobname = f"{root_path}/{filename}" | ||
blobs = listBlobs(prefix=root_path) | ||
return any(blob.name == blobname for blob in blobs) | ||
|
||
|
||
@dataclass | ||
class UploadItemParams: | ||
content_type: str | ||
cache_control: str = "public, max-age=31536000" | ||
metadata: Dict[str, Any] | None = None | ||
|
||
|
||
class StorageManager: | ||
def upload_to_gcs( | ||
self, item: str | Path | BytesIO, blobname: str, params: UploadItemParams | ||
): | ||
"""upload item to GCS""" | ||
blob = bucket.blob(blobname) | ||
blob.content_type = params.content_type | ||
blob.cache_control = params.cache_control | ||
|
||
if params.metadata: | ||
blob.metadata = {**(blob.metadata or dict()), **params.metadata} | ||
|
||
if isinstance(item, Path): | ||
blob.upload_from_filename(str(item)) | ||
elif isinstance(item, str): | ||
blob.upload_from_string(item) | ||
else: | ||
blob.upload_from_file(item) | ||
|
||
return f"gs://{BUCKET_NAME}/{blob.name}" | ||
|
||
def upload_audio_to_gcs(self, tmp_audio_path: str, filename=str(uuid4())): | ||
"""upload audio file to GCS""" | ||
blobname = f"{BLOB_BASE_URI}/{filename}" | ||
self.upload_to_gcs( | ||
Path(tmp_audio_path), | ||
blobname, | ||
UploadItemParams(content_type="audio/mpeg"), | ||
) | ||
|
||
return f"gs://{BUCKET_NAME}/{blobname}" | ||
|
||
def download_from_gcs(self, filename: str): | ||
""" | ||
Download any item on GCS to disk | ||
""" | ||
blobname = f"{BLOB_BASE_URI}/{filename}" | ||
blob = bucket.blob(blobname) | ||
tmp_file_path = f"/tmp/{str(uuid4())}" | ||
|
||
blob.download_to_filename(tmp_file_path) | ||
|
||
return tmp_file_path |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters