mmchowdhury commited on
Commit
bf5823b
·
verified ·
1 Parent(s): 8f55c3d

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +14 -11
app.py CHANGED
@@ -1,12 +1,13 @@
1
  import gradio as gr
2
  import onnxruntime as rt
3
  from transformers import AutoTokenizer
4
- import torch, json
 
5
 
6
  tokenizer = AutoTokenizer.from_pretrained("distilroberta-base")
7
 
8
  with open("tag_types_encoded(1).json", "r") as fp:
9
- encode_genre_types = json.load(fp)
10
 
11
  genres = list(encode_genre_types.keys())
12
 
@@ -15,13 +16,15 @@ input_name = inf_session.get_inputs()[0].name
15
  output_name = inf_session.get_outputs()[0].name
16
 
17
  def classify_Quote_tag(Quote):
18
- input_ids = tokenizer(Quote)['input_ids'][:512]
19
- logits = inf_session.run([output_name], {input_name: [input_ids]})[0]
20
- logits = torch.FloatTensor(logits)
21
- probs = torch.sigmoid(logits)[0]
22
- return dict(zip(genres, map(float, probs)))
23
 
24
- label = gr.outputs.Label(num_top_classes=5)
25
- iface = gr.Interface(fn=classify_Quote_tag, inputs="text", outputs=label)
26
- iface.launch(inline=False)
27
-
 
 
 
1
  import gradio as gr
2
  import onnxruntime as rt
3
  from transformers import AutoTokenizer
4
+ import torch
5
+ import json
6
 
7
  tokenizer = AutoTokenizer.from_pretrained("distilroberta-base")
8
 
9
  with open("tag_types_encoded(1).json", "r") as fp:
10
+ encode_genre_types = json.load(fp)
11
 
12
  genres = list(encode_genre_types.keys())
13
 
 
16
  output_name = inf_session.get_outputs()[0].name
17
 
18
  def classify_Quote_tag(Quote):
19
+ input_ids = tokenizer(Quote)['input_ids'][:512]
20
+ logits = inf_session.run([output_name], {input_name: [input_ids]})[0]
21
+ logits = torch.FloatTensor(logits)
22
+ probs = torch.sigmoid(logits)[0]
23
+ return dict(zip(genres, map(float, probs)))
24
 
25
+ iface = gr.Interface(
26
+ fn=classify_Quote_tag,
27
+ inputs="text",
28
+ outputs=gr.Label(num_top_classes=5) # Use gr.Label for the label output
29
+ )
30
+ iface.launch(inline=False)