Spaces:
Build error
Build error
Create app.py
Browse files
app.py
ADDED
|
@@ -0,0 +1,44 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import streamlit as st
|
| 2 |
+
from PyDictionary import PyDictionary
|
| 3 |
+
import requests
|
| 4 |
+
|
| 5 |
+
# Function to get Urdu meaning using an API
|
| 6 |
+
def get_urdu_meaning(word):
|
| 7 |
+
url = f"https://api.dictionaryapi.dev/api/v2/entries/en/{word}"
|
| 8 |
+
try:
|
| 9 |
+
response = requests.get(url)
|
| 10 |
+
data = response.json()
|
| 11 |
+
meanings = data[0]['meanings'][0]['definitions'][0]['definition']
|
| 12 |
+
return meanings
|
| 13 |
+
except:
|
| 14 |
+
return "Meaning not found in Urdu."
|
| 15 |
+
|
| 16 |
+
# Create Streamlit UI
|
| 17 |
+
st.title("Dictionary App")
|
| 18 |
+
st.write("This app provides synonyms, antonyms, and Urdu meanings for words.")
|
| 19 |
+
|
| 20 |
+
# Input field for the word
|
| 21 |
+
word = st.text_input("Enter a word:")
|
| 22 |
+
|
| 23 |
+
if word:
|
| 24 |
+
dictionary = PyDictionary()
|
| 25 |
+
|
| 26 |
+
# Synonyms and Antonyms
|
| 27 |
+
synonyms = dictionary.synonym(word)
|
| 28 |
+
antonyms = dictionary.antonym(word)
|
| 29 |
+
|
| 30 |
+
# Urdu Meaning
|
| 31 |
+
urdu_meaning = get_urdu_meaning(word)
|
| 32 |
+
|
| 33 |
+
# Display results
|
| 34 |
+
if synonyms:
|
| 35 |
+
st.write(f"**Synonyms:** {', '.join(synonyms)}")
|
| 36 |
+
else:
|
| 37 |
+
st.write("No synonyms found.")
|
| 38 |
+
|
| 39 |
+
if antonyms:
|
| 40 |
+
st.write(f"**Antonyms:** {', '.join(antonyms)}")
|
| 41 |
+
else:
|
| 42 |
+
st.write("No antonyms found.")
|
| 43 |
+
|
| 44 |
+
st.write(f"**Urdu Meaning:** {urdu_meaning}")
|