Thought I had staged it
This commit is contained in:
@@ -2,31 +2,57 @@ import random
|
||||
from typing import Optional
|
||||
|
||||
from dependency_injector.wiring import inject, Provide
|
||||
from fastapi import APIRouter, Path, Query, Depends, BackgroundTasks
|
||||
from fastapi import APIRouter, Path, Query, Depends
|
||||
from pydantic import BaseModel
|
||||
|
||||
from app.dtos.video import Task, TaskStatus
|
||||
from app.middlewares import Authorized, IsAuthenticatedViaBearerToken
|
||||
from app.configs.constants import EducationalContent
|
||||
from app.controllers.abc import ISpeakingController
|
||||
from app.dtos.speaking import (
|
||||
SaveSpeakingDTO, GenerateVideo1DTO, GenerateVideo2DTO, GenerateVideo3DTO
|
||||
)
|
||||
|
||||
controller = "speaking_controller"
|
||||
speaking_router = APIRouter()
|
||||
|
||||
|
||||
@speaking_router.get(
|
||||
'/1',
|
||||
class Video(BaseModel):
|
||||
text: str
|
||||
avatar: Optional[str] = None
|
||||
|
||||
@speaking_router.post(
|
||||
'/media',
|
||||
dependencies=[Depends(Authorized([IsAuthenticatedViaBearerToken]))]
|
||||
)
|
||||
@inject
|
||||
async def get_speaking_task(
|
||||
first_topic: str = Query(default=random.choice(EducationalContent.MTI_TOPICS)),
|
||||
second_topic: str = Query(default=random.choice(EducationalContent.MTI_TOPICS)),
|
||||
difficulty: str = Query(default=random.choice(EducationalContent.DIFFICULTIES)),
|
||||
async def generate_video(
|
||||
video: Video,
|
||||
speaking_controller: ISpeakingController = Depends(Provide[controller])
|
||||
):
|
||||
return await speaking_controller.get_speaking_part(1, first_topic, difficulty, second_topic)
|
||||
return await speaking_controller.generate_video(video.text, video.avatar)
|
||||
|
||||
|
||||
@speaking_router.get(
|
||||
'/media/{vid_id}',
|
||||
dependencies=[Depends(Authorized([IsAuthenticatedViaBearerToken]))]
|
||||
)
|
||||
@inject
|
||||
async def pool_video(
|
||||
vid_id: str = Path(...),
|
||||
speaking_controller: ISpeakingController = Depends(Provide[controller])
|
||||
):
|
||||
return await speaking_controller.pool_video(vid_id)
|
||||
|
||||
|
||||
|
||||
@speaking_router.get(
|
||||
'/avatars',
|
||||
dependencies=[Depends(Authorized([IsAuthenticatedViaBearerToken]))]
|
||||
)
|
||||
@inject
|
||||
async def get_avatars(
|
||||
speaking_controller: ISpeakingController = Depends(Provide[controller])
|
||||
):
|
||||
return await speaking_controller.get_avatars()
|
||||
|
||||
|
||||
|
||||
@speaking_router.get(
|
||||
@@ -35,64 +61,27 @@ async def get_speaking_task(
|
||||
)
|
||||
@inject
|
||||
async def get_speaking_task(
|
||||
task: int = Path(..., ge=2, le=3),
|
||||
topic: str = Query(default=random.choice(EducationalContent.MTI_TOPICS)),
|
||||
task: int = Path(..., ge=1, le=3),
|
||||
topic: Optional[str] = Query(None),
|
||||
first_topic: Optional[str] = Query(None),
|
||||
second_topic: Optional[str] = Query(None),
|
||||
difficulty: str = Query(default=random.choice(EducationalContent.DIFFICULTIES)),
|
||||
speaking_controller: ISpeakingController = Depends(Provide[controller])
|
||||
):
|
||||
return await speaking_controller.get_speaking_part(task, topic, difficulty)
|
||||
if not second_topic:
|
||||
topic_or_first_topic = topic if topic else random.choice(EducationalContent.MTI_TOPICS)
|
||||
else:
|
||||
topic_or_first_topic = first_topic if first_topic else random.choice(EducationalContent.MTI_TOPICS)
|
||||
|
||||
second_topic = second_topic if second_topic else random.choice(EducationalContent.MTI_TOPICS)
|
||||
return await speaking_controller.get_speaking_part(task, topic_or_first_topic, second_topic, difficulty)
|
||||
|
||||
|
||||
@speaking_router.post(
|
||||
'/',
|
||||
dependencies=[Depends(Authorized([IsAuthenticatedViaBearerToken]))]
|
||||
)
|
||||
@inject
|
||||
async def save_speaking(
|
||||
data: SaveSpeakingDTO,
|
||||
background_tasks: BackgroundTasks,
|
||||
speaking_controller: ISpeakingController = Depends(Provide[controller])
|
||||
):
|
||||
return await speaking_controller.save_speaking(data, background_tasks)
|
||||
|
||||
"""
|
||||
async def generate_video(self, text: str, avatar: str):
|
||||
return await self._vid_gen.create_video(text, avatar)
|
||||
|
||||
@speaking_router.post(
|
||||
'/generate_video/1',
|
||||
dependencies=[Depends(Authorized([IsAuthenticatedViaBearerToken]))]
|
||||
)
|
||||
@inject
|
||||
async def generate_video_1(
|
||||
data: GenerateVideo1DTO,
|
||||
speaking_controller: ISpeakingController = Depends(Provide[controller])
|
||||
):
|
||||
return await speaking_controller.generate_video(
|
||||
1, data.avatar, data.first_topic, data.questions, second_topic=data.second_topic
|
||||
)
|
||||
|
||||
|
||||
@speaking_router.post(
|
||||
'/generate_video/2',
|
||||
dependencies=[Depends(Authorized([IsAuthenticatedViaBearerToken]))]
|
||||
)
|
||||
@inject
|
||||
async def generate_video_2(
|
||||
data: GenerateVideo2DTO,
|
||||
speaking_controller: ISpeakingController = Depends(Provide[controller])
|
||||
):
|
||||
return await speaking_controller.generate_video(
|
||||
2, data.avatar, data.topic, [data.question], prompts=data.prompts, suffix=data.suffix
|
||||
)
|
||||
|
||||
|
||||
@speaking_router.post(
|
||||
'/generate_video/3',
|
||||
dependencies=[Depends(Authorized([IsAuthenticatedViaBearerToken]))]
|
||||
)
|
||||
@inject
|
||||
async def generate_video_3(
|
||||
data: GenerateVideo3DTO,
|
||||
speaking_controller: ISpeakingController = Depends(Provide[controller])
|
||||
):
|
||||
return await speaking_controller.generate_video(
|
||||
3, data.avatar, data.topic, data.questions
|
||||
)
|
||||
async def pool_video(self, vid_id: str):
|
||||
return await self._vid_gen.pool_status(vid_id)
|
||||
"""
|
||||
Reference in New Issue
Block a user