ankitklakra commited on
Commit
45b101e
ยท
verified ยท
1 Parent(s): b3221cd

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +47 -118
app.py CHANGED
@@ -93,161 +93,91 @@ def process_translation(text, audio_input, direction, is_hinglish):
93
 
94
  return original_text, translated_text, audio_output
95
 
96
- # --- CUSTOM CSS ---
97
 
98
  custom_css = """
99
- /* Import a nice font (Poppins) */
100
  @import url('https://fonts.googleapis.com/css2?family=Poppins:wght@300;400;600&display=swap');
101
-
102
- /* Apply font to everything */
103
- body, button, input, select, textarea, .gradio-container {
104
- font-family: 'Poppins', sans-serif !important;
105
- }
106
-
107
- /* Header Styling */
108
- .header-title {
109
- text-align: center;
110
- color: #2c3e50;
111
- margin-bottom: 0.5rem;
112
- font-size: 2.2em;
113
- font-weight: 600;
114
- }
115
- .header-subtitle {
116
- text-align: center;
117
- color: #7f8c8d;
118
- margin-bottom: 2rem;
119
- font-weight: 300;
120
- font-size: 1.1em;
121
- }
122
-
123
- /* Card Container Styling */
124
- .input-container, .output-container {
125
- background: #ffffff;
126
- border: 1px solid #e0e0e0;
127
- border-radius: 12px;
128
- padding: 25px;
129
- box-shadow: 0 4px 6px rgba(0,0,0,0.05);
130
- margin-bottom: 20px;
131
- }
132
-
133
- /* Button Styling */
134
- #translate-btn {
135
- background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
136
- border: none;
137
- color: white;
138
- font-weight: 600;
139
- font-size: 1.1em;
140
- padding: 10px 20px;
141
- border-radius: 8px;
142
- transition: transform 0.1s;
143
- }
144
- #translate-btn:hover {
145
- transform: scale(1.02);
146
- box-shadow: 0 5px 15px rgba(0,0,0,0.2);
147
- }
148
-
149
- /* Feedback Section */
150
- .feedback-box {
151
- background-color: #f8f9fa;
152
- border-radius: 8px;
153
- padding: 20px;
154
- border-left: 5px solid #ffc107;
155
- }
156
  """
157
 
158
  # --- THE UI ---
159
- with gr.Blocks(css=custom_css, title="Kurukh AI Translator") as demo:
 
160
 
161
- # HEADER SECTION
162
- with gr.Row():
163
- with gr.Column():
164
- gr.Markdown("# ๐Ÿ‡ฎ๐Ÿ‡ณ AI Kurukh (Oraon) Translator", elem_classes=["header-title"])
165
- gr.Markdown("### Bridging Communities with Artificial Intelligence | Voice & Hinglish Supported", elem_classes=["header-subtitle"])
 
 
 
 
 
166
 
167
- # TABS FOR NAVIGATION
168
  with gr.Tabs():
169
 
170
- # --- TAB 1: TRANSLATOR INTERFACE ---
171
  with gr.TabItem("๐Ÿ—ฃ๏ธ Translator"):
172
 
173
- # Help / Instructions (Collapsible)
174
  with gr.Accordion("โ„น๏ธ How to use (Click to expand)", open=False):
175
  gr.Markdown("""
176
- 1. **Select Mode:** Choose translation direction (Kurukh -> Hindi OR Hindi -> Kurukh).
177
- 2. **Hinglish Support:** Check the box if you are typing Hindi words using English letters (e.g., 'Tumhara naam kya hai').
178
- 3. **Input Methods:** Type text in the box OR click the microphone to speak (Hindi audio supported).
179
- 4. **Results:** View the translation and listen to the audio output (for Hindi results).
180
  """)
181
 
182
- # Main Grid Layout
183
  with gr.Row():
184
- # LEFT COLUMN (INPUT CARD)
185
- with gr.Column(elem_classes=["input-container"]):
186
  gr.Markdown("### ๐Ÿ“ฅ Input Source")
187
 
188
  with gr.Row():
189
- direction = gr.Radio(
190
- ["Kurukh -> Hindi", "Hindi -> Kurukh"],
191
- label="Translation Mode",
192
- value="Kurukh -> Hindi"
193
- )
194
 
195
  is_hinglish = gr.Checkbox(label="๐Ÿ”ค Hinglish Typing (e.g. 'Tumhara')", value=False)
