File size: 2,322 Bytes
42bddec
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
import streamlit as st
from flair.data import Sentence
from flair.models import SequenceTagger

# Load the Flair model
model_path = "onurkeles/hamshetsnag-pos-tagger"
pos_tagger = SequenceTagger.load(model_path)

def tag_pos(text, detailed_output):
    """Tag parts of speech in a given text, with optional detailed output."""
    sentence = Sentence(text)
    pos_tagger.predict(sentence)

    if detailed_output:
        # Generate detailed information with tag values and probabilities
        return "\n".join(
            [f"{token.text}: {token.get_tag('pos').value} ({token.get_tag('pos').score:.2f})" for token in sentence]
        )
    else:
        # Return a simple tagged string
        return sentence.to_tagged_string()

def write():
    st.markdown("# Part-of-Speech Tagging for Hamshetsnag")
    st.sidebar.header("POS Tagging")

    st.write(
        '''Detect parts of speech in Hamshetsnag text using the fine-tuned model.'''
    )

    # Sidebar for configurations
    st.sidebar.subheader("Configurable Parameters")

    # Detailed Output Checkbox
    detailed_output = st.sidebar.checkbox(
        "Detailed Output",
        value=False,
        help="If checked, output shows detailed tag information (probability scores, etc.).",
    )

    # Input field for text
    input_text = st.text_area(label='Enter a text: ', height=100, value="Put example text here.")
    
    # Provide example sentences with translations
    example_sentences = [
        "tuute acertsetser topoldetser. aaav ta? (TR: Kâğıdı büzüştürdün attın. Oldu mu?)",
        "Baran u Baden teran. (TR: Baran ve Bade koştu.)",
        "Onurun ennush nu İremin terchushe intzi shad kızdırmısh aaav. (TR: Onur'un düşüşü ve İrem'in koşuşu beni kızdırdı.)"
    ]

    st.write("## Example Sentences:")
    for example in example_sentences:
        if st.button(f"Use: {example.split('(TR:')[0].strip()}"):
            input_text = example.split('(TR:')[0].strip()  # Update the input text directly with the Hamshetsnag part
            break  # Only use the first clicked example

    if st.button("Tag POS"):
        with st.spinner('Processing...'):
            # Tag the input text and format output as per settings
            output = tag_pos(input_text, detailed_output)
            st.success(output)