Fahad Ebrahim commited on
Commit
122ddc4
1 Parent(s): 1505e0d

Add application file

Browse files
Files changed (2) hide show
  1. app.py +38 -0
  2. requirements.txt +2 -0
app.py ADDED
@@ -0,0 +1,38 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import gradio as gr
2
+ import re
3
+ from transformers import AutoTokenizer
4
+ from adapters import AutoAdapterModel
5
+ from transformers import TextClassificationPipeline
6
+ import gradio as gr
7
+ from transformers import pipeline
8
+
9
+ def preprocess(issue):
10
+ issue = re.sub(r'```.*?```', ' ', issue, flags=re.DOTALL)
11
+ issue = re.sub(r'\n', ' ', issue)
12
+ issue = re.sub(r'http[s]?://(?:[a-zA-Z]|[0-9]|[$-_@.&+]|[!*\\(\\),]|(?:%[0-9a-fA-F][0-9a-fA-F]))+', ' ', issue)
13
+ issue = re.sub(r'\d+', ' ', issue)
14
+ issue = re.sub(r'[^a-zA-Z0-9?\s]', ' ', issue)
15
+ issue = re.sub(r'\s+', ' ', issue)
16
+ return issue
17
+
18
+ def text_classification(text):
19
+ tokenizer = AutoTokenizer.from_pretrained("FacebookAI/roberta-base", max_length=256, truncation=True, padding="max_length")
20
+ model = AutoAdapterModel.from_pretrained("FacebookAI/roberta-base")
21
+ adapter_react = model.load_adapter("buelfhood/irc-facebook-react", source = "hf",set_active=True)
22
+ classifier = TextClassificationPipeline(model=model, tokenizer=tokenizer, max_length=256, padding="max_length", truncation=True,top_k=None)
23
+ preprocessed_issue = preprocess (issue)
24
+ out = classifier(preprocessed_issue)[0]
25
+ return out
26
+
27
+ examples=["This is a question", "This is a bug", "This is an enhancement" ]
28
+
29
+ io = gr.Interface(fn=text_classification,
30
+ inputs= gr.Textbox(lines=2, label="Text", placeholder="Enter title here..."),
31
+ outputs="label",
32
+ title="Text Classification",
33
+ description="Enter a text and see the text classification result!",
34
+ examples=examples)
35
+
36
+ io.launch()
37
+
38
+
requirements.txt ADDED
@@ -0,0 +1,2 @@
 
 
 
1
+ adapters
2
+