File size: 1,922 Bytes
b3f14a4
 
 
 
 
 
 
 
9e82615
b3f14a4
 
9e82615
 
c1c214c
9e82615
 
 
 
 
b3f14a4
9e82615
 
 
b3f14a4
9e82615
b3f14a4
9e82615
 
b3f14a4
 
 
 
9e82615
24e0ce1
b3f14a4
9e82615
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
b3f14a4
 
 
 
 
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
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
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__)


@st.cache_data
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

@st.cache_resource
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()