Spaces:
Configuration error
Configuration error
sync: gradio_app.py from GitHub Actions
Browse files- 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()
|