Spaces:
Runtime error
Runtime error
Create app.py
Browse files
app.py
ADDED
@@ -0,0 +1,61 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
import streamlit as st
|
2 |
+
from streamlit.logger import get_logger
|
3 |
+
from transformers import pipeline
|
4 |
+
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 |
+
|
60 |
+
if __name__ == "__main__":
|
61 |
+
run()
|