sivan22 commited on
Commit
9e82615
โ€ข
1 Parent(s): 9f790a3

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +33 -37
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
- login('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')
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
- def get_predicts_local(input)->str:
 
 
22
  classifier = pipeline("text-classification",model=model,top_k=None)
23
- predicts = classifier(input)
24
- return predicts
25
 
26
- def get_predicts_online(input)->str:
27
- import requests
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="Halacha classification",
39
  page_icon="",
40
  )
41
-
42
- st.write("# ื—ื™ืคื•ืฉ ื‘ืฉื•ืœื—ืŸ ืขืจื•ืš")
43
- use_local = st.checkbox("ื—ื™ืคื•ืฉ ืœื ืžืงื•ื•ืŸ")
44
- user_input = st.text_input('ื›ืชื•ื‘ ื›ืืŸ ืืช ืฉืืœืชืš', placeholder='ื›ืžื” ื ืจื•ืช ืžื“ืœื™ืงื™ื ื‘ื—ื ื•ื›ื”')
45
- if st.button('ื—ืคืฉ') and user_input!="":
46
- get_predicts = get_predicts_local if use_local else get_predicts_online
47
- #print(get_predicts(user_input)[0][0:5])
48
- for prediction in get_predicts(user_input)[0][:5]:
49
- rows = df[((df["bookname"] == " ืฉืœื—ืŸ ืขืจื•ืš - ืื•ืจื— ื—ื™ื™ื ") |
50
- (df["bookname"] ==" ืžืฉื ื” ื‘ืจื•ืจื”")) &
51
- (df["siman"] == prediction['label'].split(' ')[0])&
52
- (df["seif"] == prediction['label'].split(' ')[1]) ]
53
- rows.sort_values(["bookname"],ascending=False, inplace=True)
54
-
55
- print(prediction['label'].split(' '))
56
- st.write('ืกื™ืžืŸ ' + str(prediction['label']), rows[['text','sek','seif','siman','bookname']])
 
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