| import streamlit as st |
| import numpy as np |
| import pandas as pd |
| import string |
| from tensorflow.keras.models import load_model |
|
|
| |
| loaded_model = load_model("Word_Correction.h5") |
|
|
| |
| data = pd.read_csv("Word_label_dict.csv") |
| dataa = pd.read_csv("OPTED-Dictionary.csv") |
|
|
| |
| 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) |
|
|
| for char in input_string: |
| if char.isupper(): |
| index = np.where(uppercase_list == char)[0] |
| if len(index) > 0: |
| lst[index[0]] += 1 |
| elif char.islower(): |
| index = np.where(lowercase_list == char)[0] |
| if len(index) > 0: |
| lst[index[0]] += 1 |
|
|
| return pred(lst) |
|
|
| def pred(array): |
| y = loaded_model.predict(np.array([array])) |
| top_classes = np.argsort(y, axis=1)[0][-3:][::-1] |
| top_probabilities = np.sort(y, axis=1)[0][-3:][::-1] |
| 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() |
|
|