Unknownhackerr commited on
Commit
0a264b8
·
verified ·
1 Parent(s): f7cb858

Upload folder using huggingface_hub

Browse files
app.py CHANGED
@@ -1,36 +1,33 @@
 
1
  import gradio as gr
2
  from transformers import pipeline
3
 
4
  # The pipeline will automatically load the model and tokenizer
5
- # from the current directory where you've put the files.
6
  try:
7
- classifier = pipeline("text-classification", model="Unknownhackerr/hate_check_india", tokenizer="./")
8
 
9
  def classify_text(text):
10
- """
11
- Classifies a single piece of text and returns a human-readable prediction.
12
- """
13
  if not text:
14
  return "Please enter some text to classify."
15
 
16
  result = classifier(text)[0]
 
17
  label = "Hate Speech" if result['label'] == 'LABEL_1' else "Not Hate Speech"
18
  score = result['score']
19
  return f"Prediction: {label}\nConfidence: {score:.4f}"
20
 
21
- # Create the Gradio interface
22
  iface = gr.Interface(
23
  fn=classify_text,
24
  inputs=gr.Textbox(lines=5, placeholder="Enter a comment in English or Hindi..."),
25
  outputs=gr.Textbox(label="Result"),
26
  title="Multilingual Hate Speech Classifier",
27
- description="A model to classify comments in Hindi and English."
28
  )
29
 
30
  iface.launch()
31
 
32
  except Exception as e:
33
- # A simple error message box for the user
34
  gr.Interface(
35
  lambda x: f"An error occurred: {e}",
36
  inputs="text",
@@ -38,4 +35,3 @@ except Exception as e:
38
  title="Error Loading Model",
39
  description="There was an issue loading the model. Please check your files and dependencies."
40
  ).launch()
41
-
 
1
+
2
  import gradio as gr
3
  from transformers import pipeline
4
 
5
  # The pipeline will automatically load the model and tokenizer
6
+ # from the directory where the app is running.
7
  try:
8
+ classifier = pipeline("text-classification", model="./", tokenizer="./")
9
 
10
  def classify_text(text):
 
 
 
11
  if not text:
12
  return "Please enter some text to classify."
13
 
14
  result = classifier(text)[0]
15
+ # Map the default labels to more descriptive ones
16
  label = "Hate Speech" if result['label'] == 'LABEL_1' else "Not Hate Speech"
17
  score = result['score']
18
  return f"Prediction: {label}\nConfidence: {score:.4f}"
19
 
 
20
  iface = gr.Interface(
21
  fn=classify_text,
22
  inputs=gr.Textbox(lines=5, placeholder="Enter a comment in English or Hindi..."),
23
  outputs=gr.Textbox(label="Result"),
24
  title="Multilingual Hate Speech Classifier",
25
+ description="A model to classify comments as hate speech or not."
26
  )
27
 
28
  iface.launch()
29
 
30
  except Exception as e:
 
31
  gr.Interface(
32
  lambda x: f"An error occurred: {e}",
33
  inputs="text",
 
35
  title="Error Loading Model",
36
  description="There was an issue loading the model. Please check your files and dependencies."
37
  ).launch()
 
config.json ADDED
@@ -0,0 +1,27 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ {
2
+ "architectures": [
3
+ "RobertaForSequenceClassification"
4
+ ],
5
+ "attention_probs_dropout_prob": 0.1,
6
+ "bos_token_id": 0,
7
+ "classifier_dropout": null,
8
+ "eos_token_id": 2,
9
+ "hidden_act": "gelu",
10
+ "hidden_dropout_prob": 0.1,
11
+ "hidden_size": 768,
12
+ "initializer_range": 0.02,
13
+ "intermediate_size": 3072,
14
+ "layer_norm_eps": 1e-05,
15
+ "max_position_embeddings": 514,
16
+ "model_type": "roberta",
17
+ "num_attention_heads": 12,
18
+ "num_hidden_layers": 12,
19
+ "pad_token_id": 1,
20
+ "position_embedding_type": "absolute",
21
+ "problem_type": "single_label_classification",
22
+ "torch_dtype": "float32",
23
+ "transformers_version": "4.55.4",
24
+ "type_vocab_size": 1,
25
+ "use_cache": true,
26
+ "vocab_size": 50265
27
+ }
merges.txt ADDED
The diff for this file is too large to render. See raw diff
 
model.safetensors ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:5b645672416dd4ed934c4c67dc0b4060132ef8c269bc70b173270a7bdab3d2e7
3
+ size 498612824
requirements.txt CHANGED
@@ -1,2 +1,4 @@
 
 
 
1
  gradio
2
- transformers
 
1
+
2
+ transformers
3
+ torch
4
  gradio
 
special_tokens_map.json ADDED
@@ -0,0 +1,15 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ {
2
+ "bos_token": "<s>",
3
+ "cls_token": "<s>",
4
+ "eos_token": "</s>",
5
+ "mask_token": {
6
+ "content": "<mask>",
7
+ "lstrip": true,
8
+ "normalized": false,
9
+ "rstrip": false,
10
+ "single_word": false
11
+ },
12
+ "pad_token": "<pad>",
13
+ "sep_token": "</s>",
14
+ "unk_token": "<unk>"
15
+ }
tokenizer.json ADDED
The diff for this file is too large to render. See raw diff
 
tokenizer_config.json ADDED
@@ -0,0 +1,58 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ {
2
+ "add_prefix_space": false,
3
+ "added_tokens_decoder": {
4
+ "0": {
5
+ "content": "<s>",
6
+ "lstrip": false,
7
+ "normalized": true,
8
+ "rstrip": false,
9
+ "single_word": false,
10
+ "special": true
11
+ },
12
+ "1": {
13
+ "content": "<pad>",
14
+ "lstrip": false,
15
+ "normalized": true,
16
+ "rstrip": false,
17
+ "single_word": false,
18
+ "special": true
19
+ },
20
+ "2": {
21
+ "content": "</s>",
22
+ "lstrip": false,
23
+ "normalized": true,
24
+ "rstrip": false,
25
+ "single_word": false,
26
+ "special": true
27
+ },
28
+ "3": {
29
+ "content": "<unk>",
30
+ "lstrip": false,
31
+ "normalized": true,
32
+ "rstrip": false,
33
+ "single_word": false,
34
+ "special": true
35
+ },
36
+ "50264": {
37
+ "content": "<mask>",
38
+ "lstrip": true,
39
+ "normalized": false,
40
+ "rstrip": false,
41
+ "single_word": false,
42
+ "special": true
43
+ }
44
+ },
45
+ "bos_token": "<s>",
46
+ "clean_up_tokenization_spaces": false,
47
+ "cls_token": "<s>",
48
+ "eos_token": "</s>",
49
+ "errors": "replace",
50
+ "extra_special_tokens": {},
51
+ "mask_token": "<mask>",
52
+ "model_max_length": 512,
53
+ "pad_token": "<pad>",
54
+ "sep_token": "</s>",
55
+ "tokenizer_class": "RobertaTokenizer",
56
+ "trim_offsets": true,
57
+ "unk_token": "<unk>"
58
+ }
vocab.json ADDED
The diff for this file is too large to render. See raw diff