File size: 892 Bytes
29b1ee9
900738d
29b1ee9
 
900738d
40a098b
 
29b1ee9
900738d
 
 
 
29b1ee9
 
900738d
29b1ee9
900738d
29b1ee9
900738d
 
 
 
29b1ee9
 
900738d
29b1ee9
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
import gradio as gr
from transformers import AutoTokenizer, AutoModelForSequenceClassification
import torch

# Initialize the tokenizer and model
tokenizer = AutoTokenizer.from_pretrained("laptop_data.pkl")  
model = AutoModelForSequenceClassification.from_pretrained("laptop_data.pkl") 

# Define the function for classifying laptops
def classify_laptop(description):
    inputs = tokenizer(description, return_tensors="pt", padding=True, truncation=True)
    outputs = model(**inputs)
    logits = outputs.logits
    probabilities = torch.softmax(logits, dim=1)
    return {label: prob.item() for label, prob in zip(model.config.id2label.values(), probabilities[0])}

# Create the Gradio interface
iface = gr.Interface(
    fn=classify_laptop,
    inputs=gr.inputs.Textboxbox(),
    outputs=gr.outputs.Label(num_top_classes=5),
    live=True
)

# Launch the Gradio interface
iface.launch()