File size: 1,225 Bytes
684137a
 
b9e824a
684137a
 
 
b9e824a
 
 
 
 
 
 
 
684137a
b9e824a
 
 
 
0b34b06
 
 
 
 
 
 
b9e824a
c4d01d7
b9e824a
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
import gradio as gr
from sentiwordnet_calculator import SentimentPipeline

pipe = SentimentPipeline("Tanor/SRGPTSENTPOS2", "Tanor/SRGPTSENTNEG2")

def calculate(text):
    result = pipe(text)
    # Visual representation
    visual = result
    # Numerical representation
    numerical = {key: round(value, 2) for key, value in result.items()}
    # Create a formatted string
    numerical_str = ", ".join(f"{key}: {value}" for key, value in numerical.items())
    return visual, numerical_str

iface = gr.Interface(
    fn=calculate, 
    inputs=gr.inputs.Textbox(lines=5, placeholder="Enter your text here..."), 
    outputs=[gr.outputs.Label(num_top_classes=3), "text"],
    title="Sentiment Analysis for Serbian",
    description="""
    This tool performs sentiment analysis on the input text using a model trained on Serbian dictionary definitions. 
    The model was initially pretrained on the [sr-gpt2-large model by Mihailo Škorić](https://huggingface.co/JeRTeh/sr-gpt2-large), 
    then fine-tuned on selected definitions from the Serbian WordNet. Please limit the input to 300 tokens. 
    The outputs represent the Positive (POS), Negative (NEG), and Objective (OBJ) sentiment scores.
    """
)

iface.launch()