Omarrran commited on
Commit
8962d31
·
verified ·
1 Parent(s): 7ef5de3

Upload 2 files

Browse files
Files changed (2) hide show
  1. app.py +76 -0
  2. requirements.txt +5 -0
app.py ADDED
@@ -0,0 +1,76 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import gradio as gr
2
+ from transformers import AutoTokenizer, AutoModelForSeq2SeqLM
3
+ import torch
4
+
5
+ REPO_ID = "Omarrran/koshur-diacritizer-byt5-small"
6
+
7
+ print("Loading model...")
8
+ tokenizer = AutoTokenizer.from_pretrained(REPO_ID)
9
+ model = AutoModelForSeq2SeqLM.from_pretrained(REPO_ID)
10
+ model.eval()
11
+ print("Model loaded.")
12
+
13
+
14
+ def diacritize(text: str, max_tokens: int) -> str:
15
+ if not text or not text.strip():
16
+ return ""
17
+ inputs = tokenizer(text.strip(), return_tensors="pt", padding=True)
18
+ with torch.no_grad():
19
+ out = model.generate(**inputs, max_new_tokens=int(max_tokens))
20
+ return tokenizer.decode(out[0], skip_special_tokens=True)
21
+
22
+
23
+ examples = [
24
+ ["کاشر زبان", 256],
25
+ ["میانی ہند", 256],
26
+ ["سریںنگر شہر بوہت خوبصورت چھ", 256],
27
+ ["اس کتاب منز بوہت ژھور معلومات چھ", 256],
28
+ ["کشیر گرمی منز سبز تہ خوبصورت اوسان چھ", 256],
29
+ ["زہ پرون شہر گوم", 256],
30
+ ["امی گر کیاہ پیٹھ بنایو", 256],
31
+ ]
32
+
33
+ description = """
34
+ ## Koshur Diacritizer — ByT5-Small
35
+
36
+ This model restores **diacritical marks** (اِعراب) to undiacritized Kashmiri (کٲشُر) text written in Perso-Arabic script.
37
+
38
+ **Model:** [`Omarrran/koshur-diacritizer-byt5-small`](https://huggingface.co/Omarrran/koshur-diacritizer-byt5-small)
39
+
40
+ Enter raw Kashmiri text below or click an example to try instantly.
41
+ """
42
+
43
+ demo = gr.Interface(
44
+ fn=diacritize,
45
+ inputs=[
46
+ gr.Textbox(
47
+ label="Input Text (undiacritized Kashmiri)",
48
+ placeholder="یہاں کٲشُر متن لِکھِو…",
49
+ lines=3,
50
+ rtl=True,
51
+ ),
52
+ gr.Slider(
53
+ minimum=64,
54
+ maximum=512,
55
+ value=256,
56
+ step=32,
57
+ label="Max New Tokens",
58
+ ),
59
+ ],
60
+ outputs=gr.Textbox(
61
+ label="Diacritized Output",
62
+ lines=3,
63
+ rtl=True,
64
+ show_copy_button=True,
65
+ ),
66
+ examples=examples,
67
+ title="کٲشُر ڈایاکرِٹایزر | Koshur Diacritizer",
68
+ description=description,
69
+ article="Built by [Omar Haq Nawaz Malik](https://huggingface.co/Omarrran) as part of the Kashmiri language AI infrastructure initiative.",
70
+ theme=gr.themes.Soft(),
71
+ cache_examples=False,
72
+ flagging_mode="never",
73
+ )
74
+
75
+ if __name__ == "__main__":
76
+ demo.launch()
requirements.txt ADDED
@@ -0,0 +1,5 @@
 
 
 
 
 
 
1
+ transformers
2
+ torch
3
+ gradio
4
+ sentencepiece
5
+ protobuf