Delete untitled8.py
Browse files- untitled8.py +0 -45
untitled8.py
DELETED
|
@@ -1,45 +0,0 @@
|
|
| 1 |
-
# -*- coding: utf-8 -*-
|
| 2 |
-
"""untitled8.ipynb
|
| 3 |
-
|
| 4 |
-
Automatically generated by Colab.
|
| 5 |
-
|
| 6 |
-
Original file is located at
|
| 7 |
-
https://colab.research.google.com/drive/1pZ2-uU-OTWgneQGeJKXCm5zVLTDUWjmL
|
| 8 |
-
"""
|
| 9 |
-
|
| 10 |
-
!pip install streamlit
|
| 11 |
-
|
| 12 |
-
import streamlit as st
|
| 13 |
-
from googletrans import Translator
|
| 14 |
-
import datetime
|
| 15 |
-
|
| 16 |
-
def translate_word(word):
|
| 17 |
-
# Get current time in IST
|
| 18 |
-
now_utc = datetime.datetime.utcnow()
|
| 19 |
-
now_ist = now_utc + datetime.timedelta(hours=5, minutes=30)
|
| 20 |
-
|
| 21 |
-
# Check if current time is between 9 PM and 10 PM IST
|
| 22 |
-
if now_ist.hour == 21:
|
| 23 |
-
return "Error: Translation service unavailable between 9 PM and 10 PM IST"
|
| 24 |
-
|
| 25 |
-
# Check if word starts with a vowel
|
| 26 |
-
if word[0].lower() in 'aeiou':
|
| 27 |
-
return "Error: Words starting with vowels cannot be translated"
|
| 28 |
-
|
| 29 |
-
# Translate the word using Google Translator
|
| 30 |
-
translator = Translator()
|
| 31 |
-
try:
|
| 32 |
-
translation = translator.translate(word, src='en', dest='hi')
|
| 33 |
-
return translation.text
|
| 34 |
-
except Exception as e:
|
| 35 |
-
return f"Error: {str(e)}"
|
| 36 |
-
|
| 37 |
-
# Streamlit app UI
|
| 38 |
-
st.title('English to Hindi Translator')
|
| 39 |
-
|
| 40 |
-
word = st.text_input('Enter a word:')
|
| 41 |
-
|
| 42 |
-
if st.button('Translate'):
|
| 43 |
-
translation = translate_word(word)
|
| 44 |
-
st.write(f"Translation: {translation}")
|
| 45 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|