File size: 15,432 Bytes
ae22b44
8f97fc5
82b0ab8
 
b4cd3cb
8f97fc5
8a588ad
8f97fc5
 
0def9f2
 
 
 
 
82b0ab8
 
 
0def9f2
 
 
 
 
 
 
 
82b0ab8
 
0def9f2
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
82b0ab8
0def9f2
 
 
 
 
 
 
 
 
 
 
 
 
 
8f97fc5
0def9f2
8f97fc5
0def9f2
8f97fc5
0def9f2
 
 
8f97fc5
0def9f2
8f97fc5
0def9f2
8f97fc5
0def9f2
8f97fc5
0def9f2
ae22b44
0def9f2
ae22b44
d6fee57
 
 
 
 
 
748c56b
82b0ab8
d6fee57
 
 
 
 
 
 
 
748c56b
d6fee57
 
 
 
 
111a749
d6fee57
111a749
d6fee57
111a749
d6fee57
111a749
d6fee57
 
487547e
111a749
 
d6fee57
 
111a749
d6fee57
111a749
d6fee57
111a749
 
 
 
 
d6fee57
111a749
d6fee57
111a749
d6fee57
111a749
d6fee57
b4cd3cb
d6fee57
b4cd3cb
d6fee57
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
0122fc0
d6fee57
 
 
0122fc0
d6fee57
 
 
 
b4cd3cb
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
d6fee57
 
8f97fc5
 
b1b4044
 
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
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
import gradio as gr

from typo_check import css, process_input,MODEL_OPTIONS_TYPO
from title_gen import generate_title, MODEL_OPTIONS_TITLE
from content_gen import generate_content, MODEL_OPTIONS_CONTENT, get_default_prompt


