beweinreich's picture
update with audio / video url and gpu version of torch
cd7af42
from fastapi import FastAPI, HTTPException
from pydantic import BaseModel
from audio_analyzer import AudioAnalyzer
from video_analyzer import VideoAnalyzer
app = FastAPI()
class AudioRequest(BaseModel):
audio_url: str
class VideoRequest(BaseModel):
video_url: str
@app.get("/")
async def hello_world():
return {"message": "Hello, World!"}
@app.post("/v1/analyze_audio")
async def analyze_audio(request: AudioRequest):
audio_url = request.audio_url
if not audio_url:
raise HTTPException(status_code=400, detail="audio_url is required")
print(f"Analyzing audio... {audio_url}")
analyzer = AudioAnalyzer(media_url=audio_url, media_type="audio")
traits = analyzer.retrieve_traits()
return traits
@app.post("/v1/analyze_video")
async def analyze_video(request: VideoRequest):
video_url = request.video_url
if not video_url:
raise HTTPException(status_code=400, detail="video_url is required")
print(f"Analyzing video... {video_url}")
analyzer = VideoAnalyzer(video_url=video_url)
traits = analyzer.retrieve_traits()
return traits