File size: 3,370 Bytes
1ddad36
 
 
1c9f431
a28390b
1ddad36
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
a28390b
1ddad36
 
 
 
 
 
 
 
 
 
 
 
1c9f431
 
1ddad36
a28390b
1ddad36
 
1c9f431
 
1ddad36
002c6cb
1c9f431
1ddad36
 
 
 
 
 
 
1c9f431
1ddad36
002c6cb
 
 
 
1c9f431
 
 
 
002c6cb
1c9f431
002c6cb
 
 
 
1ddad36
 
 
 
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
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
import streamlit as st
import pandas as pd


from api.ModelMethods import generate


st.set_page_config(page_title="DEMO", page_icon="👋", layout="wide")


# Make basic configuration for the app
appTitle = "Nepali Spell Correction"


# Some test examples here
example = (
    "अबको स्थायी कमिटी ओली सरकारलाई दीएको समर्थन फिर्ताको तयारि रहेको साहले जानकारी दिए।"
)
examples = {
    "Examples": "",
    "अखिलेस झा धेरै दिनदेखि अनुपस्थीत थिए ।": "अखिलेस झा धेरै दिनदेखि अनुपस्थीत थिए ।",
    "आठौँ तह उपनिर्देषक पदमा दुई जना उत्तीर्ण भएका छन्।": "आठौँ तह उपनिर्देषक पदमा दुई जना उत्तीर्ण भएका छन्।",
    "उनीहरूमा रोगसँग लड्ने क्षमता मज्जाले बिकसित भइसकेको हुँदैन।": "उनीहरूमा रोगसँग लड्ने क्षमता मज्जाले बिकसित भइसकेको हुँदैन।",
}


def main():

    st.header(appTitle)
    left_column, right_column = st.columns(2)
    correctedText = None

    with left_column:
        model_options = {"mT5", "mBART", "VartaT5"}

        # Display the radio options in a single line
        selected_model = st.radio("Select the model", model_options, index=0)

        # Create a dropdown menu
        selected_example_key = st.selectbox("Select an example", list(examples.keys()))
        # Display the selected example text in a text area
        selected_example_text = examples[selected_example_key]

        # Paragraph selection

        # Get user input
        user_input = st.text_area("Enter a Nepali Sentence: ", selected_example_text)
        if st.button("Check Spelling"):
            if user_input:

                # user_input = check_and_insert_space(user_input)
                correctedText = generate(selected_model, user_input)
                # correctedText = {0: "मेरो देस नेपाल हो।", 1: "मेरो देश नेपाल हो।"}
                # correctedText = correctedText[0]["sequence"]
                # # Perfrom grammer correction
                # st.subheader("Corrected Text:")
                # st.write([f"{line['score']:.2f}: {line['sequence']}"for line in correctedText])
            else:
                st.warning("Please enter some text to check.")
    with right_column:
        if correctedText is not None:

            # st.write([f"{line['score']:.2f}: {line['sequence']}" for line in correctedText])

            # df = pd.DataFrame(correctedText, columns=["score", "sequence"])

            # Analyze the input and output
            if "span" in correctedText:
                st.write("Corrected Text:")
            else:
                st.write("No errors found:")
            st.write(
                correctedText,
                unsafe_allow_html=True,
            )

            # st.table(df)


if __name__ == "__main__":
    main()