File size: 1,827 Bytes
cf160e1
 
6dad16b
c34d1aa
 
 
30bcf14
c54e7cb
 
30bcf14
3fec75f
c54e7cb
3fe32e4
30bcf14
 
c34d1aa
6dad16b
cf160e1
9f9786a
 
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
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.9.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.9.0'])


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 == 'English':
        results = sp_analysis(text)
    elif language == 'French':
        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()