ankitklakra commited on
Commit
4c58b5c
·
verified ·
1 Parent(s): b27e854

Create app.py

Browse files
Files changed (1) hide show
  1. app.py +85 -0
app.py ADDED
@@ -0,0 +1,85 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import gradio as gr
2
+ from transformers import pipeline
3
+
4
+ # --- CONFIGURATION ---
5
+
6
+ MODEL_K2H = "ankitklakra/kurukh-to-hindi"
7
+ MODEL_H2K = "ankitklakra/hindi-to-kurukh"
8
+
9
+ # --- LOAD MODELS ---
10
+
11
+ print("Loading Kurukh -> Hindi Model...")
12
+ pipe_k2h = pipeline("text2text-generation", model=MODEL_K2H)
13
+
14
+ print("Loading Hindi -> Kurukh Model...")
15
+ pipe_h2k = pipeline("text2text-generation", model=MODEL_H2K)
16
+
17
+ # --- TRANSLATION FUNCTION ---
18
+ def translate_text(text, direction):
19
+ if not text:
20
+ return ""
21
+
22
+ # Select the correct brain based on user choice
23
+ if direction == "Kurukh -> Hindi":
24
+ target_pipeline = pipe_k2h
25
+ else:
26
+ target_pipeline = pipe_h2k
27
+
28
+ # Translate
29
+ # max_length=128 allow for longer sentences
30
+ results = target_pipeline(text, max_length=128)
31
+ return results[0]['generated_text']
32
+
33
+ # --- THE USER INTERFACE ---
34
+ with gr.Blocks(theme=gr.themes.Soft()) as demo:
35
+
36
+ # Header
37
+ gr.Markdown(
38
+ """
39
+ # 🇮🇳 AI Kurukh (Kurux) Translator
40
+ ### Preserving Tribal Languages with Artificial Intelligence
41
+ *Powered by Custom Fine-Tuned Google mT5 Models*
42
+ """
43
+ )
44
+
45
+ # Input Section
46
+ with gr.Row():
47
+ direction = gr.Radio(
48
+ ["Kurukh -> Hindi", "Hindi -> Kurukh"],
49
+ label="Translation Mode",
50
+ value="Kurukh -> Hindi"
51
+ )
52
+
53
+ with gr.Row():
54
+ with gr.Column():
55
+ input_text = gr.Textbox(
56
+ label="Input Text",
57
+ placeholder="Type your sentence here...",
58
+ lines=5
59
+ )
60
+ translate_btn = gr.Button("Translate 🚀", variant="primary")
61
+
62
+ with gr.Column():
63
+ output_text = gr.Textbox(
64
+ label="Translation Result",
65
+ lines=5,
66
+ show_copy_button=True # Allows users to copy result
67
+ )
68
+
69
+ # Examples to help new users
70
+ gr.Examples(
71
+ examples=[
72
+ ["निघै नामे इन्द्रा हिकै?", "Kurukh -> Hindi"],
73
+ ["इन्गे अम्मो चि'आ।", "Kurukh -> Hindi"],
74
+ ["तुम्हारा नाम क्या है?", "Hindi -> Kurukh"],
75
+ ["मुझे पानी दो।", "Hindi -> Kurukh"]
76
+ ],
77
+ inputs=[input_text, direction],
78
+ label="Click on an example to test:"
79
+ )
80
+
81
+ # Logic Connection
82
+ translate_btn.click(fn=translate_text, inputs=[input_text, direction], outputs=output_text)
83
+
84
+ # Launch
85
+ demo.launch()