bisalsaha's picture
Update app.py
9b11bd0 verified
Raw History Blame Contribute Delete
1.5 kB
import spaces
import gradio as gr
from transformers import pipeline
# আপনার ফাইন-টিউন করা 100% একুরেট মডেল
MODEL_ID = "bisalsaha/bart-trade-doc-classifier"
classifier = pipeline("text-classification", model=MODEL_ID)
@spaces.GPU
def classify_document(text):
if not text or not text.strip():
return {"error": "অনুগ্রহ করে ডকুমেন্টের টেক্সট পেস্ট করুন।"}
# ৬টি মূল বাংলাদেশ ব্যাংক ক্যাটাগরিতে প্রেডিকশন
results = classifier(text[:1024], top_k=None)
all_scores = {r["label"]: f"{round(r['score'] * 100, 2)}%" for r in results}
top_result = results[0]
return {
"Document Category": top_result["label"],
"Confidence": f"{round(top_result['score'] * 100, 2)}%",
"All Category Confidences": all_scores
}
demo = gr.Interface(
fn=classify_document,
inputs=gr.Textbox(
label="Document Text (from PDF / OCR)",
lines=12,
placeholder="Paste document text from Bill of Entry, LCA, LC, IMP, EXP, or PRC here..."
),
outputs=gr.JSON(label="Bangladesh Bank IDP Classification Result"),
title="🏦 UCB - Bangladesh Bank Trade Document Classifier",
description="Fine-tuned BART Model for 6 Core Bangladesh Bank Regulatory Categories (LCA, LC, Bill of Entry, IMP, EXP, PRC)."
)
demo.launch()