File size: 1,651 Bytes
122ddc4 |
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 |
import gradio as gr
import re
from transformers import AutoTokenizer
from adapters import AutoAdapterModel
from transformers import TextClassificationPipeline
import gradio as gr
from transformers import pipeline
def preprocess(issue):
issue = re.sub(r'```.*?```', ' ', issue, flags=re.DOTALL)
issue = re.sub(r'\n', ' ', issue)
issue = re.sub(r'http[s]?://(?:[a-zA-Z]|[0-9]|[$-_@.&+]|[!*\\(\\),]|(?:%[0-9a-fA-F][0-9a-fA-F]))+', ' ', issue)
issue = re.sub(r'\d+', ' ', issue)
issue = re.sub(r'[^a-zA-Z0-9?\s]', ' ', issue)
issue = re.sub(r'\s+', ' ', issue)
return issue
def text_classification(text):
tokenizer = AutoTokenizer.from_pretrained("FacebookAI/roberta-base", max_length=256, truncation=True, padding="max_length")
model = AutoAdapterModel.from_pretrained("FacebookAI/roberta-base")
adapter_react = model.load_adapter("buelfhood/irc-facebook-react", source = "hf",set_active=True)
classifier = TextClassificationPipeline(model=model, tokenizer=tokenizer, max_length=256, padding="max_length", truncation=True,top_k=None)
preprocessed_issue = preprocess (issue)
out = classifier(preprocessed_issue)[0]
return out
examples=["This is a question", "This is a bug", "This is an enhancement" ]
io = gr.Interface(fn=text_classification,
inputs= gr.Textbox(lines=2, label="Text", placeholder="Enter title here..."),
outputs="label",
title="Text Classification",
description="Enter a text and see the text classification result!",
examples=examples)
io.launch()
|