RangGaraga commited on
Commit
b70d6f9
Β·
verified Β·
1 Parent(s): fd837ca

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +11 -16
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", aggregation_strategy="simple")
6
 
7
- # ── Label mapping ─────────────────────────────────────────────────────────────
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>"
@@ -116,7 +116,7 @@ def run_ner(text: str):
116
  return table_html
117
 
118
 
119
- # ── CSS kustom ────────────────────────────────────────────────────────────────
120
  CUSTOM_CSS = """
121
  .gradio-container { max-width: 100% !important; padding: 0 32px !important; }
122
 
@@ -155,43 +155,39 @@ CUSTOM_CSS = """
155
  #analyze-btn:hover { background: #2563eb !important; }
156
  """
157
 
158
- # ── Bangun UI ─────────────────────────────────────────────────────────────────
159
  with gr.Blocks(title="NusaBert NER") as demo:
160
 
161
  gr.HTML("<style>" + CUSTOM_CSS + "</style>")
162
 
163
  gr.Markdown(
164
- "# πŸ” NusaBert NER β€” Pengenalan Entitas Bernama\n"
165
  "Model: **cahya/NusaBert-ner-v1.3** Β· Masukkan teks Bahasa Indonesia lalu klik **Lakukan Analisis**.",
166
  elem_id="app-title",
167
  )
168
 
169
  gr.Markdown("### πŸ“‹ Contoh Teks")
170
 
171
- # FIX 1: inisialisasi list sebelum loop
172
  example_btns = []
173
  for title, body in EXAMPLES:
174
  btn = gr.Button(f"{title}\n\n{body}", elem_classes="example-btn")
175
  example_btns.append((btn, body))
176
 
177
- gr.Markdown("### ✏️ Input Teks")
178
- # FIX 2: parameter lengkap, bukan ...
179
  text_input = gr.Textbox(
180
  lines=8,
181
  placeholder="Ketik atau tempel teks di sini…",
182
  label="",
183
  show_label=False,
184
  )
185
- # FIX 2: parameter lengkap
186
- analyze_btn = gr.Button("πŸ”Ž Lakukan Analisis", elem_id="analyze-btn")
187
 
188
- gr.Markdown("### πŸ“Š Hasil Analisis Entitas")
189
- # FIX 2: parameter lengkap
190
  output_html = gr.HTML(
191
  value="<p style='color:gray; font-size:14px;'>Hasil analisis akan muncul di sini.</p>"
192
  )
193
 
194
- # Hubungkan tombol contoh β†’ input field
195
  for btn, body in example_btns:
196
  btn.click(fn=lambda b=body: b, inputs=[], outputs=text_input)
197
 
@@ -202,5 +198,4 @@ with gr.Blocks(title="NusaBert NER") as demo:
202
  text_input.submit(fn=run_ner, inputs=text_input, outputs=output_html)
203
 
204
  if __name__ == "__main__":
205
- # FIX 3: css dipindah ke launch() sesuai Gradio 6
206
  demo.launch()
 
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>"
 
116
  return table_html
117
 
118
 
119
+ # CSS kustom
120
  CUSTOM_CSS = """
121
  .gradio-container { max-width: 100% !important; padding: 0 32px !important; }
122
 
 
155
  #analyze-btn:hover { background: #2563eb !important; }
156
  """
157
 
158
+ # Bangun UI
159
  with gr.Blocks(title="NusaBert NER") as demo:
160
 
161
  gr.HTML("<style>" + CUSTOM_CSS + "</style>")
162
 
163
  gr.Markdown(
164
+ "#NusaBert NER β€” Pengenalan Entitas Bernama\n"
165
  "Model: **cahya/NusaBert-ner-v1.3** Β· Masukkan teks Bahasa Indonesia lalu klik **Lakukan Analisis**.",
166
  elem_id="app-title",
167
  )
168
 
169
  gr.Markdown("### πŸ“‹ Contoh Teks")
170
 
 
171
  example_btns = []
172
  for title, body in EXAMPLES:
173
  btn = gr.Button(f"{title}\n\n{body}", elem_classes="example-btn")
174
  example_btns.append((btn, body))
175
 
176
+ gr.Markdown("###Input Teks")
 
177
  text_input = gr.Textbox(
178
  lines=8,
179
  placeholder="Ketik atau tempel teks di sini…",
180
  label="",
181
  show_label=False,
182
  )
183
+ analyze_btn = gr.Button("Lakukan Analisis", elem_id="analyze-btn")
 
184
 
185
+ gr.Markdown("### Hasil Analisis Entitas")
 
186
  output_html = gr.HTML(
187
  value="<p style='color:gray; font-size:14px;'>Hasil analisis akan muncul di sini.</p>"
188
  )
189
 
190
+ # Hubungkan tombol contoh
191
  for btn, body in example_btns:
192
  btn.click(fn=lambda b=body: b, inputs=[], outputs=text_input)
193
 
 
198
  text_input.submit(fn=run_ner, inputs=text_input, outputs=output_html)
199
 
200
  if __name__ == "__main__":
 
201
  demo.launch()