Spaces:
Runtime error
Runtime error
Update app.py
Browse files
app.py
CHANGED
@@ -5,55 +5,51 @@ import datasets
|
|
5 |
import pandas as pd
|
6 |
from huggingface_hub import login
|
7 |
|
8 |
-
LOGGER = get_logger(__name__)
|
9 |
-
model = "sivan22/halacha-siman-seif-classifier-new"
|
10 |
-
|
11 |
|
12 |
-
|
13 |
-
ds = datasets.load_dataset('sivan22/orach-chaim',token=True)
|
14 |
-
df = ds['train'].to_pandas()
|
15 |
-
def clean(s)->str:
|
16 |
-
return s.replace(" ","")
|
17 |
-
df['seif']= df['seif'].apply(clean)
|
18 |
|
19 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
20 |
|
21 |
-
|
|
|
|
|
22 |
classifier = pipeline("text-classification",model=model,top_k=None)
|
23 |
-
|
24 |
-
return predicts
|
25 |
|
26 |
-
def
|
27 |
-
|
28 |
-
API_URL = "https://api-inference.huggingface.co/models/" + model
|
29 |
-
headers = {"Authorization": f"Bearer {'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'}"}
|
30 |
-
def query(input_text):
|
31 |
-
response = requests.post(API_URL, headers=headers, json='{{inputs:' +input_text+'}{wait_for_model:true}}')
|
32 |
-
return response.json()
|
33 |
-
predicts = query(input)
|
34 |
return predicts
|
35 |
|
36 |
def run():
|
37 |
st.set_page_config(
|
38 |
-
page_title="
|
39 |
page_icon="",
|
40 |
)
|
41 |
-
|
42 |
-
|
43 |
-
|
44 |
-
|
45 |
-
|
46 |
-
|
47 |
-
|
48 |
-
|
49 |
-
|
50 |
-
|
51 |
-
|
52 |
-
|
53 |
-
rows
|
54 |
-
|
55 |
-
|
56 |
-
|
|
|
57 |
|
58 |
|
59 |
|
|
|
5 |
import pandas as pd
|
6 |
from huggingface_hub import login
|
7 |
|
|
|
|
|
|
|
8 |
|
9 |
+
LOGGER = get_logger(__name__)
|
|
|
|
|
|
|
|
|
|
|
10 |
|
11 |
|
12 |
+
@st.cache_data
|
13 |
+
def get_df() ->object:
|
14 |
+
ds = datasets.load_from_disk('sivan22/orach-chaim')
|
15 |
+
df = ds['train'].to_pandas()
|
16 |
+
def clean(s)->str:
|
17 |
+
return s.replace(" ","")
|
18 |
+
df['seif']= df['seif'].apply(clean)
|
19 |
+
return df
|
20 |
|
21 |
+
@st.cache_resource
|
22 |
+
def get_model()->object:
|
23 |
+
model = "sivan22/halacha-siman-seif-classifier"
|
24 |
classifier = pipeline("text-classification",model=model,top_k=None)
|
25 |
+
return classifier
|
|
|
26 |
|
27 |
+
def get_predicts(classifier,input)->str:
|
28 |
+
predicts = classifier(input)
|
|
|
|
|
|
|
|
|
|
|
|
|
29 |
return predicts
|
30 |
|
31 |
def run():
|
32 |
st.set_page_config(
|
33 |
+
page_title="ืืืคืืฉ ืืื ืืฉืืืื ืขืจืื",
|
34 |
page_icon="",
|
35 |
)
|
36 |
+
st.write("# ืืืคืืฉ ืืื ืืฉืืืื ืขืจืื")
|
37 |
+
|
38 |
+
classifier = get_model()
|
39 |
+
df = get_df()
|
40 |
+
|
41 |
+
user_input = st.text_input('ืืชืื ืืื ืืช ืฉืืืชื', placeholder='ืืื ื ืจืืช ืืืืืงืื ืืื ืืืื ืืืืืืช ืืื ืืื')
|
42 |
+
num_of_results = st.sidebar.slider('ืืกืคืจ ืืชืืฆืืืช ืฉืืจืฆืื ื ืืืฆืื:',1,25,5)
|
43 |
+
|
44 |
+
if st.button('ืืคืฉ') and user_input!="":
|
45 |
+
for prediction in get_predicts(classifier,user_input)[0][:num_of_results]:
|
46 |
+
siman = prediction['label'].split(' ')[0]
|
47 |
+
seif = prediction['label'].split(' ')[1]
|
48 |
+
rows = df[((df["bookname"] == " ืฉืืื ืขืจืื - ืืืจื ืืืื ") | (df["bookname"] ==" ืืฉื ื ืืจืืจื")) &
|
49 |
+
(df["siman"] == siman) &
|
50 |
+
(df["seif"] == seif) ]
|
51 |
+
rows = rows.sort_values(["bookname"],ascending=False)
|
52 |
+
st.write(('ืกืืื ' + siman + ' ืกืขืืฃ ' + seif), rows[['text','bookname','sek','seif','siman',]])
|
53 |
|
54 |
|
55 |
|