Spaces:
Sleeping
Sleeping
UltraMarkoBR
commited on
Create app.py
Browse files
app.py
ADDED
@@ -0,0 +1,39 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
import streamlit as st
|
2 |
+
from transformers import AutoModelForSequenceClassification, AutoTokenizer
|
3 |
+
import torch
|
4 |
+
|
5 |
+
# Load pre-trained model and tokenizer
|
6 |
+
model_name = "distilbert-base-uncased"
|
7 |
+
model = AutoModelForSequenceClassification.from_pretrained(model_name)
|
8 |
+
tokenizer = AutoTokenizer.from_pretrained(model_name)
|
9 |
+
|
10 |
+
# Define a function to search for Samba songs
|
11 |
+
def search_samba(query):
|
12 |
+
# Tokenize the query
|
13 |
+
inputs = tokenizer(query, return_tensors="pt")
|
14 |
+
|
15 |
+
# Get the model's output
|
16 |
+
outputs = model(**inputs)
|
17 |
+
|
18 |
+
# Get the predicted class probabilities
|
19 |
+
logits = outputs.logits
|
20 |
+
probs = torch.nn.functional.softmax(logits, dim=1)
|
21 |
+
|
22 |
+
# Return the top 5 Samba song matches
|
23 |
+
top_5 = torch.topk(probs, k=5)
|
24 |
+
return top_5.indices, top_5.values
|
25 |
+
|
26 |
+
# Create a Streamlit app
|
27 |
+
st.title("Samba Search")
|
28 |
+
|
29 |
+
# Get user input
|
30 |
+
query = st.text_input("Enter a song title or artist")
|
31 |
+
|
32 |
+
# Search for Samba songs
|
33 |
+
if st.button("Search"):
|
34 |
+
indices, values = search_samba(query)
|
35 |
+
|
36 |
+
# Display the top 5 matches
|
37 |
+
st.write("Top 5 Samba Song Matches:")
|
38 |
+
for i, (index, value) in enumerate(zip(indices[0], values[0])):
|
39 |
+
st.write(f"{i+1}. Song {index.item()} - Probability: {value.item():.2f}")
|