File size: 646 Bytes
094951f
9fbf14c
38d4932
 
 
 
094951f
38d4932
 
 
9fbf14c
 
094951f
38d4932
 
094951f
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
from typing import Any

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)
    factor = 100 if results[0]['label'] == 'Hawkish' else -100
    return results[0]['label'], round(results[0]['score'] * factor, 0)


gr.Interface(predict_fn, "textbox", ["label", "label"]).launch()