Piyushmryaa commited on
Commit
6421cd0
1 Parent(s): 1a863cf

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +40 -39
app.py CHANGED
@@ -1,40 +1,41 @@
1
- import streamlit as st
2
- import torch
3
-
4
- # from datasets import DatasetDict, Dataset
5
-
6
- # # Load train, test, and validation JSON files
7
- # train_data = Dataset.from_json('jsonDataTrain.json')
8
- # test_data = Dataset.from_json('jsonDataTest.json')
9
- # validation_data = Dataset.from_json('jsonDataVal.json')
10
-
11
- # # Define the features
12
- # features = ['Post', 'defamation', 'hate', 'non-hostile', 'offensive']
13
-
14
- labels = ['hate', 'non-hostile', 'defamation', 'offensive']
15
- id2label = {idx:label for idx, label in enumerate(labels)}
16
- label2id = {label:idx for idx, label in enumerate(labels)}
17
-
18
- from transformers import BertTokenizer, BertForSequenceClassification
19
-
20
- # Load the fine-tuned model and tokenizer
21
- model_name = "fine_tuned_hindi_bert_model"
22
- tokenizer = BertTokenizer.from_pretrained(model_name)
23
- model = BertForSequenceClassification.from_pretrained(model_name)
24
-
25
- # Example input text
26
- input_text = "मैं एक छात्र हूं जो छात्रावास में रहता हूं और दृढ़ संकल्प के साथ अपनी पढ़ाई करता हूं लेकिन मेरा दोस्त मूर्ख है। वह हर समय गेम खेलता है और खाना खाता है।"
27
-
28
- input_text1 = st.input_text(input)
29
-
30
- # Tokenize the input text
31
- inputs = tokenizer(input_text, return_tensors="pt")
32
-
33
- # Perform inference
34
- with torch.no_grad():
35
- outputs = model(**inputs)
36
-
37
- # Get the predicted class
38
- predicted_class = outputs.logits
39
- for i in range(len(predicted_class[0])):
 
40
  st.write(id2label[i], predicted_class[0][i].item())
 
1
+ import streamlit as st
2
+ import torch
3
+
4
+ # from datasets import DatasetDict, Dataset
5
+
6
+ # # Load train, test, and validation JSON files
7
+ # train_data = Dataset.from_json('jsonDataTrain.json')
8
+ # test_data = Dataset.from_json('jsonDataTest.json')
9
+ # validation_data = Dataset.from_json('jsonDataVal.json')
10
+
11
+ # # Define the features
12
+ # features = ['Post', 'defamation', 'hate', 'non-hostile', 'offensive']
13
+
14
+ labels = ['hate', 'non-hostile', 'defamation', 'offensive']
15
+ id2label = {idx:label for idx, label in enumerate(labels)}
16
+ label2id = {label:idx for idx, label in enumerate(labels)}
17
+
18
+ from transformers import BertTokenizer, BertForSequenceClassification
19
+
20
+ # Load the fine-tuned model and tokenizer
21
+ model_name = "fine_tuned_hindi_bert_model"
22
+ tokenizer = BertTokenizer.from_pretrained(model_name)
23
+ model = BertForSequenceClassification.from_pretrained(model_name)
24
+
25
+ # Example input text
26
+ # input_text = "मैं एक छात्र हूं जो छात्रावास में रहता हूं और दृढ़ संकल्प के साथ अपनी पढ़ाई करता हूं लेकिन मेरा दोस्त मूर्ख है। वह हर समय गेम खेलता है और खाना खाता है।"
27
+ st.title("Hate Speech Classificsation Demo")
28
+
29
+ input_text = st.input_text(input)
30
+
31
+ # Tokenize the input text
32
+ inputs = tokenizer(input_text, return_tensors="pt")
33
+
34
+ # Perform inference
35
+ with torch.no_grad():
36
+ outputs = model(**inputs)
37
+
38
+ # Get the predicted class
39
+ predicted_class = outputs.logits
40
+ for i in range(len(predicted_class[0])):
41
  st.write(id2label[i], predicted_class[0][i].item())