Piyushmryaa commited on
Commit
83c2f38
1 Parent(s): 226ed4d

files upload 1

Browse files
Files changed (5) hide show
  1. demo.py +40 -0
  2. jsonDataTest.json +0 -0
  3. jsonDataTrain.json +0 -0
  4. jsonDataValid.json +0 -0
  5. requirements.txt +1 -0
demo.py ADDED
@@ -0,0 +1,40 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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())
jsonDataTest.json ADDED
The diff for this file is too large to render. See raw diff
 
jsonDataTrain.json ADDED
The diff for this file is too large to render. See raw diff
 
jsonDataValid.json ADDED
The diff for this file is too large to render. See raw diff
 
requirements.txt ADDED
@@ -0,0 +1 @@
 
 
1
+ streamlit