Spaces:
Build error
Build error
File size: 2,404 Bytes
8992c1a ed17812 e5e7d35 cefe2e4 ed17812 a877358 |
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 |
import streamlit as st
# Dictionary dataset (for demo purposes, you can replace this with an API or a larger dataset)
urdu_dictionary = {
"happy": {
"urdu_meaning": "خوش",
"synonyms": ["joyful", "cheerful", "content"]
},
"sad": {
"urdu_meaning": "اداس",
"synonyms": ["unhappy", "sorrowful", "melancholy"]
},
"beautiful": {
"urdu_meaning": "خوبصورت",
"synonyms": ["attractive", "lovely", "gorgeous"]
},
"strong": {
"urdu_meaning": "مضبوط",
"synonyms": ["powerful", "sturdy", "resilient"]
}
}
# Function to fetch word details
def get_word_info(word):
word = word.lower()
return urdu_dictionary.get(word, None)
# Streamlit UI
def main():
st.title("📖 English to Urdu Dictionary")
st.write("Enter an English word to get its Urdu meaning and synonyms.")
# Sidebar for additional options
with st.sidebar:
st.header("Options")
show_history = st.checkbox("Show search history", value=True)
# User input: Dropdown or text input
word_list = list(urdu_dictionary.keys())
selected_word = st.selectbox("Or select a word from the list:", word_list)
word = st.text_input("Enter an English word:", "")
# Use the selected word if no text input is provided
if not word:
word = selected_word
# Initialize session state for search history
if "search_history" not in st.session_state:
st.session_state.search_history = []
if word:
word_info = get_word_info(word)
if word_info:
st.success(f"**Urdu Meaning:** word_info('urdu_meaning')")
st.write(f"**Synonyms:** ', '.join(word_info('synonyms')")
# Update search history
if word not in st.session_state.search_history:
st.session_state.search_history.append(word)
if len(st.session_state.search_history) > 5:
st.session_state.search_history.pop(0)
else:
st.error("Word not found in the dictionary. Try another word!")
# Display search history
if show_history and st.session_state.search_history:
st.subheader("Search History")
for i, searched_word in enumerate(st.session_state.search_history[::-1], 1):
st.write(f"{i}. {searched_word}")
if __name__ == "__main__":
main() |