SleepyTerr commited on
Commit
ab6d074
·
verified ·
1 Parent(s): 030ce0c

Create app.py

Browse files
Files changed (1) hide show
  1. app.py +30 -0
app.py ADDED
@@ -0,0 +1,30 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import gradio as gr
2
+ import pandas as pd
3
+
4
+ # Load your dataset from HF Dataset repo
5
+ url = "https://huggingface.co/datasets/SleepyTerr/RB_music/resolve/main/rnb_dataset.csv"
6
+ df = pd.read_csv(url)
7
+
8
+ # Define a simple API function
9
+ def get_song(index: int):
10
+ if index < 0 or index >= len(df):
11
+ return "Invalid index"
12
+ song = df.iloc[index]
13
+ return {
14
+ "Song": song['Song'],
15
+ "Artist": song['Artist'],
16
+ "Album": song['Album'],
17
+ "Release Year": song['Release Year'],
18
+ "Monthly Listeners": song['Monthly Listeners']
19
+ }
20
+
21
+ # Gradio interface
22
+ api = gr.Interface(
23
+ fn=get_song,
24
+ inputs=gr.Number(label="Song Index"),
25
+ outputs="json",
26
+ title="R&B Music Dataset API",
27
+ description="Returns song info by index"
28
+ )
29
+
30
+ api.launch()