Spaces:
Running
on
Zero
Running
on
Zero
import gradio as gr | |
from typo_check import css, process_input | |
# 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(): | |
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, | |
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.") | |
import sys | |
sys.path.append('.') | |
from title_gen import generate_title | |
with gr.Row(): | |
article_content = gr.Textbox(lines=10, label="Article Content", rtl=True, elem_classes="textbox1") | |
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], | |
outputs=generated_title | |
) | |
gr.Examples( | |
examples=[ | |
["""އެހެންވެ ޕީކް ގަޑިތަކުގައި ކަރަންޓު ކެނޑޭ މައްސަލަ ބޮޑުވެ، އެންވަޔަރުމެންޓް މިނިސްޓަރު އިބްރާހިމް ތޯރިގު އޭރު ވިދާޅުވި ގޮތުގައި އެކަން ހައްލުކުރުމަށް 1.5 މެގަވޮޓުގެ އާ ޖެނަރޭޓަރެއް ގަނެފައިވެ އެވެ. އަދި މިދިޔަ މަހުގެ ތެރޭގައި އެ ޖެނަރޭޓަރު ބަހައްޓާނެކަމަށް ތޯރިގު ވިދާޅުވި އެވެ. | |
އައްޑޫ ސިޓީ ކައުންސިލުން އާންމުކުރި ވީޑިއޯ އިންޓަވިއުއެއްގައި މޭޔަރު އަލީ ނިޒާރު ވިދާޅުވީ، މި ފަހަރު ދިމާވ ގަމަށް ކަރަންޓު ދީފައިވާ ހައި ވޯލްޓޭޖް ކޭބަލްގެ މައްސަލައެއް ކަމަށެވެ. | |
އެ މައްސަލަ ހައްލުކުރުމަށް ފެނަކައިގެ އިންޖިނިއަރުންގެ ޓީމަކުން މަސައްކަތް ކުރަމުން އަންނަ ކަމަށާއި އެކަމަކު އަދިވެސް މައްސަލަ ދިމާވެފައިވާ ކޭބަލް އޮތް ސަރަހައްދު ސާފު ނުވާ ކަމަށް ނިޒާރު ވިދާޅުވި އެވެ. | |
އޭގެ ސަބަބުން އައްޑޫގެ އެކި ސަރަހައްދުތަކުން ކަރަންޓު ކެނޑުމުގެ މައްސަލަ ދިމާވާ ކަމަށް އޭނާ ވިދާޅުވި އެވެ. | |
"ކޮންމެވެސް ގޮތަކުން މަސައްކަތް ކުރުމުގެ ތެރެއިން ލިބިފައިވާ ގެއްލުމާ އެކު، އެކަން ރަނގަޅު ނުކުރެވި އޮތީ. ގަމަށް ކަރަންޓު ދޭ ކޮންމެ ފަހަރަކު ޕަވާ ސްޓޭޝަނުން ކަރަންޓު ފެއިލް ކޮށްލަނީ. އެހެންވެ، އައްޑޫގެ އެކި ތަންތަނުން ކަރަންޓު ކެނޑެނީ،" ނިޒާރު ވިދާޅުވި އެވެ. | |
"""], | |
["""މަސްތުވެގެން ހުރެ ނުރައްކާތެރިކޮށް ޓެކްސީ ކާރެއް ދުއްވި މީހަކު ހައްޔަރުކޮށްފި އެވެ. | |
އެ މައްސަލާގައި ފުލުހުން ހައްޔަރުކުރީ ކާރު ދުއްވި ހމ. ފްލެޓްނަންބަރު 07-1-4، މުހައްމަދު މާއިސް އެވެ. | |
ފުލުހުން ބުނީ މިދިޔަ ބުރާސްފަތި ދުވަހުގެ ރޭ ހުޅުމާލޭ ހައިވޭގައި ހެޑްލައިޓް ނުދިއްލާ، ހަތަރު ސިގްނަލް ޖައްސައިގެން ނުރައްކާތެރިކޮށް ބާރު ސްޕީޑްގައި ދުއްވާފައި ދިޔަ ކާރެއް ފުލުހުންގެ އެންގުމުން ވެސް މަޑުނުކޮށް ދިޔަ ކަމަށެވެ. | |
އެ ކާރު ހޯދުމުގެ މަސައްކަތް ފުލުހުން ކުރަމުން ގެންދަނިކޮށް، ހުޅުމާލޭ ހައިވަކަރު މަގުން ޓްރީޓޮޕް ހޮސްޕިޓަލާ ދިމާލަށް އެ ކާރު ދަތުރު ކުރަމުން ދަނިކޮށް ފުލުހުން މަޑުކުރަން އެންގުމުން ވެސް މަޑުނުކޮށް ދުއްވާފައި ދިޔަ ކަމަށް ފުލުހުން ބުންޏެވެ. | |
ފުލުހުން ބުނިގޮތުގައި ކާރު ދުއްވާފައި ދިޔައީ ބަމްޕަރުތަކަށާއި ގޯޅި އަޅާއިރު ވެސް ދުވެލި މަޑުނުކޮށެވެ. | |
ޑްރަގްސް ބޭނުން ކޮށްގެން ހުރެ ދުއްވި ކާރު.-- | |
އެގޮތަށް ދުއްވަމުން ގޮސް ރަބަރުގަސްމަގު 97 ނަމްބަރު ފްލެޓް ކައިރިން ކާރު މަޑުކުރި އެ ކާރު ކައިރިއަށް ފުލުހުން ދިއުމުން އަނެއްކާވެސް ކާރު ދުއްވާލަން އުޅުނު ކަމަށް ވެސް ފުލުހުން ބުންޏެވެ. | |
ފުލުހުން ބުނީ ކާރު ހުއްޓުވިއިރު، ކާރުގެ ކަނާތްފަރާތު ފަހަތު ފުރޮޅުގެ ޓަޔަރު ނެތް ކަމަށާއި އެ ޓަޔަރު ފެނިފައިވަނީ 103 ނަމްބަރު ފްލެޓް ކައިރިން ކަމަށެވެ. އަދި ކާރަށް ވެސް އެކި ވަރުގެ ގެއްލުންތައް ލިިބިފައި ހުރި ކަމަށް ފުލުހުން ބުންޏެވެ. | |
ކާރު ދުއްވި މާއިސް ހައްޔަރު ކުރުމުން، ކޯޓުން ވަނީ އޭނާގެ ބަންދަށް ތިން ދުވަސް ޖަހައިފަ އެވެ. | |
ފުލުހުން ވަނީ އެ ކާރު ވެސް ޓޯކޮށްފަ އެވެ. ފުލުހުން އާންމުކުރި ފޮޓޯއިން ފެންނަ ގޮތުގައި އޭނާ ދުއްވ އަވަސް ރައިޑުގެ ޓެކްސީއެކެވެ. | |
"""], | |
], | |
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 and the model is still in early stages of development. | |
### Limitations | |
- The model shines 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. | |
### Tips for Best Results | |
- Use well-structured, news-style content similar to the training data | |
- Try multiple seeds to get different title options | |
- Keep content focused on a single main topic | |
- Review generated titles for accuracy and appropriateness | |
""") | |
# Launch the app | |
if __name__ == "__main__": | |
#demo.launch(server_name="0.0.0.0", server_port=7811) | |
demo.launch() |