File size: 2,349 Bytes
fe2e7c5
 
 
 
 
 
 
435a527
fe2e7c5
 
435a527
 
fe2e7c5
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
98a9641
 
 
fe2e7c5
435a527
 
 
 
 
 
 
fe2e7c5
 
 
eff6a13
98a9641
 
 
f45e8da
435a527
 
 
49c978c
134c4b3
fe2e7c5
 
 
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
import numpy as np
import pandas as pd
import string
from tensorflow.keras.models import load_model

# Load your trained model
loaded_model = load_model("Word_Correction.h5")

# Load your data
data = pd.read_csv("Word_label_dict.csv")  # Make sure to replace "Word_label_dict.csv" with your dataset file
dataa = pd.read_csv("OPTED-Dictionary.csv")

# Create arrays for uppercase and lowercase letters
lowercase_list = np.array(list(string.ascii_lowercase))
uppercase_list = np.array(list(string.ascii_uppercase))

def mat(input_string):
    lst = np.zeros(26, dtype=int)  # Initialize a NumPy array filled with zeros

    for char in input_string:
        if char.isupper():
            index = np.where(uppercase_list == char)[0]  # Find the index of the uppercase letter
            if len(index) > 0:
                lst[index[0]] += 1
        elif char.islower():
            index = np.where(lowercase_list == char)[0]  # Find the index of the lowercase letter
            if len(index) > 0:
                lst[index[0]] += 1

    return pred(lst)

def pred(array):
    y = loaded_model.predict(np.array([array]))  # Pass array as a numpy array
    top_classes = np.argsort(y, axis=1)[0][-3:][::-1]  # Get indices of top three probabilities
    top_probabilities = np.sort(y, axis=1)[0][-3:][::-1]  # Get top three probabilities
    return top_classes, top_probabilities

def get_definition(word):
    definition = dataa[dataa['Word'] == word]['Definition'].values
    if len(definition) > 0:
        return definition[0]
    else:
        return None

def main():
    st.title("**Smart Dictionary with Auto-Correction**")
    input_text = st.text_input("Enter the Word")
    if st.button("Check"):
        top_classes, top_probabilities = mat(input_text)
        for i, (class_, probability) in enumerate(zip(top_classes, top_probabilities)):
            suggested_word = data[data.Label == class_].Word.values[0]
            if st.button(f"Suggested Word: {suggested_word}"):
                definition = get_definition(suggested_word)
                if definition:
                    st.write(f"The dictionary meaning of '{suggested_word}' is: {definition}")
                else:
                    st.write(f"No definition found for '{suggested_word}' in the dictionary.")

if __name__ == "__main__":
    main()