Spaces:
Runtime error
Runtime error
File size: 1,414 Bytes
165591c a0060b9 c5cbe1e 165591c e302782 165591c a0060b9 165591c a0060b9 47e00f6 5b14b96 32441b9 5b14b96 9429ed6 e302782 165591c 5b14b96 e302782 165591c |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 |
import gradio as gr
import numpy as np
import torch
from transformers import AutoModelForSequenceClassification, AutoTokenizer
from examples import yellow, stairway, numb, puppets, firework
def lyrics_categories(input_text):
spotify_model = "spotify/autonlp-huggingface-demo-song-lyrics-18923587"
model = AutoModelForSequenceClassification.from_pretrained(spotify_model)
tokenizer = AutoTokenizer.from_pretrained(spotify_model)
labels = model.config.id2label
inputs = tokenizer(input_text, return_tensors="pt")
outputs = model(**inputs)
predictions = torch.nn.functional.softmax(outputs.logits, dim=-1)
predictions = predictions.detach().numpy()[0]
index_sorted = np.argsort(predictions)[::-1]
clean_outputs = {labels[idx]:str(predictions[idx]) for idx in index_sorted}
print(clean_outputs)
return clean_outputs
description = "With lyrics, find the top 5 genres this song belongs to! (Powered by Spotify)"
iface = gr.Interface(fn=lyrics_categories,
inputs=gr.inputs.Textbox(lines=20, placeholder="Enter song lyrics here...", label="Song Lyrics"),
outputs=gr.outputs.Label(num_top_classes=5,
examples=[stairway, numb, puppets, firework, yellow],
article=desc,
title="Song Lyrics Classifier",
label="Lyrics Categories")
)
iface.launch()
|