gpucce commited on
Commit
8aaa3ed
1 Parent(s): d99519d

adding model classification

Browse files
Files changed (2) hide show
  1. app.py +21 -3
  2. tag_map.json +1 -0
app.py CHANGED
@@ -1,9 +1,27 @@
1
  import gradio as gr
 
 
2
 
 
 
3
 
4
- def greet(name):
5
- return "Hello " + name + "!!"
6
 
 
7
 
8
- iface = gr.Interface(fn=greet, inputs="text", outputs="text")
 
 
 
 
 
 
 
 
 
 
 
 
 
 
9
  iface.launch()
 
1
  import gradio as gr
2
+ from transformers import AutoModelForSequenceClassification, AutoTokenizer, AutoConfig
3
+ import json
4
 
5
+ with open("tag_map.json") as tag_map_file:
6
+ tag_map = json.load(tag_map_file)
7
 
8
+ reverse_map = {j: i for i, j in tag_map.items()}
 
9
 
10
+ model_name_or_path = "roberta-base"
11
 
12
+ config = AutoConfig.from_pretrained(model_name_or_path)
13
+ config.num_classes = len(tag_map)
14
+ model = AutoModelForSequenceClassification.from_pretrained(
15
+ model_name_or_path, config=config
16
+ )
17
+ tokenizer = AutoTokenizer.from_pretrained(model_name_or_path)
18
+
19
+
20
+ def classify(text):
21
+ return reverse_map[
22
+ model(**tokenizer(text, return_tensors="pt")).logits.argmax(-1).item()
23
+ ]
24
+
25
+
26
+ iface = gr.Interface(fn=classify, inputs="text", outputs="text")
27
  iface.launch()
tag_map.json ADDED
@@ -0,0 +1 @@
 
 
1
+ {"advantageous_effects_of_the_invention": 0, "solution_to_the_problem": 1, "technical_problem": 2, "other": 3}