Spaces:
Runtime error
Runtime error
Added model hub links
Browse files- apps/classifier.py +16 -3
- apps/mlm.py +14 -2
apps/classifier.py
CHANGED
@@ -20,17 +20,30 @@ def load_model(input_text, model_name_or_path):
|
|
20 |
def app():
|
21 |
st.title("RoBERTa Marathi")
|
22 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
23 |
classifier = st.sidebar.selectbox("Select a Model", index=0, options=["Indic NLP", "iNLTK"])
|
24 |
|
25 |
sample_texts = [
|
26 |
-
"दानिश सिद्दीकीच्या मृत्यूला आम्ही जबाबदार नाही",
|
27 |
"अध्यक्ष शरद पवार आणि उपमुख्यमंत्री अजित पवार यांची भेट घेतली.",
|
28 |
"मोठी बातमी! उद्या दुपारी १ वाजता जाहीर होणार दहावीचा निकाल",
|
|
|
29 |
]
|
30 |
model_name_or_path = cfg["models"][classifier]
|
31 |
|
32 |
-
|
33 |
-
|
|
|
|
|
34 |
|
35 |
predict_button = st.button("Predict")
|
36 |
|
|
|
20 |
def app():
|
21 |
st.title("RoBERTa Marathi")
|
22 |
|
23 |
+
st.markdown(
|
24 |
+
"This demo uses [RoBERTa for Marathi](https://huggingface.co/flax-community/roberta-base-mr) model "
|
25 |
+
"trained on [mC4](https://huggingface.co/datasets/mc4)."
|
26 |
+
)
|
27 |
+
|
28 |
+
st.markdown(
|
29 |
+
"Can't figure out where to get a sample text? Visit this "
|
30 |
+
"[link](https://maharashtratimes.com/entertainment/articlelist/19359255.cms), copy any headline and see if "
|
31 |
+
"the model is predicting it as `entertainment` or not."
|
32 |
+
)
|
33 |
+
|
34 |
classifier = st.sidebar.selectbox("Select a Model", index=0, options=["Indic NLP", "iNLTK"])
|
35 |
|
36 |
sample_texts = [
|
|
|
37 |
"अध्यक्ष शरद पवार आणि उपमुख्यमंत्री अजित पवार यांची भेट घेतली.",
|
38 |
"मोठी बातमी! उद्या दुपारी १ वाजता जाहीर होणार दहावीचा निकाल",
|
39 |
+
"Custom",
|
40 |
]
|
41 |
model_name_or_path = cfg["models"][classifier]
|
42 |
|
43 |
+
text_to_classify = st.selectbox("Select a Text", options=sample_texts, index=len(sample_texts) - 1)
|
44 |
+
|
45 |
+
if text_to_classify == "Custom":
|
46 |
+
text_to_classify = st.text_input("Enter custom text:")
|
47 |
|
48 |
predict_button = st.button("Predict")
|
49 |
|
apps/mlm.py
CHANGED
@@ -15,12 +15,22 @@ def load_model(input_text, model_name_or_path):
|
|
15 |
nlp = pipeline("fill-mask", model=model, tokenizer=tokenizer)
|
16 |
result = nlp(input_text)
|
17 |
sentence, mask = result[0]["sequence"], result[0]["token_str"]
|
18 |
-
return sentence, mask
|
19 |
|
20 |
|
21 |
def app():
|
22 |
st.title("RoBERTa Marathi")
|
23 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
24 |
masked_texts = [
|
25 |
"मोठी बातमी! उद्या दुपारी <mask> वाजता जाहीर होणार दहावीचा निकाल",
|
26 |
"अध्यक्ष <mask> पवार आणि उपमुख्यमंत्री अजित पवार यांची भेट घेतली.",
|
@@ -33,7 +43,9 @@ def app():
|
|
33 |
|
34 |
if fill_button:
|
35 |
with st.spinner("Filling the Mask..."):
|
36 |
-
filled_sentence, mask = load_model(masked_text, cfg["models"]["RoBERTa"])
|
37 |
|
38 |
st.markdown(f"**Filled sentence: **{filled_sentence}")
|
39 |
st.markdown(f"**Predicted masked token: **{mask}")
|
|
|
|
|
|
15 |
nlp = pipeline("fill-mask", model=model, tokenizer=tokenizer)
|
16 |
result = nlp(input_text)
|
17 |
sentence, mask = result[0]["sequence"], result[0]["token_str"]
|
18 |
+
return sentence, mask, result
|
19 |
|
20 |
|
21 |
def app():
|
22 |
st.title("RoBERTa Marathi")
|
23 |
|
24 |
+
st.markdown(
|
25 |
+
"This demo uses [RoBERTa for Marathi](https://huggingface.co/flax-community/roberta-base-mr) model "
|
26 |
+
"trained on [mC4](https://huggingface.co/datasets/mc4)."
|
27 |
+
)
|
28 |
+
|
29 |
+
st.markdown(
|
30 |
+
"Can't figure out where to get a sample text? Visit this "
|
31 |
+
"[link](https://maharashtratimes.com/entertainment/articlelist/19359255.cms), copy any headline and mask a word."
|
32 |
+
)
|
33 |
+
|
34 |
masked_texts = [
|
35 |
"मोठी बातमी! उद्या दुपारी <mask> वाजता जाहीर होणार दहावीचा निकाल",
|
36 |
"अध्यक्ष <mask> पवार आणि उपमुख्यमंत्री अजित पवार यांची भेट घेतली.",
|
|
|
43 |
|
44 |
if fill_button:
|
45 |
with st.spinner("Filling the Mask..."):
|
46 |
+
filled_sentence, mask, raw_json = load_model(masked_text, cfg["models"]["RoBERTa"])
|
47 |
|
48 |
st.markdown(f"**Filled sentence: **{filled_sentence}")
|
49 |
st.markdown(f"**Predicted masked token: **{mask}")
|
50 |
+
|
51 |
+
st.write(raw_json)
|