196
 
197
- input_text = gr.Textbox(
198
- label="Enter Text",
199
- placeholder="Type sentences here...",
200
- lines=4,
201
- show_label=False
202
- )
203
 
204
- input_audio = gr.Audio(
205
- sources=["microphone"],
206
- type="filepath",
207
- label="๐ŸŽ™๏ธ Voice Input (Hindi Only)"
208
- )
209
-
210
- translate_btn = gr.Button("Translate ๐Ÿš€", variant="primary", elem_id="translate-btn")
211
 
212
- # RIGHT COLUMN (OUTPUT CARD)
213
- with gr.Column(elem_classes=["output-container"]):
214
  gr.Markdown("### ๐Ÿ“ค Translation Result")
215
-
216
- output_text = gr.Textbox(
217
- label="Translation",
218
- lines=4,
219
- show_label=False,
220
- interactive=False,
221
- show_copy_button=True
222
- )
223
-
224
- output_audio = gr.Audio(
225
- label="๐Ÿ”Š Listen (Hindi Only)",
226
- interactive=False,
227
- autoplay=False
228
- )
229
 
230
- # Connect Logic
231
  translate_btn.click(
232
  fn=process_translation,
233
  inputs=[input_text, input_audio, direction, is_hinglish],
234
  outputs=[input_text, output_text, output_audio]
235
  )
236
 
237
- # --- TAB 2: FEEDBACK INTERFACE ---
238
  with gr.TabItem("๐Ÿ“ Improve the AI"):
239
- with gr.Column(elem_classes=["feedback-box"]):
240
- gr.Markdown("### ๐Ÿ› ๏ธ Help us improve accuracy")
241
- gr.Markdown("Our AI is still learning! If you spot a mistake, please submit the correct translation below. This helps us train better versions.")
242
-
 
243
  with gr.Row():
244
  fb_direction = gr.Radio(["Kurukh -> Hindi", "Hindi -> Kurukh"], label="Direction", value="Kurukh -> Hindi")
245
 
246
  with gr.Row():
247
- fb_original = gr.Textbox(label="Original Text", placeholder="The sentence you tried to translate")
248
- fb_ai_output = gr.Textbox(label="AI's Wrong Translation (Optional)")
249
 
250
- fb_user_correct = gr.Textbox(label="โœ… Your Correct Translation", lines=2, placeholder="Type the correct Kurukh/Hindi translation here")
251
 
252
  submit_btn = gr.Button("Submit Correction to Database", variant="secondary")
253
  status_lbl = gr.Label(label="Status")
@@ -258,8 +188,7 @@ with gr.Blocks(css=custom_css, title="Kurukh AI Translator") as demo:
258
  outputs=status_lbl
259
  )
260
 
261
- # FOOTER
262
  gr.Markdown("---")
263
- gr.Markdown("<center>Built with โค๏ธ for the Kurukh Community โ€ข Powered by Google mT5 & OpenAI Whisper</center>")
264
 
265
  demo.launch()
 
93
 
94
  return original_text, translated_text, audio_output
95
 
96
+ # --- CUSTOM CSS ---
97
 
98
  custom_css = """
99
+ <style>
100
  @import url('https://fonts.googleapis.com/css2?family=Poppins:wght@300;400;600&display=swap');
101
+ body, button, input, select, textarea, .gradio-container { font-family: 'Poppins', sans-serif !important; }
102
+ .header-div { text-align: center; margin-bottom: 20px; }
103
+ .header-title { font-size: 2.5em; font-weight: 600; color: #2c3e50; margin: 0; }
104
+ .header-subtitle { font-size: 1.2em; color: #7f8c8d; font-weight: 300; margin-top: 5px; }
105
+ .input-box, .output-box { border: 1px solid #e0e0e0; border-radius: 12px; padding: 20px; background: white; box-shadow: 0 4px 6px rgba(0,0,0,0.05); }
106
+ .primary-btn { background: linear-gradient(135deg, #667eea 0%, #764ba2 100%) !important; color: white !important; font-weight: bold; border-radius: 8px; }
107
+ .feedback-area { background-color: #f9f9f9; border-left: 5px solid #f1c40f; padding: 15px; border-radius: 5px; }
108
+ </style>
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
109
  """
110
 
111
  # --- THE UI ---
