CoolFace
Apppublic

Raghavendra0827/Smart_Dictionary_with_Auto_Correction

sourceHugging Faceapache-2.0updated 2y agoView on Hugging Face
1likes
app.py62 linesDownload Raw Back to root
1import streamlit as st2import numpy as np3import pandas as pd4import string5from tensorflow.keras.models import load_model6 7# Load your trained model8loaded_model = load_model("Word_Correction.h5")9 10# Load your data11data = pd.read_csv("Word_label_dict.csv")  # Make sure to replace "Word_label_dict.csv" with your dataset file12dataa = pd.read_csv("OPTED-Dictionary.csv")13 14# Create arrays for uppercase and lowercase letters15lowercase_list = np.array(list(string.ascii_lowercase))16uppercase_list = np.array(list(string.ascii_uppercase))17 18def mat(input_string):19    lst = np.zeros(26, dtype=int)  # Initialize a NumPy array filled with zeros20 21    for char in input_string:22        if char.isupper():23            index = np.where(uppercase_list == char)[0]  # Find the index of the uppercase letter24            if len(index) > 0:25                lst[index[0]] += 126        elif char.islower():27            index = np.where(lowercase_list == char)[0]  # Find the index of the lowercase letter28            if len(index) > 0:29                lst[index[0]] += 130 31    return pred(lst)32 33def pred(array):34    y = loaded_model.predict(np.array([array]))  # Pass array as a numpy array35    top_classes = np.argsort(y, axis=1)[0][-3:][::-1]  # Get indices of top three probabilities36    top_probabilities = np.sort(y, axis=1)[0][-3:][::-1]  # Get top three probabilities37    return top_classes, top_probabilities38 39def get_definition(word):40    definition = dataa[dataa['Word'] == word]['Definition'].values41    if len(definition) > 0:42        return definition[0]43    else:44        return None45 46def main():47    st.title("**Smart Dictionary with Auto-Correction**")48    input_text = st.text_input("Enter the Word")49    if st.button("Check"):50        top_classes, top_probabilities = mat(input_text)51        for i, (class_, probability) in enumerate(zip(top_classes, top_probabilities)):52            suggested_word = data[data.Label == class_].Word.values[0]53            if st.button(f"Suggested Word: {suggested_word}"):54                definition = get_definition(suggested_word)55                if definition:56                    st.write(f"The dictionary meaning of '{suggested_word}' is: {definition}")57                else:58                    st.write(f"No definition found for '{suggested_word}' in the dictionary.")59 60if __name__ == "__main__":61    main()62