JonCard's picture
Add Infinite Radio server for Hugging Face Spaces
ab98ae3
Raw History Blame Contribute Delete
1.4 kB
# generated by fastapi-codegen:
# filename: infiniteradio.yml
# GENERATED by scripts/generate.sh from infiniteradio.yml -- DO NOT EDIT.
# Route bodies delegate to functions of the same name in app/handlers.py.
from __future__ import annotations
from fastapi import FastAPI
from pydantic import conint
from app import handlers
from app.lifecycle import lifespan
from .models import Style
app = FastAPI(
title='Infinite Radio',
description='Endless generated music, steered by tempo and style parameters.',
version='1.0',
servers=[{'url': '/'}],
lifespan=lifespan,
)
@app.get('/', response_model=str)
async def get_player():
"""
HTML page with an audio player for the stream.
"""
return await handlers.get_player()
@app.get('/stream', response_model=bytes)
async def get_stream():
"""
Continuous MP3 audio stream of the generated music. All listeners hear the same live stream.
"""
return await handlers.get_stream()
@app.post('/style', response_model=None)
async def post_style(body: Style):
"""
Post a value to set the style for future generated music.
"""
return await handlers.post_style(body)
@app.put('/tempo/{tempo}', response_model=None)
async def put_tempo(tempo: conint(ge=40, le=150)):
"""
Put a value to set the tempo of future generated music.
"""
return await handlers.put_tempo(tempo)