gabehubner commited on
Commit
0dac66f
·
1 Parent(s): 283aa6c

add sentiment

Browse files
Files changed (3) hide show
  1. __pycache__/app.cpython-311.pyc +0 -0
  2. app.py +23 -0
  3. flagged/log.csv +2 -0
__pycache__/app.cpython-311.pyc ADDED
Binary file (1.25 kB). View file
 
app.py ADDED
@@ -0,0 +1,23 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import gradio as gr
2
+ from transformers import AutoTokenizer, AutoModelForSequenceClassification
3
+
4
+ # Load pre-trained model and tokenizer
5
+ model_name = "nlptown/bert-base-multilingual-uncased-sentiment"
6
+ model = AutoModelForSequenceClassification.from_pretrained(model_name)
7
+ tokenizer = AutoTokenizer.from_pretrained(model_name)
8
+
9
+ def predict(text):
10
+ # Tokenize input text
11
+ inputs = tokenizer(text, return_tensors="pt")
12
+
13
+ # Get model's prediction
14
+ outputs = model(**inputs)
15
+
16
+ # Get predicted class index
17
+ predicted_class_idx = outputs.logits.argmax(-1).item()
18
+
19
+ # Return predicted class
20
+ return model.config.id2label[predicted_class_idx]
21
+
22
+ iface = gr.Interface(fn=predict, inputs="text", outputs="text")
23
+ iface.launch(share=True)
flagged/log.csv ADDED
@@ -0,0 +1,2 @@
 
 
 
1
+ name,output,flag,username,timestamp
2
+ John,Hello John!!,,,2024-02-16 12:12:07.583126