Omarrran commited on
Commit
f63b211
·
verified ·
1 Parent(s): 1b8e9b2

Create app.py

Browse files
Files changed (1) hide show
  1. app.py +58 -0
app.py ADDED
@@ -0,0 +1,58 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import gradio as gr
2
+ from ai4bharat.transliteration import XlitEngine
3
+
4
+ # Function for transliteration
5
+ def transliterate_to_kashmiri(user_input):
6
+ # Create an instance of the transliteration engine
7
+ e = XlitEngine(src_script_type="en", beam_width=5, rescore=False) # Adjusted beam_width for faster performance
8
+
9
+ # Perform transliteration
10
+ out = e.translit_sentence(user_input, lang_code="ks")
11
+
12
+ return out
13
+
14
+ # Examples for display in the interface
15
+ examples = [
16
+ ["Hello, how are you?", "ہیلؤ، ہاؤ آر یو؟"],
17
+ ["Good morning!", "گڈ مارننگ!"],
18
+ ["What is your name?", "تُہند ناو کِیہ چھ؟"],
19
+ ["I am feeling great today!", "آج سچِہ زبردست ہوں!"],
20
+ ["See you later!", "بَعِد چُھٹ چھُ؟"]
21
+ ]
22
+
23
+ # Set up the Gradio interface
24
+ with gr.Blocks() as demo:
25
+ gr.Markdown("""
26
+ # English to Kashmiri Transliteration
27
+ This tool allows you to convert English sentences into Kashmiri transliterations.
28
+
29
+ **How to use:**
30
+ 1. Enter a sentence in English in the text box.
31
+ 2. Click "Transliterate" to see the Kashmiri output.
32
+
33
+ ### Example Sentences:
34
+ """)
35
+
36
+ # Display the examples
37
+ for example in examples:
38
+ gr.Markdown(f"**English:** {example[0]}\n\n**Kashmiri Transliteration:** {example[1]}")
39
+
40
+ gr.Markdown("### Enter your own sentence:")
41
+
42
+ # Create input field for user sentence
43
+ user_input = gr.Textbox(label="Enter the sentence in English:", placeholder="e.g., Hello, how are you?")
44
+
45
+ # Output area for transliterated text
46
+ transliterated_output = gr.Textbox(label="Transliterated Output (Kashmiri):", placeholder="Result will be shown here")
47
+
48
+ # Button to trigger the transliteration
49
+ submit_button = gr.Button("Transliterate")
50
+
51
+ # Define the button action
52
+ submit_button.click(fn=transliterate_to_kashmiri, inputs=user_input, outputs=transliterated_output)
53
+
54
+ # Add examples to the interface for easy testing
55
+ gr.Examples(examples=examples, inputs=user_input, outputs=transliterated_output)
56
+
57
+ # Launch the Gradio interface
58
+ demo.launch(share=True, inbrowser=True, theme="huggingface")