hawk-monitor / app.py
cta2106
fixed something
f892f46
raw
history blame contribute delete
712 Bytes
from typing import Any, Tuple
from transformers import pipeline, LongformerForSequenceClassification, LongformerTokenizer, Trainer
import gradio as gr
def predict_fn(text: str) -> Tuple[Any, Any]:
model = LongformerForSequenceClassification.from_pretrained("model")
tokenizer = LongformerTokenizer.from_pretrained("allenai/longformer-base-4096")
p = pipeline("sentiment-analysis", model=model, tokenizer=tokenizer)
results = p(text, top_k=3)
WEIGHTS = {"Dovish": -100, "Neutral": 0, "Hawkish": 100}
scores = [d["score"] * WEIGHTS.get(d["label"]) for d in results]
return results[0]["label"], round(sum(scores), 0)
gr.Interface(predict_fn, "textbox", ["label", "label"]).launch()