deepugaur commited on
Commit
98c8da4
·
verified ·
1 Parent(s): 5572ae7

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +7 -7
app.py CHANGED
@@ -8,9 +8,9 @@ def translate_word(word):
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"
@@ -32,7 +32,7 @@ if st.button('Translate'):
32
  st.write(f"Translation: {translation}")
33
 
34
 
35
- test_data = [
36
  {"english": "hello", "hindi": "नमस्ते"},
37
  {"english": "world", "hindi": "दुनिया"},
38
  {"english": "apple", "hindi": "सेब"},
@@ -40,11 +40,11 @@ test_data = [
40
  {"english": "computer", "hindi": "कंप्यूटर"}
41
  ]
42
 
43
- def translate_and_evaluate(test_data):
44
  correct = 0
45
- total = len(test_data)
46
 
47
- for item in test_data:
48
  translated_word = translate_word(item["english"])
49
  if translated_word == item["hindi"]:
50
  correct += 1
@@ -53,6 +53,6 @@ def translate_and_evaluate(test_data):
53
  return accuracy
54
 
55
  # Calculate accuracy
56
- accuracy = translate_and_evaluate(test_data)
57
  print(f"Accuracy: {accuracy:.2f}%")
58
 
 
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 and now_ist.minute < 60:
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"
 
32
  st.write(f"Translation: {translation}")
33
 
34
 
35
+ train_data = [
36
  {"english": "hello", "hindi": "नमस्ते"},
37
  {"english": "world", "hindi": "दुनिया"},
38
  {"english": "apple", "hindi": "सेब"},
 
40
  {"english": "computer", "hindi": "कंप्यूटर"}
41
  ]
42
 
43
+ def translate_and_evaluate(train_data):
44
  correct = 0
45
+ total = len(train_data)
46
 
47
+ for item in train_data:
48
  translated_word = translate_word(item["english"])
49
  if translated_word == item["hindi"]:
50
  correct += 1
 
53
  return accuracy
54
 
55
  # Calculate accuracy
56
+ accuracy = translate_and_evaluate(train_data)
57
  print(f"Accuracy: {accuracy:.2f}%")
58