OsnNos commited on
Commit
4423ebf
1 Parent(s): 0048c09

Upload 4 files

Browse files
Files changed (4) hide show
  1. app.py +46 -0
  2. config.json +27 -0
  3. model.safetensors +3 -0
  4. requirements.txt +3 -0
app.py ADDED
@@ -0,0 +1,46 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import gradio as gr
2
+ from transformers import pipeline
3
+ from transformers import AutoTokenizer
4
+
5
+ tokenizer = AutoTokenizer.from_pretrained("bert-base-cased")
6
+
7
+ # Load the text classification pipeline from Hugging Face
8
+ classifier = pipeline("text-classification", model="./clickbait-classifier-model-90", tokenizer=tokenizer)
9
+
10
+
11
+ def classify_text(text):
12
+ prediction = classifier(text)[0]
13
+ clickbait_label = "LABEL_1" # Assuming LABEL_1 corresponds to clickbait
14
+ non_clickbait_label = "LABEL_0" # Assuming LABEL_0 corresponds to non-clickbait
15
+
16
+ predicted_label = prediction["label"]
17
+ predicted_score = prediction["score"] * 100
18
+
19
+ clickbait_score = predicted_score if predicted_label == clickbait_label else 0
20
+ non_clickbait_score = predicted_score if predicted_label == non_clickbait_label else 0
21
+
22
+ return clickbait_score, non_clickbait_score
23
+
24
+ # Example clickbait headline
25
+ clickbait_example = ["You'll Never Believe What This Dog Did Next!"]
26
+
27
+ # Example non-clickbait headline
28
+ non_clickbait_example = ["Local School Board Approves New Budget"]
29
+
30
+ # Combine into a list of examples
31
+ examples = [clickbait_example, non_clickbait_example]
32
+
33
+ # Create the Gradio interface
34
+ iface = gr.Interface(
35
+ fn=classify_text,
36
+ inputs=[gr.Textbox(lines=2, placeholder="Enter a text headline...")],
37
+ outputs=[
38
+ gr.Slider(label="Clickbait", minimum=0, maximum=100, step=1),
39
+ gr.Slider(label="Non-Clickbait", minimum=0, maximum=100, step=1),
40
+ ],
41
+ title="Clickbait Detector",
42
+ examples=examples,
43
+ )
44
+
45
+ # Launch the interface
46
+ iface.launch()
config.json ADDED
@@ -0,0 +1,27 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ {
2
+ "_name_or_path": "bert-base-cased",
3
+ "architectures": [
4
+ "BertForSequenceClassification"
5
+ ],
6
+ "attention_probs_dropout_prob": 0.1,
7
+ "classifier_dropout": null,
8
+ "gradient_checkpointing": false,
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-12,
15
+ "max_position_embeddings": 512,
16
+ "model_type": "bert",
17
+ "num_attention_heads": 12,
18
+ "num_hidden_layers": 12,
19
+ "pad_token_id": 0,
20
+ "position_embedding_type": "absolute",
21
+ "problem_type": "single_label_classification",
22
+ "torch_dtype": "float32",
23
+ "transformers_version": "4.35.2",
24
+ "type_vocab_size": 2,
25
+ "use_cache": true,
26
+ "vocab_size": 28996
27
+ }
model.safetensors ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:92a922d579ec96ac374aa6289ff32e226def1858593c658eef584e81becbf78f
3
+ size 433270768
requirements.txt ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ gradio
2
+ transformers
3
+ torch