Spaces:
Sleeping
Sleeping
| import gradio as gr | |
| from transformers import pipeline | |
| nama_model = "datanikah9/mbart-penerjemah-gorontalo" | |
| # Untuk Space default CPU, hapus device=0 | |
| penerjemah = pipeline("translation", model=nama_model) | |
| def terjemahkan(teks, arah): | |
| if not teks: | |
| return "" | |
| if arah == "Indonesia ➡ Gorontalo": | |
| hasil = penerjemah(teks, src_lang="id_ID", tgt_lang="gor_GN") | |
| else: | |
| hasil = penerjemah(teks, src_lang="gor_GN", tgt_lang="id_ID") | |
| return hasil[0]['translation_text'] | |
| demo = gr.Interface( | |
| fn=terjemahkan, | |
| inputs=[ | |
| gr.Textbox(lines=5, label="Masukkan Teks"), | |
| gr.Radio(["Indonesia ➡ Gorontalo", "Gorontalo ➡ Indonesia"], value="Indonesia ➡ Gorontalo", label="Arah Terjemahan") | |
| ], | |
| outputs=gr.Textbox(lines=5, label="Hasil Terjemahan"), | |
| title="Penerjemah MBART Gorontalo ↔ Indonesia", | |
| description="Model `datanikah9/mbart-penerjemah-gorontalo` untuk menerjemahkan teks dua arah antara Bahasa Indonesia dan Bahasa Gorontalo.", | |
| examples=[ | |
| ["Bagaimana kabarmu hari ini?", "Indonesia ➡ Gorontalo"], | |
| ["Ti huta wawu", "Gorontalo ➡ Indonesia"] | |
| ] | |
| ) | |
| demo.launch() |