RangGaraga commited on
Commit
80eab94
Β·
verified Β·
1 Parent(s): c2bea74

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +17 -17
app.py CHANGED
@@ -1,10 +1,10 @@
1
  import gradio as gr
2
  from transformers import pipeline
3
 
4
- # ── Load model ──────────────────────────────────────────────────────────────
5
- ner = pipeline("ner", model="cahya/NusaBert-ner-v1.3", grouped_entities=True)
6
 
7
- # ── Label mapping (kode β†’ Bahasa Indonesia) ─────────────────────────────────
8
  LABEL_MAP = {
9
  "CRD": "Kardinal",
10
  "DAT": "Tanggal",
@@ -27,7 +27,7 @@ LABEL_MAP = {
27
  "LAN": "Bahasa",
28
  }
29
 
30
- # ── Contoh teks ──────────────────────────────────────────────────────────────
31
  EXAMPLES = [
32
  (
33
  "Contoh 1 – RUPS & Dana Cadangan",
@@ -70,7 +70,7 @@ EXAMPLES = [
70
  ),
71
  ]
72
 
73
- # ── Fungsi inferensi ─────────────────────────────────────────────────────────
74
  def run_ner(text: str):
75
  if not text or not text.strip():
76
  return "<p style='color:gray;'>Masukkan teks terlebih dahulu.</p>"
@@ -114,7 +114,7 @@ def run_ner(text: str):
114
  return table_html
115
 
116
 
117
- # ── CSS kustom ───────────────────────────────────────────────────────────────
118
  CUSTOM_CSS = """
119
  /* Kontainer utama */
120
  .gradio-container { max-width: 860px !important; margin: 0 auto; }
@@ -158,48 +158,48 @@ CUSTOM_CSS = """
158
  #analyze-btn:hover { background: #2563eb !important; }
159
  """
160
 
161
- # ── Bangun UI ─────────────────────────────────────────────────────────────────
162
  with gr.Blocks(css=CUSTOM_CSS, title="NusaBert NER") as demo:
163
 
164
  gr.Markdown(
165
- "# πŸ” NusaBert NER β€” Pengenalan Entitas Bernama\n"
166
  "Model: **cahya/NusaBert-ner-v1.3** Β· Masukkan teks Bahasa Indonesia lalu klik **Lakukan Analisis**.",
167
  elem_id="app-title",
168
  )
169
 
170
  with gr.Row():
171
- # ── Kolom kiri: contoh teks ──────────────────────────────────────────
172
  with gr.Column(scale=1):
173
- gr.Markdown("### πŸ“‹ Contoh Teks")
174
  example_btns = []
175
  for title, body in EXAMPLES:
176
  btn = gr.Button(f"**{title}**\n\n{body}", elem_classes="example-btn")
177
  example_btns.append((btn, body))
178
 
179
- # ── Kolom kanan: input & output ──────────────────────────────────────
180
  with gr.Column(scale=2):
181
- gr.Markdown("### ✏️ Input Teks")
182
  text_input = gr.Textbox(
183
  lines=8,
184
  placeholder="Ketik atau tempel teks di sini…",
185
  label="",
186
  show_label=False,
187
  )
188
- analyze_btn = gr.Button("πŸ”Ž Lakukan Analisis", elem_id="analyze-btn")
189
 
190
- gr.Markdown("### πŸ“Š Hasil Analisis Entitas")
191
  output_html = gr.HTML(
192
  value="<p style='color:gray; font-size:14px;'>Hasil analisis akan muncul di sini.</p>"
193
  )
194
 
195
- # ── Hubungkan tombol contoh β†’ input field ───────────────────────────────
196
  for btn, body in example_btns:
197
  btn.click(fn=lambda b=body: b, inputs=[], outputs=text_input)
198
 
199
- # ── Hubungkan tombol analisis ────────────────────────────────────────────
200
  analyze_btn.click(fn=run_ner, inputs=text_input, outputs=output_html)
201
 
202
- # ── Enter di textbox juga memicu analisis ────────────────────────────────
203
  text_input.submit(fn=run_ner, inputs=text_input, outputs=output_html)
204
 
205
  if __name__ == "__main__":
 
1
  import gradio as gr
2
  from transformers import pipeline
3
 
4
+ # Load model
5
+ ner = pipeline("ner", model="cahya/NusaBert-ner-v1.3", aggregation_strategy="simple")
6
 
7
+ # Label mapping
8
  LABEL_MAP = {
9
  "CRD": "Kardinal",
10
  "DAT": "Tanggal",
 
27
  "LAN": "Bahasa",
28
  }
29
 
30
+ # Contoh teks
31
  EXAMPLES = [
32
  (
33
  "Contoh 1 – RUPS & Dana Cadangan",
 
70
  ),
71
  ]
72
 
73
+ # Fungsi inferensi
74
  def run_ner(text: str):
75
  if not text or not text.strip():
76
  return "<p style='color:gray;'>Masukkan teks terlebih dahulu.</p>"
 
114
  return table_html
115
 
116
 
117
+ # CSS kustom
118
  CUSTOM_CSS = """
119
  /* Kontainer utama */
120
  .gradio-container { max-width: 860px !important; margin: 0 auto; }
 
158
  #analyze-btn:hover { background: #2563eb !important; }
159
  """
160
 
161
+ # Bangun UI
162
  with gr.Blocks(css=CUSTOM_CSS, title="NusaBert NER") as demo:
163
 
164
  gr.Markdown(
165
+ "#NusaBert NER β€” Pengenalan Entitas\n"
166
  "Model: **cahya/NusaBert-ner-v1.3** Β· Masukkan teks Bahasa Indonesia lalu klik **Lakukan Analisis**.",
167
  elem_id="app-title",
168
  )
169
 
170
  with gr.Row():
171
+ # Kolom kiri: contoh teks
172
  with gr.Column(scale=1):
173
+ gr.Markdown("###Contoh Teks")
174
  example_btns = []
175
  for title, body in EXAMPLES:
176
  btn = gr.Button(f"**{title}**\n\n{body}", elem_classes="example-btn")
177
  example_btns.append((btn, body))
178
 
179
+ # Kolom kanan: input & output
180
  with gr.Column(scale=2):
181
+ gr.Markdown("###Input Teks")
182
  text_input = gr.Textbox(
183
  lines=8,
184
  placeholder="Ketik atau tempel teks di sini…",
185
  label="",
186
  show_label=False,
187
  )
188
+ analyze_btn = gr.Button("Lakukan Analisis", elem_id="analyze-btn")
189
 
190
+ gr.Markdown("###Hasil Analisis Entitas")
191
  output_html = gr.HTML(
192
  value="<p style='color:gray; font-size:14px;'>Hasil analisis akan muncul di sini.</p>"
193
  )
194
 
195
+ # Hubungkan tombol contoh β†’ input field
196
  for btn, body in example_btns:
197
  btn.click(fn=lambda b=body: b, inputs=[], outputs=text_input)
198
 
199
+ # Hubungkan tombol analisis
200
  analyze_btn.click(fn=run_ner, inputs=text_input, outputs=output_html)
201
 
202
+ # Enter di textbox juga memicu analisis
203
  text_input.submit(fn=run_ner, inputs=text_input, outputs=output_html)
204
 
205
  if __name__ == "__main__":