Spaces:
Sleeping
Sleeping
Create app.py
Browse files
app.py
ADDED
@@ -0,0 +1,33 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
import gradio as gr
|
2 |
+
from transformers import AutoTokenizer, AutoModelForSequenceClassification, pipeline
|
3 |
+
|
4 |
+
# Load the tokenizer and model
|
5 |
+
model_name = "alpcansoydas/product-model-18.10.24-bert-total27label_ifhavemorethan100sampleperfamily"
|
6 |
+
tokenizer_name = "bert-base-uncased"
|
7 |
+
|
8 |
+
# Initialize tokenizer and model
|
9 |
+
tokenizer = AutoTokenizer.from_pretrained(tokenizer_name)
|
10 |
+
model = AutoModelForSequenceClassification.from_pretrained(model_name)
|
11 |
+
|
12 |
+
# Create a pipeline for text classification
|
13 |
+
classifier = pipeline("text-classification", model=model, tokenizer=tokenizer)
|
14 |
+
|
15 |
+
# Function to classify input text
|
16 |
+
def classify_product_family(text):
|
17 |
+
results = classifier(text)
|
18 |
+
predicted_label = results[0]['label']
|
19 |
+
return f"Predicted Family Label: {predicted_label}"
|
20 |
+
|
21 |
+
# Gradio interface
|
22 |
+
with gr.Blocks() as demo:
|
23 |
+
gr.Markdown("# Product Family Classifier")
|
24 |
+
gr.Markdown("Classify product descriptions into one of 27 family labels.")
|
25 |
+
|
26 |
+
input_text = gr.Textbox(label="Enter Product Description", placeholder="Type product description here...")
|
27 |
+
output_label = gr.Textbox(label="Predicted Family Label")
|
28 |
+
|
29 |
+
classify_button = gr.Button("Classify")
|
30 |
+
classify_button.click(fn=classify_product_family, inputs=input_text, outputs=output_label)
|
31 |
+
|
32 |
+
# Launch the Gradio interface
|
33 |
+
demo.launch()
|