Spaces:
Runtime error
Runtime error
Download app.py from chriskasparaws/songsopenapi: direct link, hf CLI and curl.
- Browser
- Download file 839 Bytes
-
https://huggingface.co/spaces/chriskasparaws/songsopenapi/resolve/main/app.py
- Command line
-
hf download hf://spaces/chriskasparaws/songsopenapi/app.py
-
curl -L -o app.py https://huggingface.co/spaces/chriskasparaws/songsopenapi/resolve/main/app.py
839 Bytes
| from fastapi import FastAPI | |
| from pydantic import BaseModel | |
| from typing import List | |
| import uvicorn | |
| app = FastAPI(title="Top Songs API", description="API to retrieve the top 10 songs played today", version="1.0.0") | |
| class Song(BaseModel): | |
| title: str | |
| artist: str | |
| album: str | |
| class TopSongs(BaseModel): | |
| songs: List[Song] | |
| # Simulate a larger dataset of songs | |
| all_songs = [ | |
| {"title": f"Song Title {i}", "artist": f"Artist Name {i}", "album": f"Album Name {i}"} for i in range(1, 101) | |
| ] | |
| async def read_top_songs(): | |
| # This example simply slices the first 10 songs to simulate "top songs" | |
| return all_songs[:10] | |
| if __name__ == "__main__": | |
| uvicorn.run(app, host="0.0.0.0") | |