widget / app.py
deepugaur's picture
Update app.py
3a9379f verified
raw
history blame
1.01 kB
import streamlit as st
from deep_translator import GoogleTranslator
import datetime
def translate_word(word):
# Get current time in IST
now_utc = datetime.datetime.utcnow()
now_ist = now_utc + datetime.timedelta(hours=5, minutes=30)
# Check if current time is between 9 PM and 10 PM IST
if now_ist.hour == 21:
return "Error: Translation service unavailable between 9 PM and 10 PM IST"
# Check if word starts with a vowel
if word[0].lower() in 'aeiou':
return "Error: Words starting with vowels cannot be translated"
# Translate the word using Google Translator
try:
translation = GoogleTranslator(source='en', target='hi').translate(word)
return translation
except Exception as e:
return f"Error: {str(e)}"
# Streamlit app UI
st.title('English to Hindi Translator')
word = st.text_input('Enter a word:')
if st.button('Translate'):
translation = translate_word(word)
st.write(f"Translation: {translation}")