File size: 1,230 Bytes
f96782e
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
# -*- coding: utf-8 -*-
"""untitled8.ipynb

Automatically generated by Colab.

Original file is located at
    https://colab.research.google.com/drive/1pZ2-uU-OTWgneQGeJKXCm5zVLTDUWjmL
"""

!pip install streamlit

import streamlit as st
from googletrans import Translator
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
    translator = Translator()
    try:
        translation = translator.translate(word, src='en', dest='hi')
        return translation.text
    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}")