cta2106 commited on
Commit
9fbf14c
·
1 Parent(s): 2463169

outputing hawkishness score

Browse files
Files changed (1) hide show
  1. app.py +6 -4
app.py CHANGED
@@ -1,14 +1,16 @@
 
 
1
  from transformers import pipeline, LongformerForSequenceClassification, LongformerTokenizer, Trainer
2
  import gradio as gr
3
 
4
 
5
- def predict_fn(text: str) -> str:
6
  model = LongformerForSequenceClassification.from_pretrained("model")
7
  tokenizer = LongformerTokenizer.from_pretrained("allenai/longformer-base-4096")
8
-
9
  p = pipeline("sentiment-analysis", model=model, tokenizer=tokenizer)
10
- return p(text)[0]["label"]
 
 
11
 
12
 
13
  gr.Interface(predict_fn, "textbox", "label").launch()
14
-
 
1
+ from typing import Any
2
+
3
  from transformers import pipeline, LongformerForSequenceClassification, LongformerTokenizer, Trainer
4
  import gradio as gr
5
 
6
 
7
+ def predict_fn(text: str) -> dict[str, Any]:
8
  model = LongformerForSequenceClassification.from_pretrained("model")
9
  tokenizer = LongformerTokenizer.from_pretrained("allenai/longformer-base-4096")
 
10
  p = pipeline("sentiment-analysis", model=model, tokenizer=tokenizer)
11
+ results = p(text)
12
+ factor = 100 if results[0]['label'] == 'Hawkish' else -100
13
+ return {"label": results[0]['label'], "hawkishness_score": round(results[0]['score'] * factor, 0)}
14
 
15
 
16
  gr.Interface(predict_fn, "textbox", "label").launch()