Spaces:
Runtime error
Runtime error
File size: 2,800 Bytes
5f1da2d 52f8887 5f1da2d 4dadc70 5f1da2d 52f8887 4dadc70 5f1da2d 4dadc70 5f1da2d |
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 56 57 |
from transformers import TextClassificationPipeline, AutoTokenizer, AutoModelForSequenceClassification
import gradio as gr
import os
models = [
"Overfit-GM/bert-base-turkish-cased-offensive",
"Overfit-GM/bert-base-turkish-uncased-offensive",
"Overfit-GM/bert-base-turkish-128k-cased-offensive",
"Overfit-GM/bert-base-turkish-128k-uncased-offensive",
"Overfit-GM/convbert-base-turkish-mc4-cased-offensive",
"Overfit-GM/convbert-base-turkish-mc4-uncased-offensive",
"Overfit-GM/convbert-base-turkish-cased-offensive",
"Overfit-GM/distilbert-base-turkish-cased-offensive",
"Overfit-GM/electra-base-turkish-cased-discriminator-offensive",
"Overfit-GM/electra-base-turkish-mc4-cased-discriminator-offensive",
"Overfit-GM/electra-base-turkish-mc4-uncased-discriminator-offensive",
"Overfit-GM/xlm-roberta-large-turkish-offensive",
"Overfit-GM/mdeberta-v3-base-offensive"
]
model_box=[
gr.load(models[0], src='models', hf_token=os.environ['API_KEY']),
gr.load(models[1], src='models', hf_token=os.environ['API_KEY']),
gr.load(models[2], src='models', hf_token=os.environ['API_KEY']),
gr.load(models[3], src='models', hf_token=os.environ['API_KEY']),
gr.load(models[4], src='models', hf_token=os.environ['API_KEY']),
gr.load(models[5], src='models', hf_token=os.environ['API_KEY']),
gr.load(models[6], src='models', hf_token=os.environ['API_KEY']),
gr.load(models[7], src='models', hf_token=os.environ['API_KEY']),
gr.load(models[8], src='models', hf_token=os.environ['API_KEY']),
gr.load(models[9], src='models', hf_token=os.environ['API_KEY']),
gr.load(models[10], src='models', hf_token=os.environ['API_KEY']),
gr.load(models[11], src='models', hf_token=os.environ['API_KEY']),
gr.load(models[12], src='models', hf_token=os.environ['API_KEY'])
]
def sentiment_analysis(text, model_choice):
model = model_box[model_choice]
output = model(text)
return output
with gr.Blocks() as demo:
gr.HTML("""<h1 style="font-weight:600;font-size:50;margin-top:4px;margin-bottom:4px;text-align:center;">No Offense Classifier</h1></div>""")
with gr.Row():
with gr.Column():
model_choice = gr.Dropdown(label="Select Model", choices=[m for m in models], type="index", interactive=True)
input_text = gr.Textbox(label="Input", placeholder="senin ben amk")
the_button = gr.Button(label="Run")
with gr.Column():
output_window = gr.Label(num_top_classes=5)
the_button.click(sentiment_analysis, inputs=[input_text, model_choice], outputs=[output_window])
examples = gr.Examples(examples=["bu adamların ülkesine dönmesi lazım", "adam olsan oraya gitmezdin"],
inputs=[input_text])
demo.launch() |