Spaces:
Build error
Build error
Update app.py
Browse files
app.py
CHANGED
|
@@ -1,44 +1,73 @@
|
|
| 1 |
import streamlit as st
|
| 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 |
-
st.
|
| 36 |
-
|
| 37 |
-
|
| 38 |
-
|
| 39 |
-
|
| 40 |
-
|
| 41 |
-
|
| 42 |
-
|
| 43 |
-
|
| 44 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
import streamlit as st
|
| 2 |
+
|
| 3 |
+
# Dictionary dataset (for demo purposes, you can replace this with an API or a larger dataset)
|
| 4 |
+
urdu_dictionary = {
|
| 5 |
+
"happy": {
|
| 6 |
+
"urdu_meaning": "خوش",
|
| 7 |
+
"synonyms": ["joyful", "cheerful", "content"]
|
| 8 |
+
},
|
| 9 |
+
"sad": {
|
| 10 |
+
"urdu_meaning": "اداس",
|
| 11 |
+
"synonyms": ["unhappy", "sorrowful", "melancholy"]
|
| 12 |
+
},
|
| 13 |
+
"beautiful": {
|
| 14 |
+
"urdu_meaning": "خوبصورت",
|
| 15 |
+
"synonyms": ["attractive", "lovely", "gorgeous"]
|
| 16 |
+
},
|
| 17 |
+
"strong": {
|
| 18 |
+
"urdu_meaning": "مضبوط",
|
| 19 |
+
"synonyms": ["powerful", "sturdy", "resilient"]
|
| 20 |
+
}
|
| 21 |
+
}
|
| 22 |
+
|
| 23 |
+
# Function to fetch word details
|
| 24 |
+
def get_word_info(word):
|
| 25 |
+
word = word.lower()
|
| 26 |
+
return urdu_dictionary.get(word, None)
|
| 27 |
+
|
| 28 |
+
# Streamlit UI
|
| 29 |
+
def main():
|
| 30 |
+
st.title("📖 English to Urdu Dictionary")
|
| 31 |
+
st.write("Enter an English word to get its Urdu meaning and synonyms.")
|
| 32 |
+
|
| 33 |
+
# Sidebar for additional options
|
| 34 |
+
with st.sidebar:
|
| 35 |
+
st.header("Options")
|
| 36 |
+
show_history = st.checkbox("Show search history", value=True)
|
| 37 |
+
|
| 38 |
+
# User input: Dropdown or text input
|
| 39 |
+
word_list = list(urdu_dictionary.keys())
|
| 40 |
+
selected_word = st.selectbox("Or select a word from the list:", word_list)
|
| 41 |
+
word = st.text_input("Enter an English word:", "")
|
| 42 |
+
|
| 43 |
+
# Use the selected word if no text input is provided
|
| 44 |
+
if not word:
|
| 45 |
+
word = selected_word
|
| 46 |
+
|
| 47 |
+
# Initialize session state for search history
|
| 48 |
+
if "search_history" not in st.session_state:
|
| 49 |
+
st.session_state.search_history = []
|
| 50 |
+
|
| 51 |
+
if word:
|
| 52 |
+
word_info = get_word_info(word)
|
| 53 |
+
|
| 54 |
+
if word_info:
|
| 55 |
+
st.success(f"**Urdu Meaning:** {word_info['urdu_meaning']}")
|
| 56 |
+
st.write(f"**Synonyms:** {', '.join(word_info['synonyms']}")
|
| 57 |
+
|
| 58 |
+
# Update search history
|
| 59 |
+
if word not in st.session_state.search_history:
|
| 60 |
+
st.session_state.search_history.append(word)
|
| 61 |
+
if len(st.session_state.search_history) > 5:
|
| 62 |
+
st.session_state.search_history.pop(0)
|
| 63 |
+
else:
|
| 64 |
+
st.error("Word not found in the dictionary. Try another word!")
|
| 65 |
+
|
| 66 |
+
# Display search history
|
| 67 |
+
if show_history and st.session_state.search_history:
|
| 68 |
+
st.subheader("Search History")
|
| 69 |
+
for i, searched_word in enumerate(st.session_state.search_history[::-1], 1):
|
| 70 |
+
st.write(f"{i}. {searched_word}")
|
| 71 |
+
|
| 72 |
+
if __name__ == "__main__":
|
| 73 |
+
main()
|