llmvetter commited on
Commit
f29e8e5
·
1 Parent(s): 7cdd9d5

Moved model to hub

Browse files
Files changed (2) hide show
  1. app.py +36 -0
  2. requirements.txt +3 -0
app.py ADDED
@@ -0,0 +1,36 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import gradio as gr
2
+ from transformers import pipeline
3
+
4
+ # --- Configuration ---
5
+ MODEL_PATH = "./model"
6
+ DEVICE = -1
7
+
8
+ # --- Load Model ---
9
+ classifier = pipeline(
10
+ "text-classification",
11
+ model=MODEL_PATH,
12
+ tokenizer=MODEL_PATH,
13
+ )
14
+
15
+ # --- Prediction Function ---
16
+ def classify_product(product_name):
17
+ result = classifier(product_name)[0]
18
+ category = result['label']
19
+ confidence = result['score'] * 100
20
+ return f"Predicted Category: **{category}**\nConfidence: {confidence:.2f}%"
21
+
22
+ # --- Gradio Interface ---
23
+ iface = gr.Interface(
24
+ fn=classify_product,
25
+ inputs=gr.Textbox(
26
+ lines=3,
27
+ placeholder="Enter a product name (e.g., 'Bluetooth noise-cancelling headphones')",
28
+ ),
29
+ outputs="markdown",
30
+ title="Fine-Tuned Product Classifier",
31
+ description="A demonstration of a fine-tuned BERT model for product category classification. Type a product name and get the predicted category."
32
+ )
33
+
34
+ # --- Launch ---
35
+ if __name__ == "__main__":
36
+ iface.launch()
requirements.txt ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ gradio
2
+ transformers
3
+ torch