from transformers import TextClassificationPipeline, AutoTokenizer, AutoModelForSequenceClassification from nooffense.sentence_encoder import SentenceEncoder import numpy as np import gradio as gr import os class EmbedInterface: def __init__(self): self.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" ] def clear_sentences(self): return "" def display_list(self, written_text, text_to_add): if written_text == "": new_text = text_to_add else: new_text = written_text + "\n" + text_to_add return new_text def sentiment_analysis(self, text, model_choice, text_to_compare): sentence_list = text_to_compare.split('\n') model = SentenceEncoder(self.models[model_choice]) pred = model.find_most_similar(text, sentence_list) return {p[0]:(float(p[1]) if p[1]>0 else 0) for p in pred} def __call__(self): with gr.Blocks() as embed_interface: gr.HTML("""