File size: 1,634 Bytes
3d023d8
3a9379f
3d023d8
 
 
 
 
 
 
 
 
8c0610d
f151e95
8c0610d
 
3d023d8
 
 
3a9379f
 
3d023d8
 
 
 
 
 
 
 
 
 
 
3a9379f
5572ae7
98c8da4
5572ae7
 
 
 
 
 
 
98c8da4
5572ae7
98c8da4
5572ae7
98c8da4
5572ae7
 
 
 
 
 
 
 
98c8da4
5572ae7
 
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
47
48
49
50
51
52
53
54
55
56
57
58
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 word starts with a vowel
    if word[0].lower() in 'aeiou':
        if now_ist.hour == 21 and now_ist.minute < 60:

            return "Error: Words starting with vowels cannot be translated between 9 PM and 10 PM IST"
    
    
    # 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}")


train_data = [
    {"english": "hello", "hindi": "नमस्ते"},
    {"english": "world", "hindi": "दुनिया"},
    {"english": "apple", "hindi": "सेब"},
    {"english": "book", "hindi": "किताब"},
    {"english": "computer", "hindi": "कंप्यूटर"}
]

def translate_and_evaluate(train_data):
    correct = 0
    total = len(train_data)

    for item in train_data:
        translated_word = translate_word(item["english"])
        if translated_word == item["hindi"]:
            correct += 1

    accuracy = (correct / total) * 100
    return accuracy

# Calculate accuracy
accuracy = translate_and_evaluate(train_data)
print(f"Accuracy: {accuracy:.2f}%")