Spaces:
Runtime error
Runtime error
File size: 1,236 Bytes
97b2e7d 04d1b46 c08b24a 11b0444 f59afe1 11b0444 8908623 11b0444 cf60be6 11b0444 97b2e7d 1b39098 97b2e7d 1b39098 97b2e7d |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 |
import gradio as gr
import hazm
import typing
normalizer = hazm.Normalizer()
sent_tokenizer = hazm.SentenceTokenizer()
word_tokenizer = hazm.WordTokenizer()
tagger = hazm.POSTagger(
model=str("pos_tagger.model")
)
def preprocess_text(text: str) -> typing.List[typing.List[str]]:
"""Split/normalize text into sentences/words with hazm"""
text = normalizer.normalize(text)
processed_sentences = []
for sentence in sent_tokenizer.tokenize(text):
words = word_tokenizer.tokenize(sentence)
processed_words = fix_words(words)
processed_sentences.append(processed_words)
return " ".join(processed_sentences)
def fix_words(words: typing.List[str]) -> typing.List[str]:
fixed_words = []
for word, pos in tagger.tag(words):
if pos[-1] == "e":
if word[-1] != "ِ":
if (word[-1] == "ه") and (word[-2] != "ا"):
word += "ی"
word += "ِ"
fixed_words.append(word)
return fixed_words
def greet(name):
return name
iface = gr.Interface(fn=preprocess_text, inputs="text", outputs="text")
iface.launch() |