ggapar commited on
Commit
88afcc9
Β·
verified Β·
1 Parent(s): 0813b0f

sync: gradio_app.py from GitHub Actions

Browse files
Files changed (1) hide show
  1. gradio_app.py +24 -0
gradio_app.py CHANGED
@@ -141,6 +141,20 @@ def classify_text(text: str, mode: str):
141
  return label, badge, reasoning, status
142
 
143
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
144
  # ── UI ───────────────────────────────────────────────────────────────────────
145
 
146
  with gr.Blocks(title="DFK Text Classifier", theme=gr.themes.Soft()) as demo:
@@ -208,6 +222,16 @@ with gr.Blocks(title="DFK Text Classifier", theme=gr.themes.Soft()) as demo:
208
  outputs=[text_input, label_out, badge_html, reasoning_out, status_out],
209
  )
210
 
 
 
 
 
 
 
 
 
 
 
211
  if __name__ == "__main__":
212
  demo.queue(max_size=5)
213
  demo.launch()
 
141
  return label, badge, reasoning, status
142
 
143
 
144
+
145
+
146
+ # ── Dedicated API endpoint (hanya butuh text, mode=cepat default) ─────────────
147
+ # Teman bisa panggil via: client.predict(text, api_name="/api_predict")
148
+
149
+ def api_predict(text: str) -> dict:
150
+ """
151
+ Simple API endpoint untuk pemanggilan eksternal.
152
+ Input : text (str)
153
+ Output: dict dengan keys: label, status
154
+ """
155
+ label, _, _, status = classify_text(text, "Cepat (~30 detik) β€” Label saja")
156
+ return {"label": label, "status": status}
157
+
158
  # ── UI ───────────────────────────────────────────────────────────────────────
159
 
160
  with gr.Blocks(title="DFK Text Classifier", theme=gr.themes.Soft()) as demo:
 
222
  outputs=[text_input, label_out, badge_html, reasoning_out, status_out],
223
  )
224
 
225
+ # ── Hidden API trigger (dipanggil via api_name='/api_predict') ─────────────
226
+ api_text_input = gr.Textbox(visible=False)
227
+ api_output = gr.JSON(visible=False)
228
+ api_text_input.submit(
229
+ api_predict,
230
+ inputs=api_text_input,
231
+ outputs=api_output,
232
+ api_name="api_predict",
233
+ )
234
+
235
  if __name__ == "__main__":
236
  demo.queue(max_size=5)
237
  demo.launch()