from transformers import TextClassificationPipeline, AutoTokenizer, AutoModelForSequenceClassification import gradio as gr # def get_model(model_name='Overfit-GM/temp_dist'): # id2label = {0: 'INSULT', 1: 'OTHER', # 2: 'PROFANITY', 3: 'RACIST', 4: 'SEXIST'} # label2id = {v: k for k, v in id2label.items()} # tokenizer = AutoTokenizer.from_pretrained(model_name) # model = AutoModelForSequenceClassification.from_pretrained(model_name, # problem_type="single_label_classification", # id2label=id2label, # label2id=label2id, # num_labels=5, # output_hidden_states=False, # ) # return model, tokenizer models = [ "Overfit-GM/temp_dist", "deprem-ml/deprem_bert_128k" ] model_box=[ gr.load(models[0], src='models'), gr.load(models[1], src='models'), ] def sentiment_analysis(text, model_choice): a_variable = model_box[model_choice] output = a_variable(text) return output with gr.Blocks() as demo: gr.HTML("""

No Offense Classifier

""") 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()