RnB_Music_API / app.py
SleepyTerr's picture
Create app.py
ab6d074 verified
raw
history blame contribute delete
776 Bytes
import gradio as gr
import pandas as pd
# Load your dataset from HF Dataset repo
url = "https://huggingface.co/datasets/SleepyTerr/RB_music/resolve/main/rnb_dataset.csv"
df = pd.read_csv(url)
# Define a simple API function
def get_song(index: int):
if index < 0 or index >= len(df):
return "Invalid index"
song = df.iloc[index]
return {
"Song": song['Song'],
"Artist": song['Artist'],
"Album": song['Album'],
"Release Year": song['Release Year'],
"Monthly Listeners": song['Monthly Listeners']
}
# Gradio interface
api = gr.Interface(
fn=get_song,
inputs=gr.Number(label="Song Index"),
outputs="json",
title="R&B Music Dataset API",
description="Returns song info by index"
)
api.launch()