JHigg commited on
Commit
727f4c6
·
verified ·
1 Parent(s): 8365f69

Create translator.py

Browse files
Files changed (1) hide show
  1. translator.py +20 -0
translator.py ADDED
@@ -0,0 +1,20 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import gradio as gr
2
+
3
+ # Function to translate a word into Pig Latin
4
+ def to_pig_latin(word):
5
+ # If the word starts with a vowel, add 'way' to the end
6
+ if word[0].lower() in 'aeiou':
7
+ return word + "way"
8
+ # Otherwise, move the first consonant cluster to the end, then add 'ay'
9
+ else:
10
+ first_vowel = next((i for i, char in enumerate(word) if char.lower() in 'aeiou'), len(word))
11
+ return word[first_vowel:] + word[:first_vowel] + "ay"
12
+
13
+ # Function to translate a sentence into Pig Latin
14
+ def translate_text(text):
15
+ words = text.split()
16
+ pig_latin_words = [to_pig_latin(word) for word in words]
17
+ return ' '.join(pig_latin_words)
18
+
19
+ # Set up Gradio interface
20
+ gr.Interface(fn=translate_text, inputs="text", outputs="text", title="Pig Latin Translator").launch()