Spaces:
Runtime error
Runtime error
import streamlit as st | |
from streamlit.logger import get_logger | |
from transformers import pipeline | |
import datasets | |
import pandas as pd | |
from huggingface_hub import login | |
LOGGER = get_logger(__name__) | |
def get_df() ->object: | |
ds = datasets.load_dataset('sivan22/orach-chaim') | |
df = ds['train'].to_pandas() | |
def clean(s)->str: | |
return s.replace(" ","") | |
df['seif']= df['seif'].apply(clean) | |
return df | |
def get_model()->object: | |
model = "sivan22/halacha-siman-seif-classifier" | |
classifier = pipeline("text-classification",model=model,top_k=None) | |
return classifier | |
def get_predicts(classifier,input)->str: | |
predicts = classifier(input) | |
return predicts | |
def run(): | |
st.set_page_config( | |
page_title="讞讬驻讜砖 讞讻诐 讘砖讜诇讞谉 注专讜讱", | |
page_icon="", | |
) | |
st.write("# 讞讬驻讜砖 讞讻诐 讘砖讜诇讞谉 注专讜讱") | |
classifier = get_model() | |
df = get_df() | |
user_input = st.text_input('讻转讜讘 讻讗谉 讗转 砖讗诇转讱', placeholder='讻诪讛 谞专讜转 诪讚诇讬拽讬诐 讘讻诇 诇讬诇讛 诪诇讬诇讜转 讛讞谞讜讻讛') | |
num_of_results = st.sidebar.slider('诪住驻专 讛转讜爪讗讜转 砖讘专爪讜谞讱 诇讛爪讬讙:',1,25,5) | |
if st.button('讞驻砖') and user_input!="": | |
for prediction in get_predicts(classifier,user_input)[0][:num_of_results]: | |
siman = prediction['label'].split(' ')[0] | |
seif = prediction['label'].split(' ')[1] | |
rows = df[((df["bookname"] == " 砖诇讞谉 注专讜讱 - 讗讜专讞 讞讬讬诐 ") | (df["bookname"] ==" 诪砖谞讛 讘专讜专讛")) & | |
(df["siman"] == siman) & | |
(df["seif"] == seif) ] | |
rows = rows.sort_values(["bookname"],ascending=False) | |
st.write(('住讬诪谉 ' + siman + ' 住注讬祝 ' + seif), rows[['text','bookname','sek','seif','siman',]]) | |
if __name__ == "__main__": | |
run() | |