# Create Gradio interface using the latest syntax
with gr.Blocks(theme=gr.themes.Default(), css=css) as demo:
    with gr.Tabs():
        with gr.Tab("Typo Correction"):
            gr.Markdown("# <center>Dhivehi Typo Correction</center>")
            gr.Markdown("This app uses a fine-tuned T5 model to correct typos in Dhivehi text. Enter text with typos and the model will attempt to fix them.")
            
            with gr.Row():
                model_choice = gr.Dropdown(choices=list(MODEL_OPTIONS_TYPO.keys()), value="A3 Model", label="Model")

            with gr.Row():
                input_text = gr.Textbox(
                    lines=1,
                    placeholder="ދިވެހި ބަހުން ލިޔުމެއް މިތާ ލިޔެބަލާ",
                    label="Input Text",
                    rtl=True,
                    elem_classes="textbox1"
                )


            with gr.Row():
                corrected_text = gr.Textbox(
                    lines=1,
                    label="Corrected Text",
                    rtl=True,
                    elem_classes="textbox1"
                )
            
            with gr.Row():
                highlighted_diff = gr.HTML(
                    label="Changes Highlighted",
                    elem_classes="dhivehi-text"
                )
            
            submit_btn = gr.Button("ރަނގަޅު ކޮށްލުމަށް",elem_classes="textbox1")  # "Correct" in Dhivehi
            submit_btn.click(
                fn=process_input,
                inputs=[input_text,model_choice],
                outputs=[corrected_text, highlighted_diff]
            )
            
            gr.Examples(
                examples=[
                    ["މައި ނޭމް އިސް އަހްމދް"],  # My name is Ahmed (with typos)
                    ["ވަރަށ ރައްގޅޭ ދއުވސް"],   # Very good day (with typos)
                    ["މިއަދ ސްކޫލަށް ދިއުމަށްޓަކައި ހެނދުނ ވަރށް އަވަހށް ތެދުވިން"],  # I woke up early today to go to school (with typos)
                    ["ރާއްޖެއަކީ ވަރށް ރީތި ގުދުރަތީ މަންޒަރުތައް ހުރި ގައުމެކެވެ"],  # Maldives is a country with beautiful natural scenery (with typos)
                    ["ދިވެހި ބަހަކީ އަޅުގަނޑުމެންގެ މާދަރި ބަހެވ އަދި އެބަސް ދިރުވައި އާލާކުރން ޖެހެއވެ"],  # Dhivehi is our mother tongue and we need to preserve it (with typos)
                    ["ކުޅިވަރަކީ ހަށިގަނޑގެ ދުޅަހެޔޮ ކަމަށް ވަރށް މުހިންމު ކަމެކެވެ"],  # Sports are very important for physical health (with typos)
                ],
                inputs=input_text,
            )

            gr.Markdown("""## Note:

        This application uses a fine-tuned T5 model specifically designed to correct common typos in Dhivehi text. The model focuses on:

        - Fixing common mistakes in diacritics
        - Correcting missing Dhivehi letters
        - Addressing typical typing errors

        ### What it can fix

        The model works best with common typing mistakes. For example, if you type "ދިވެހ ބަސް" (missing a diacritic), the model will correct it properly.

        ### Limitations

        The model is trained only on common errors and may not fix more complex or unusual mistakes. For instance, if you type "ދިވެހިދަ ބަސް" (with an incorrect vowel mark rather than a missing one), the correction might not work as expected.

        Simply enter your Dhivehi text with typos, and the model will attempt to correct the common errors while preserving the meaning of your text.""")

        with gr.Tab("Title Generation"):
            gr.Markdown("# <center>Dhivehi Article Title Generator</center>")
            gr.Markdown("Enter Dhivehi article content to generate a title using a fine-tuned T5 model. Set the random seed for reproducibility. Enable sampling for creative/random results.")
            
            with gr.Row():
                article_content = gr.Textbox(lines=10, label="Article Content", rtl=True, elem_classes="textbox1")
            with gr.Row():
                model_choice = gr.Dropdown(choices=list(MODEL_OPTIONS_TITLE.keys()), value="V6 Model", label="Model")
            with gr.Row():
                seed = gr.Slider(0, 10000, value=42, step=1, label="Random Seed")
                use_sampling = gr.Checkbox(label="Use Sampling (Creative/Random)", value=False)
            with gr.Row():
                generated_title = gr.Textbox(label="Generated Title", rtl=True, elem_classes="textbox1" )
            generate_btn = gr.Button("Generate Title")
            generate_btn.click(
                fn=generate_title,
                inputs=[article_content, seed, use_sampling, model_choice],
                outputs=generated_title
            )

            gr.Examples(
                examples=[
                    ["""މިއަދު ފާހަގަކުރާ "އާތު ޑޭ" ނުވަތަ ދުނިޔޭގެ ދުވަހުގެ މުނާސަބަތުގައި ގޫގުލްގެ ޑޫޑުލްގައި ރާއްޖޭގެ ރީތި ރަށެއް ކަމަށްވާ ށ. އެރިޔަދޫ ހިމަނައިފި އެވެ.

ދުނިޔޭގެ ދުވަހާ ގުޅުވައިގެން، ގޫގުލްގެ ހޯމް ޕޭޖުން ފެންނަ ޑޫޑުލް މިއަދު ހަދާފައިވަނީ ދުނިޔޭގެ އަޖައިބެއް ކަހަލަ ރީތި ހަ ތަނެއްގެ މަންޒަރުތައް ބޭނުންކޮށްގެންނެވެ. ޑޫޑުލްގައި ހިމަނާފައި ވަނީ އިނގިރޭސިބަހުން ގޫގުލް ކިޔާއިރު އޮންނަ ހަ އަކުރުގެ ބައްޓަން ސިފަވާ ގޮތަށް އޮންނަ ތަންތަނެވެ.

ޑޫޑުލްގައި، ހިތްގައިމު އެރިޔަދޫ އޮތީ ގޫގުލްގެ "ޖީ" އަކުރުގެ ގޮތުގަ އެވެ.

އެރިޔަދޫއަކީ ހުއިފިލަނޑާ އާލާކުރުމަށް ސަރުކާރުން ވަރަށް ކުރީއްސުރެ އަމިއްލަ މީހަކަށް ކުއްޔަށް ދޫކޮށްފައި އޮންނަ ރަށެކެވެ. އެ ރަށުގެ ހާއްސަ، ރީތި ނޫފެހި ވިލު ބޭނުންކުރަމުން އަންނަނީ ހުއިފިލަނޑާ އަލާކުރުމަށެވެ.


ޑޫޑުލްގައި އެ ރަށް ހިމެނުމަށް ފަހު ގޫގުލް އިން ބުނީ މިފަހަރު "ޖީ" އަކުރު ހާއްސަކުރ ރާއްޖެއަށް ކަމަށެވެ.

"ބިން ތިރިކޮށް ހެދިފައި އޮންނަ ސުވަރުގެއް ފަދަ ރާއްޖެ. މި ރީތި ޖަޒީރާ ގައުމު އެކުލެވިގެންވަނީ ވައް ބައްޓަމަށް އޮންނަ، މުރަކަ ފަރުތަކެއްގެ މަތީގައި އުފެދިފައިވާ ވިހި އަތޮޅުގެ މައްޗަށް. މި އަތޮޅުތަކުގައި ރީތި ފަޅުތައް ހުރޭ. އަދި 'އެޓޯލް' މި ބަސް އައިސްފައި ވަނީ ވެސް ދިވެހިބަހުން،" ގޫގުލް އިން ބުންޏެވެ.


އެރިޔަދޫ

ޑޫޑުލްގައި "އޯ" އަކުރުގައި ހިމަނާފައި ވަނީ ފްރާންސްގެ އެލްޕްސް ފަރުބަދަތަކެވެ. އެއީ ހިލަ ފަރުބަދަތަކާއި ރީތި ފެހި ގަސްތަކުން ޖަރީވެފައި އޮންނަ ރީތި ސަރަހައްދެކެވެ.

ދެވަނަ "އޯ" އަކުރުގައި ހިމަނާފައި ވަނީ ރީތި ކޯރަކާ އެކު އޮންނަ، ގަސްގަހާގެއްސާއި ދިރުންތަކުން މުއްސަނދި ސަރަހައްދެއް ކަމަށްވާ ކެނެޑާގެ ކޯޓް-ނޯޑެވެ.

ދެވަނަ "ޖީ" އަކުރުގައި އާޖެންޓީނާ ދެކުނުގެ ސަރަހައްދެއް ކަމަށްވާ މެންޑޯޒާގެ މަންޒަރެއް ހިމަނާފައިވާއިރު، "އެލް" އަކުރުގައި ހިމަނާފައި ވަނީ އެމެރިކާގެ ޔޫޓާގެ ހަނަފަސް ސަރަހައްދެކެވެ. އަދި "އީ" އަކުރު ހާއްސަކޮށްފައި ވަނީ އޮސްޓްރޭލިއާގެ ނިއު ސައުތު ވޭލްސްގައި އޮންނަ ހިކިފަސް ސަރަހައްދަކަށެވެ.
"""],
        ["""ބިލްބާއޯ (މެއި 1) - ޔޫއެފާ ޔޫރޮޕާ ލީގު ކާމިޔާބު ކުރިޔަސް މެންޗެސްޓާ ޔުނައިޓެޑްގެ މައްސަލަތަކަށް ހައްލެއް ނުލިބޭނެ ކަމަށް ކޯޗު ރުބެން އަމޯރިމް ބުނެފި އެވެ.

ރަށުން ބޭރުގައި މިރޭ އެތުލެޓިކް ބިލްބާއޯއާ ދެކޮޅަށް ކުޅޭ ސެމީ ފައިނަލްގެ ފުރަތަމަ ލެގުގެ ކުރިމް މީޑިއާއާ ވާހަކަ ދައްކަމުން އަމޯރިމް ބުނީ، މުބާރާތް ކާމިޔާބު ކޮށްގެން ޗެމްޕިއަންސް ލީގު ޖާގައެއް ލިބި، ހަރަދު ކުރާނެ ފައިސާ ލިބުނަސް، ކްލަބުގެ ކޮންސިސްޓެންސީ ދަމަހައްޓަން ގިނަ މަސައްކަތްތަކެއް ކުރަން ޖެހިފައިވާ ކަމަށެވެ.

"ޔޫރޮޕާ ލީގު ކާމިޔާބު ކޮށްގެން އަންނަ ސީޒަންގައި ޗެމްޕިއަންސް ލީގު ކުޅެން ލިބުމަކީ، އަހަރެމެންގެ ކްލަބްގެ ބައިވަރު ކަންކަން ބަދަލު ކުރެވިދާނެ ކަމެއް، ކުރިއަށް އޮތް ހޫނު މޫސުމުގެ ޓްރާންސްފާގައި ވެސް،" ޔުނައިޓެޑްގެ ކޯޗު އަމޯރިމް ބުންޏެވެ.

"ޔޫރޮޕާ ލީގުން މޮޅުވެގެން އަހަރެމެންގެ މައްސަލަތަކެއް ހައްލެއް ނުވާނެ. މޮޅުވެގެން ލިބޭނީ ޗެމްޕިއަންސް ލީގުގެ ޖާގައަކާއި ހަރަދު ކުރާނެ ފައިސާ. އެކަމަކު އަސްލު މައްސަލަތައް އަދިވެސް ހުރީ. އަހަރެމެންގެ ކޮންސިސްޓެންޓް ވާން ޖެހޭ. ރަނގަޅު ނިންމުންތައް ނިންމައި، ރަނގަޅު ރެކްރޫޓްމަންޓް ސިސްޓަމަކާއި ރަނގަޅު އެކަޑަމީއެއް ބޭނުންވޭ. މިއީ މި ކުލަބްގެ އަސްލު މަގާމަށް ދިޔުމަށްޓަކައި ހައްލު ކުރަން ޖެހޭ ކަންކަން."

އިނގިރޭސި ޕްރިމިއާ ލީގުގެ 14 ވަނައިގައި އޮތް މެންޗެސްޓާ ޔުނައިޓެޑަށް، އަންނަ ސީޒަންގައި ޔޫރަޕްގެ މުބާރާތެއް ކުޅެވެން އޮތް ހަމައެކަނި ގޮތަކ ޔޫރޮޕާ ލީގު ކާމިޔާބު ކުރުމެވެ.

ޔޫރޮޕާ ލީގުގެ ސެމީ ފައިނަލްގައި އެތުލެޓިކް ބިލްބާއޯ އާއި ޔުނައިޓެޑް މިރޭ ވާދަ ކުރާއިރު، ދެ ވަނަ ސެމީގައި ބައްދަލުކުރާނ ޓޮޓެންހަމް ހޮޓްސްޕާ އާއި ނޯވޭގެ ބޯޑޯ/ގްލިމްޓް އެވެ.
"""],
                ],
                inputs=article_content,
            )

            gr.Markdown("""## Notes:

✨ **What does this do?**

Dhivehi article content and, with the help of a fine-tuned T5 model, conjures up a fitting title! Whether you want something straightforward or a bit more creative, just tweak the random seed or enable sampling for a dash of randomness.

- **Best for:** Quickly summarizing the essence of your article in a catchy title.
- **Creative mode:** Turn on sampling for surprising, out-of-the-box suggestions.
- **Consistent mode:** Keep sampling off for reliable, focused titles.

⚠️ **Experimental Status**
This is an experimental model trained on a very small dataset of Dhivehi news articles. Results may vary significantly.

### Limitations

- The model is only good with clear, well-written content. If your article is too short, vague, or off-topic, the title might be less impressive.
- Sometimes, creativity can go a little too wild—if you get a strange title, try a different seed or turn off sampling.
- Due to limited training data, the model may not handle all topics or writing styles equally well.
- Experimental nature means outputs should be reviewed carefully before use.

""")

        with gr.Tab("Content Generation"):
            gr.Markdown("# <center>Dhivehi Content Generator</center>")
            gr.Markdown("Generate Dhivehi news articles or content using a fine-tuned T5 model. Select your model and tweak generation parameters.")
            with gr.Row():
                model_choice = gr.Dropdown(choices=list(MODEL_OPTIONS_CONTENT.keys()), value=list(MODEL_OPTIONS_CONTENT.keys())[0], label="Model")
            with gr.Row():
                prompt_input = gr.Textbox(label="Input Prompt", lines=1, elem_classes="textbox1")
            def update_prompt(model_choice):
                return get_default_prompt(model_choice)
            model_choice.change(fn=update_prompt, inputs=model_choice, outputs=prompt_input)
            gr.Examples(
                examples=[
                    ["ގުޅިފަޅުގެ ލޭންޑް ޔޫޒް ޕްލޭނަށް ބަދަލު ގެނެސްފައިވާތީ މިއަދު ގުރުއަތުލުން ބާއްވަނީ"],
                    ["ދެމަފިރިންގެ ގުޅުންތަކާއި ޒިންމާތައް ބިނާކުރަން ޖެހޭ އަސާސްތައް"],
                    ["ކެފެއިންގެ ސަބަބުން އިންސާނާގެ ހަށިގަނޑަށް ކުރާ ޖިސްމާނީ އަދި ނަފްސާނީ އަސަރުތައް ބަޔާންކޮށްދެއްވާށެވެ."],
                ],
                inputs=prompt_input,
            )
            with gr.Row():
                max_tokens_slider = gr.Slider(10, 300, value=150, label="Max New Tokens")
                num_beams_slider = gr.Slider(1, 10, value=4, step=1, label="Beam Size (num_beams)")
            with gr.Row():
                rep_penalty_slider = gr.Slider(1.0, 1.9, value=1.2, step=0.1, label="Repetition Penalty")
                ngram_slider = gr.Slider(0, 10, value=3, step=1, label="No Repeat Ngram Size")
            with gr.Row():
                do_sample_checkbox = gr.Checkbox(label="Do Sample", value=True)
            with gr.Row():
                output_text = gr.Textbox(label="Generated Output", lines=10, elem_classes="textbox1")
            generate_button = gr.Button("Generate Content")
            generate_button.click(
                fn=generate_content,
                inputs=[prompt_input, max_tokens_slider, num_beams_slider, rep_penalty_slider, ngram_slider, do_sample_checkbox, model_choice],
                outputs=output_text
            )
            gr.Markdown("""
**Notice:**

All outputs generated are synthetic, created using fine-tuned models for experimental and educational evaluation. Accuracy is not guaranteed, and the content should not be considered a source of truth. Please avoid applying these results to production environments, critical systems, or real-world decision-making without proper validation.
""")

# Launch the app
if __name__ == "__main__":
    #demo.launch(server_name="0.0.0.0", server_port=7811)
    demo.launch()