eIRC / app.py
Fahad Ebrahim
Add application file
122ddc4
raw
history blame
No virus
1.65 kB
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()