112
+
113
+ with gr.Blocks(title="Kurukh AI Translator") as demo:
114
 
115
+ # INJECT CSS MANUALLY
116
+ gr.HTML(custom_css)
117
+
118
+ # HEADER (Using HTML for better styling control)
119
+ gr.HTML("""
120
+ <div class="header-div">
121
+ <h1 class="header-title">๐Ÿ‡ฎ๐Ÿ‡ณ AI Kurukh (Oraon) Translator</h1>
122
+ <p class="header-subtitle">Bridging Communities with Artificial Intelligence | Voice & Hinglish Supported</p>
123
+ </div>
124
+ """)
125
 
 
126
  with gr.Tabs():
127
 
128
+ # --- TAB 1: TRANSLATOR ---
129
  with gr.TabItem("๐Ÿ—ฃ๏ธ Translator"):
130
 
 
131
  with gr.Accordion("โ„น๏ธ How to use (Click to expand)", open=False):
132
  gr.Markdown("""
133
+ 1. **Select Mode:** Kurukh -> Hindi OR Hindi -> Kurukh.
134
+ 2. **Hinglish:** Check the box if you type Hindi in English (e.g., 'Tumhara').
135
+ 3. **Voice:** Click the microphone to speak (Hindi only).
 
136
  """)
137
 
 
138
  with gr.Row():
139
+ # LEFT COLUMN
140
+ with gr.Column():
141
  gr.Markdown("### ๐Ÿ“ฅ Input Source")
142
 
143
  with gr.Row():
144
+ direction = gr.Radio(["Kurukh -> Hindi", "Hindi -> Kurukh"], label="Translation Mode", value="Kurukh -> Hindi")
 
 
 
 
145
 
146
  is_hinglish = gr.Checkbox(label="๐Ÿ”ค Hinglish Typing (e.g. 'Tumhara')", value=False)
147
 
148
+ input_text = gr.Textbox(label="Enter Text", placeholder="Type sentences here...", lines=4)
149
+ input_audio = gr.Audio(sources=["microphone"], type="filepath", label="๐ŸŽ™๏ธ Voice Input (Hindi Only)")
 
 
 
 
150
 
151
+
152
+ translate_btn = gr.Button("Translate ๐Ÿš€", variant="primary")
 
 
 
 
 
153
 
154
+ # RIGHT COLUMN
155
+ with gr.Column():
156
  gr.Markdown("### ๐Ÿ“ค Translation Result")
157
+ output_text = gr.Textbox(label="Translation", lines=4, interactive=False, show_copy_button=True)
158
+ output_audio = gr.Audio(label="๐Ÿ”Š Listen (Hindi Only)", interactive=False, autoplay=False)
 
 
 
 
 
 
 
 
 
 
 
 
159
 
 
160
  translate_btn.click(
161
  fn=process_translation,
162
  inputs=[input_text, input_audio, direction, is_hinglish],
163
  outputs=[input_text, output_text, output_audio]
164
  )
165
 
166
+ # --- TAB 2: FEEDBACK ---
167
  with gr.TabItem("๐Ÿ“ Improve the AI"):
168
+ gr.Markdown("### ๐Ÿ› ๏ธ Help us improve accuracy")
169
+ gr.Markdown("Our AI is learning! If you spot a mistake, please submit the correct translation below.")
170
+
171
+
172
+ with gr.Group():
173
  with gr.Row():
174
  fb_direction = gr.Radio(["Kurukh -> Hindi", "Hindi -> Kurukh"], label="Direction", value="Kurukh -> Hindi")
175
 
176
  with gr.Row():
177
+ fb_original = gr.Textbox(label="Original Text")
178
+ fb_ai_output = gr.Textbox(label="AI's Wrong Translation")
179
 
180
+ fb_user_correct = gr.Textbox(label="โœ… Your Correct Translation", lines=2, placeholder="Type the correct translation here")
181
 
182
  submit_btn = gr.Button("Submit Correction to Database", variant="secondary")
183
  status_lbl = gr.Label(label="Status")
 
188
  outputs=status_lbl
189
  )
190
 
 
191
  gr.Markdown("---")
192
+ gr.HTML("<center style='color: #888;'>Built with โค๏ธ for the Kurukh Community โ€ข Powered by Google mT5 & OpenAI Whisper</center>")
193
 
194
  demo.launch()