Spaces:
Running
Running
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()
|