File size: 2,035 Bytes
cf160e1
 
6dad16b
c34d1aa
 
 
7aa55e8
e04912d
c54e7cb
7aa55e8
3fec75f
e04912d
7aa55e8
3fe32e4
7aa55e8
 
30bcf14
 
c34d1aa
6dad16b
cf160e1
2371e04
9f9786a
cf160e1
 
 
 
2371e04
cf160e1
2371e04
cf160e1
 
 
 
 
 
3e8133b
cf160e1
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
817bde3
322183f
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
import gradio as gr
import re

import subprocess
import sys

# subprocess.check_call([sys.executable, "-m", "pip", "uninstall", 'tensorflow'])
subprocess.check_call([sys.executable, "-m", "pip", "install", 'tensorflow==2.10.0'])
subprocess.check_call([sys.executable, "-m", "pip", "install", 'tensorflow-gpu'])
# subprocess.check_call([sys.executable, "-m", "pip", "uninstall", 'transformers'])
subprocess.check_call([sys.executable, "-m", "pip", "install", 'transformers'])
subprocess.check_call([sys.executable, "-m", "pip", "install", 'keras==2.10.0'])
subprocess.check_call([sys.executable, "-m", "pip", "install", 'pytorch-pretrained-bert'])

import pytorch_pretrained_bert as ppb
assert 'bert-large-cased' in ppb.modeling.PRETRAINED_MODEL_ARCHIVE_MAP

from transformers import pipeline
  


sp_model = "JonatanGk/roberta-base-bne-finetuned-cyberbullying-spanish"
ca_model = "JonatanGk/roberta-base-ca-finetuned-cyberbullying-catalan"
sp_analysis = pipeline("text-classification", model=sp_model, tokenizer=sp_model)
ca_analysis = pipeline("text-classification", model=ca_model, tokenizer=ca_model)

def bullying_analysis(language, text):
    if language == 'Spanish':
        results = sp_analysis(text)
    elif language == 'Catalan':
        results = ca_analysis(text)
    return results[0]["label"], round(results[0]["score"], 5)


gradio_ui = gr.Interface(
    fn=bullying_analysis,
    title="CyberBullying Detector ()",
    description="Enter some text and check if the model detects bullying.",
    inputs=[
        gr.inputs.Radio(['Spanish','Catalan'],label='Language',),
        gr.inputs.Textbox(lines=5, label="Paste some text here"),
    ],
    outputs=[
        gr.outputs.Textbox(label="Label"),
        gr.outputs.Textbox(label="Score"),
    ],
    examples=[
        ['Spanish', "Eres mas alto que un pino y mas tonto que un pepino!"],
        ['Catalan', "Ets un barrufet!"],
        ['Spanish', "Estas mas gordo que una foca!"],
        ['Catalan', "Ets mes lleig que un pecat!"],
    ],
)

gradio_ui.launch()