Create app.py
Browse files
app.py
ADDED
@@ -0,0 +1,33 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
import streamlit as st
|
2 |
+
from googletrans import Translator
|
3 |
+
import datetime
|
4 |
+
|
5 |
+
def translate_word(word):
|
6 |
+
# Get current time in IST
|
7 |
+
now_utc = datetime.datetime.utcnow()
|
8 |
+
now_ist = now_utc + datetime.timedelta(hours=5, minutes=30)
|
9 |
+
|
10 |
+
# Check if current time is between 9 PM and 10 PM IST
|
11 |
+
if now_ist.hour == 21:
|
12 |
+
return "Error: Translation service unavailable between 9 PM and 10 PM IST"
|
13 |
+
|
14 |
+
# Check if word starts with a vowel
|
15 |
+
if word[0].lower() in 'aeiou':
|
16 |
+
return "Error: Words starting with vowels cannot be translated"
|
17 |
+
|
18 |
+
# Translate the word using Google Translator
|
19 |
+
translator = Translator()
|
20 |
+
try:
|
21 |
+
translation = translator.translate(word, src='en', dest='hi')
|
22 |
+
return translation.text
|
23 |
+
except Exception as e:
|
24 |
+
return f"Error: {str(e)}"
|
25 |
+
|
26 |
+
# Streamlit app UI
|
27 |
+
st.title('English to Hindi Translator')
|
28 |
+
|
29 |
+
word = st.text_input('Enter a word:')
|
30 |
+
|
31 |
+
if st.button('Translate'):
|
32 |
+
translation = translate_word(word)
|
33 |
+
st.write(f"Translation: {translation}")
|