Skip to content

Commit

Permalink
abstract audiocast inteface definitions
Browse files Browse the repository at this point in the history
  • Loading branch information
nwaughachukwuma committed Nov 2, 2024
1 parent 96d454d commit 46fbe15
Show file tree
Hide file tree
Showing 3 changed files with 31 additions and 38 deletions.
24 changes: 2 additions & 22 deletions app/src/utils/render_audiocast_utils.py
Original file line number Diff line number Diff line change
@@ -1,36 +1,16 @@
import re
from pathlib import Path
from typing import TypedDict, cast
from typing import cast

import httpx
import streamlit as st
from pydantic import BaseModel
from src.utils.render_waveform import render_waveform

from env_var import APP_URL, SERVER_URL
from utils_pkg.audiocast_utils import GenerateAudiocastDict, GenerateAudioCastRequest
from utils_pkg.chat_utils import ContentCategory


class GenerateAudioCastRequest(BaseModel):
sessionId: str
summary: str
category: str


class GenerateAudioCastResponse(BaseModel):
url: str
script: str
source_content: str
created_at: str | None


class GenerateAudiocastDict(TypedDict):
url: str
script: str
source_content: str
created_at: str | None


def navigate_to_home():
main_script = str(Path(__file__).parent.parent / "app.py")
st.switch_page(main_script)
Expand Down
20 changes: 4 additions & 16 deletions server/src/utils/generate_audiocast.py
Original file line number Diff line number Diff line change
@@ -1,30 +1,18 @@
from datetime import datetime
from typing import Optional

from fastapi import BackgroundTasks, HTTPException
from pydantic import BaseModel

from services.storage import StorageManager
from utils_pkg.audio_manager import AudioManager, AudioManagerConfig
from utils_pkg.audiocast_request import AudioScriptMaker, generate_source_content
from utils_pkg.chat_utils import ContentCategory
from utils_pkg.audiocast_utils import (
GenerateAudioCastRequest,
GenerateAudioCastResponse,
)
from utils_pkg.session_manager import SessionManager
from utils_pkg.waveform_utils import WaveformUtils


class GenerateAudioCastRequest(BaseModel):
sessionId: str
summary: str
category: ContentCategory


class GenerateAudioCastResponse(BaseModel):
url: str
script: str
source_content: str
created_at: Optional[str]


async def generate_audiocast(
request: GenerateAudioCastRequest, background_tasks: BackgroundTasks
):
Expand Down
25 changes: 25 additions & 0 deletions utils_pkg/audiocast_utils.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
from typing import TypedDict

from pydantic import BaseModel

from utils_pkg.chat_utils import ContentCategory


class GenerateAudioCastRequest(BaseModel):
sessionId: str
summary: str
category: ContentCategory


class GenerateAudioCastResponse(BaseModel):
url: str
script: str
source_content: str
created_at: str | None


class GenerateAudiocastDict(TypedDict):
url: str
script: str
source_content: str
created_at: str | None

0 comments on commit 46fbe15

Please sign in to comment.