bisalsaha commited on
Commit
cc1caa1
·
1 Parent(s): 2880440

Initial ZeroGPU-compatible classifier

Browse files
Files changed (2) hide show
  1. app.py +39 -0
  2. requirements.txt +4 -0
app.py ADDED
@@ -0,0 +1,39 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import spaces
2
+ import gradio as gr
3
+ from transformers import pipeline
4
+
5
+ classifier = pipeline(
6
+ "zero-shot-classification",
7
+ model="facebook/bart-large-mnli"
8
+ )
9
+
10
+ TRADE_DOC_TYPES = [
11
+ "Commercial Invoice",
12
+ "Packing List",
13
+ "Bill of Lading",
14
+ "Certificate of Origin"
15
+ ]
16
+
17
+ @spaces.GPU
18
+ def classify_document(text):
19
+ if not text or not text.strip():
20
+ return {"error": "Empty text"}
21
+
22
+ prediction = classifier(text[:500], candidate_labels=TRADE_DOC_TYPES)
23
+
24
+ return {
25
+ "predicted_type": prediction["labels"][0],
26
+ "confidence": round(prediction["scores"][0], 3),
27
+ "all_scores": dict(zip(prediction["labels"],
28
+ [round(s, 3) for s in prediction["scores"]]))
29
+ }
30
+
31
+ demo = gr.Interface(
32
+ fn=classify_document,
33
+ inputs=gr.Textbox(label="Document Text", lines=10),
34
+ outputs=gr.JSON(label="Classification Result"),
35
+ title="UCB Document Classifier",
36
+ description="PDF থেকে বের করা টেক্সট দিন, Document Type বলে দিবে"
37
+ )
38
+
39
+ demo.launch()
requirements.txt ADDED
@@ -0,0 +1,4 @@
 
 
 
 
 
1
+ transformers
2
+ torch
3
+ gradio
4
+ spaces