tdnathmlenthusiast commited on
Commit
29b1ee9
1 Parent(s): 0d14161

hugging face uploaded main elements

Browse files
Files changed (3) hide show
  1. app.py +32 -0
  2. laptop_data.pkl +3 -0
  3. requirements.txt +4 -0
app.py ADDED
@@ -0,0 +1,32 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import gradio as gr
2
+ from transformers import BertTokenizer, BertForSequenceClassification
3
+ import torch
4
+
5
+ # Load the tokenizer and model
6
+ model_path = "laptop_data.pkl" # Replace with the actual path
7
+ tokenizer = BertTokenizer.from_pretrained(model_path)
8
+ model = BertForSequenceClassification.from_pretrained(model_path)
9
+
10
+ # Set the model to evaluation mode
11
+ model.eval()
12
+
13
+
14
+ def classify_text(text):
15
+ inputs = tokenizer(text, return_tensors="pt",
16
+ padding=True, truncation=True)
17
+ with torch.no_grad():
18
+ outputs = model(**inputs)
19
+ logits = outputs.logits
20
+ probabilities = torch.softmax(logits, dim=1)
21
+ return probabilities[0].tolist()
22
+
23
+
24
+ iface = gr.Interface(
25
+ fn=classify_text,
26
+ inputs=gr.inputs.Textbox(),
27
+ outputs=gr.outputs.Label(num_top_classes=2),
28
+ live=True,
29
+ interpretation="default"
30
+ )
31
+
32
+ iface.launch()
laptop_data.pkl ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:e2ef9db05bf1455d35939d2bc1cecef60ec94ddf364c114612a441cf303d2dd4
3
+ size 328602971
requirements.txt ADDED
@@ -0,0 +1,4 @@
 
 
 
 
 
1
+ gradio==3.17.0
2
+ onnxruntime==1.15.0
3
+ torch==1.13.1
4
+ transformers==4.26.0