nebiyu29 commited on
Commit
aea9d52
1 Parent(s): 71eddc7

initial commit

Browse files
Files changed (1) hide show
  1. main.py +30 -0
main.py ADDED
@@ -0,0 +1,30 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ from transformers import AutoTokenizer, AutoModelForSequenceClassification
2
+
3
+
4
+ # Load model directly
5
+ from transformers import AutoTokenizer, AutoModelForSequenceClassification
6
+
7
+ tokenizer = AutoTokenizer.from_pretrained("nebiyu29/fintunned-v2-roberta_GA")
8
+ model = AutoModelForSequenceClassification.from_pretrained("nebiyu29/fintunned-v2-roberta_GA")
9
+
10
+
11
+ def classify_text(text):
12
+ """
13
+ This function preprocesses, feeds text to the model, and outputs the predicted class.
14
+ """
15
+ inputs = tokenizer(text, padding=True, truncation=True, return_tensors="pt")
16
+ outputs = model(**inputs)
17
+ logits = outputs.logits # Access logits instead of pipeline output
18
+ predictions = torch.argmax(logits, dim=-1) # Apply argmax for prediction
19
+ return model.config.id2label[predictions.item()] # Map index to class label
20
+
21
+ interface = gr.Interface(
22
+ fn=classify_text,
23
+ inputs="text",
24
+ outputs="text",
25
+ title="Text Classification Demo",
26
+ description="Enter some text, and the model will classify it.",
27
+ choices=["positive", "negative", "neutral"] # Adjust class names
28
+ )
29
+
30
+ interface.launch()