Spaces:
Sleeping
Sleeping
App update for placeholder 2
Browse files
app.py
CHANGED
@@ -11,16 +11,17 @@ with open("label_types_encoded.json", "r") as fp:
|
|
11 |
genres = list(encode_genre_types.keys())
|
12 |
|
13 |
inf_session = rt.InferenceSession('news-classifier-quantized.onnx')
|
14 |
-
input_name = inf_session.get_inputs(
|
15 |
output_name = inf_session.get_outputs()[0].name
|
16 |
|
17 |
-
def classify_news_label(
|
18 |
-
input_ids = tokenizer(
|
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=4)
|
|
|
25 |
iface = gr.Interface(fn=classify_news_label, inputs="text", outputs=label)
|
26 |
iface.launch(inline=False)
|
|
|
11 |
genres = list(encode_genre_types.keys())
|
12 |
|
13 |
inf_session = rt.InferenceSession('news-classifier-quantized.onnx')
|
14 |
+
input_name = inf_session.get_inputs()[0].name
|
15 |
output_name = inf_session.get_outputs()[0].name
|
16 |
|
17 |
+
def classify_news_label(article):
|
18 |
+
input_ids = tokenizer(article)['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=4)
|
25 |
+
text_input = gr.inputs.Text(placeholder="Enter an article here") # Added placeholder
|
26 |
iface = gr.Interface(fn=classify_news_label, inputs="text", outputs=label)
|
27 |
iface.launch(inline=False)
|