casamN commited on
Commit
c3483ff
Β·
verified Β·
1 Parent(s): 2dc98d1

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +94 -78
app.py CHANGED
@@ -163,99 +163,114 @@ def query_pdf(question, top_k=3):
163
 
164
  def build_app():
165
  custom_css = """
166
- /* === Make layout full-width and responsive === */
167
- body, html {
168
- margin: 0;
169
- padding: 0;
170
- width: 100%;
171
- height: 100%;
172
- background: #f9fafb;
173
  }
174
 
175
  .gradio-container {
176
- font-family: 'Inter', 'Segoe UI', sans-serif;
177
- background: #f9fafb;
178
- color: #1f2937;
179
- width: 100% !important;
180
- max-width: 1400px !important; /* keeps content centered on large screens */
181
- margin: 0 auto !important; /* centers content */
182
- padding: 1.5% 2% !important; /* breathing room */
183
- box-sizing: border-box;
 
 
 
 
 
 
184
  }
185
 
186
- .gr-block, .gr-panel, .tabitem, .gradio-interface {
187
- width: 100% !important;
188
- max-width: 100% !important;
189
  }
190
-
191
- h1, h2, h3 {
192
- color: #003366 !important;
193
- font-weight: 600 !important;
194
  }
195
-
196
- .tab-nav button {
197
- font-size: 16px !important;
198
- font-weight: 500 !important;
199
- border-radius: 8px !important;
200
  }
201
-
202
- textarea, input, .gr-text-input {
203
- font-size: 15px !important;
204
- border-radius: 10px !important;
205
  }
206
 
207
- .gr-button {
208
- background-color: #003366 !important;
209
- color: white !important;
210
- border-radius: 10px !important;
211
- font-weight: 500 !important;
212
- padding: 10px 20px !important;
213
  }
214
-
215
- .gr-button:hover {
216
- background-color: #0055a4 !important;
 
217
  }
218
 
219
- footer, .gradio-container > div:last-child {
220
- text-align: center;
221
- margin-top: 2em;
 
222
  }
223
  """
224
 
225
-
226
- with gr.Blocks(title="Kiembu ↔ English β€” NRF Kenya Project", css=custom_css,
227
- theme=gr.themes.Soft(primary_hue="blue", secondary_hue="gray")) as app:
 
 
228
 
229
  gr.Markdown("""
230
  <div style='text-align:center'>
231
- <h1 style='color:#003366;'>Kiembu ↔ English Translation Suite</h1>
232
- <h3 style='color:#d4a017;'>Funded by NRF Kenya β€” Creating LLMs that Understand Native Languages</h3>
233
- <hr style='border:1px solid #003366;width:80%;margin:auto'>
234
  </div>
235
  """)
236
 
237
  with gr.Tabs():
238
- # Dictionary Tab
 
 
 
239
  with gr.TabItem("Dictionary Translator"):
240
- gr.Markdown("""### Quick Word Translation β€” **Kiembu ↔ English** and get its translation instantly.
241
- πŸ”€ **Sample Words:**
 
 
 
242
  | Kiembu | English |
243
  |:--|:--|
244
  | Uvoro | how are you |
245
  | Ri? | When? |
246
  | Ku? | Where? |
247
- | Uka | come |""")
 
248
  inp = gr.Textbox(label="Enter Word", placeholder="e.g. 'Uvoro' or 'how are you'", lines=1)
249
- dir_sel = gr.Radio(["Kiembu β†’ English", "English β†’ Kiembu"], value="Kiembu β†’ English", label="Select Direction")
 
 
 
 
250
  out = gr.Textbox(label="Translation Result")
251
  gr.Button("Translate").click(translate_word, [inp, dir_sel], out)
252
 
253
- # PDF Translation Tab
 
 
254
  with gr.TabItem("PDF Translation"):
255
  gr.Markdown("""
256
- ### **English β†’ Kiembu PDF Translator**
257
- Upload an **English PDF document** (e.g., ID or passport application, hospital form, etc.),
258
- and the system will translate it into **Kiembu** and generate a downloadable translated PDF.
259
  """)
260
  pdf_input = gr.File(label="Upload English PDF", file_types=[".pdf"])
261
  translate_btn = gr.Button("Translate to Kiembu")
@@ -263,16 +278,18 @@ def build_app():
263
  status = gr.Textbox(label="Status", interactive=False)
264
  translate_btn.click(translate_pdf_to_kiembu, inputs=[pdf_input], outputs=[output_file, status])
265
 
266
- # NRF LLM Model Q&A Tab
 
 
267
  with gr.TabItem("PDF Chat (NRF LLM Model)"):
268
  gr.Markdown("""
269
- ### **Interactive PDF Chat (Gemma Q&A)**
270
- Upload any **informative PDF** (e.g., government reports, history books, manuals)
271
  and ask natural-language questions to understand its content better.
272
 
273
- Example:
274
- - *β€œWhat does this document say about birth registration?”*
275
- - *β€œSummarize Chapter 2.”*
276
  """)
277
  pdf = gr.File(label="Upload PDF Document")
278
  status = gr.Textbox(label="Status")
@@ -286,24 +303,22 @@ def build_app():
286
  # TAB 4: ABOUT
287
  # -----------------------------
288
  with gr.TabItem("About"):
289
- gr.Markdown(
290
- """
291
- ### About the Project
292
- The **NRF Kenya Project** on *Creating LLMs that Understand Native Languages*
293
- aims to preserve and promote indigenous linguistic heritage through advanced AI translation tools.
294
-
295
- - **Languages Supported:** Kiembu ↔ English
296
- - **Core Engine:** NRF LLM Model (based on lightweight MarianMT)
297
- - **Developed by:** Casam Njagi Nyaga
298
- - **Funding Agency:** National Research Fund (NRF), Kenya
299
- - **Objective:** Foster inclusion of native languages in AI-driven communication.
300
- """
301
- )
302
 
303
  gr.Markdown("""
304
  <hr style='border:0.5px solid #ccc'>
305
  <div style='text-align:center;color:#003366;font-size:14px'>
306
- Β© 2025 National Research Fund (NRF) Kenya β€” All Rights Reserved
307
  </div>
308
  """)
309
 
@@ -312,3 +327,4 @@ def build_app():
312
 
313
  demo = build_app()
314
  demo.launch()
 
 
163
 
164
  def build_app():
165
  custom_css = """
166
+ body {
167
+ background: #f5f5f5;
168
+ margin: 0;
169
+ padding: 0;
170
+ overflow: auto;
 
 
171
  }
172
 
173
  .gradio-container {
174
+ display: flex;
175
+ flex-direction: column;
176
+ align-items: center;
177
+ justify-content: flex-start;
178
+ min-height: 100vh;
179
+ padding: 30px 15px;
180
+ box-sizing: border-box;
181
+ border: 2px solid #ccc;
182
+ border-radius: 16px;
183
+ box-shadow: 0 4px 16px rgba(0,0,0,0.1);
184
+ background: white;
185
+ max-width: 900px;
186
+ margin: 20px auto;
187
+ overflow-y: auto;
188
  }
189
 
190
+ ::-webkit-scrollbar {
191
+ width: 10px;
 
192
  }
193
+ ::-webkit-scrollbar-track {
194
+ background: #eee;
195
+ border-radius: 10px;
 
196
  }
197
+ ::-webkit-scrollbar-thumb {
198
+ background: #aaa;
199
+ border-radius: 10px;
 
 
200
  }
201
+ ::-webkit-scrollbar-thumb:hover {
202
+ background: #777;
 
 
203
  }
204
 
205
+ textarea, input[type="text"], .gr-textbox, .gr-input {
206
+ border: 2px solid #bbb !important;
207
+ border-radius: 10px !important;
208
+ padding: 8px !important;
209
+ box-shadow: inset 0 2px 4px rgba(0,0,0,0.05);
210
+ transition: border-color 0.2s ease, box-shadow 0.2s ease;
211
  }
212
+ textarea:focus, input[type="text"]:focus {
213
+ border-color: #0078D7 !important;
214
+ box-shadow: 0 0 5px rgba(0,120,215,0.3) !important;
215
+ outline: none;
216
  }
217
 
218
+ button, .gr-button {
219
+ border-radius: 10px !important;
220
+ padding: 10px 16px !important;
221
+ font-weight: 600 !important;
222
  }
223
  """
224
 
225
+ with gr.Blocks(
226
+ title="Kiembu ↔ English β€” NRF Kenya Project",
227
+ css=custom_css,
228
+ theme=gr.themes.Soft(primary_hue="blue", secondary_hue="gray")
229
+ ) as app:
230
 
231
  gr.Markdown("""
232
  <div style='text-align:center'>
233
+ <h1 style='color:#003366;'>Kiembu ↔ English Translation Suite</h1>
234
+ <h3 style='color:#d4a017;'>Funded by NRF Kenya β€” Creating LLMs that Understand Native Languages</h3>
235
+ <hr style='border:1px solid #003366;width:80%;margin:auto'>
236
  </div>
237
  """)
238
 
239
  with gr.Tabs():
240
+
241
+ # -----------------------------
242
+ # TAB 1: DICTIONARY TRANSLATOR
243
+ # -----------------------------
244
  with gr.TabItem("Dictionary Translator"):
245
+ gr.Markdown("""
246
+ ### Quick Word Translation β€” **Kiembu ↔ English**
247
+ Enter a single word or short phrase and get its translation instantly.
248
+
249
+ **Sample Words:**
250
  | Kiembu | English |
251
  |:--|:--|
252
  | Uvoro | how are you |
253
  | Ri? | When? |
254
  | Ku? | Where? |
255
+ | Uka | come |
256
+ """)
257
  inp = gr.Textbox(label="Enter Word", placeholder="e.g. 'Uvoro' or 'how are you'", lines=1)
258
+ dir_sel = gr.Radio(
259
+ ["Kiembu β†’ English", "English β†’ Kiembu"],
260
+ value="Kiembu β†’ English",
261
+ label="Select Direction"
262
+ )
263
  out = gr.Textbox(label="Translation Result")
264
  gr.Button("Translate").click(translate_word, [inp, dir_sel], out)
265
 
266
+ # -----------------------------
267
+ # TAB 2: PDF TRANSLATION
268
+ # -----------------------------
269
  with gr.TabItem("PDF Translation"):
270
  gr.Markdown("""
271
+ ### **English β†’ Kiembu PDF Translator**
272
+ Upload an **English PDF document** (e.g., ID form, hospital form, passport form)
273
+ and get a **translated PDF in Kiembu** for download.
274
  """)
275
  pdf_input = gr.File(label="Upload English PDF", file_types=[".pdf"])
276
  translate_btn = gr.Button("Translate to Kiembu")
 
278
  status = gr.Textbox(label="Status", interactive=False)
279
  translate_btn.click(translate_pdf_to_kiembu, inputs=[pdf_input], outputs=[output_file, status])
280
 
281
+ # -----------------------------
282
+ # TAB 3: NRF LLM MODEL Q&A
283
+ # -----------------------------
284
  with gr.TabItem("PDF Chat (NRF LLM Model)"):
285
  gr.Markdown("""
286
+ ### **Interactive PDF Chat β€” NRF LLM Model**
287
+ Upload any **informative PDF** (e.g., government report, history book, or manual)
288
  and ask natural-language questions to understand its content better.
289
 
290
+ **Examples:**
291
+ - "What does this document say about birth registration?"
292
+ - "Summarize Chapter 2."
293
  """)
294
  pdf = gr.File(label="Upload PDF Document")
295
  status = gr.Textbox(label="Status")
 
303
  # TAB 4: ABOUT
304
  # -----------------------------
305
  with gr.TabItem("About"):
306
+ gr.Markdown("""
307
+ ### About the Project
308
+ The **NRF Kenya Project** on *Creating LLMs that Understand Native Languages*
309
+ aims to preserve and promote indigenous linguistic heritage through advanced AI translation tools.
310
+
311
+ - **Languages Supported:** Kiembu ↔ English
312
+ - **Core Engine:** NRF LLM Model (based on lightweight MarianMT)
313
+ - **Developed by:** Casam Njagi Nyaga
314
+ - **Funding Agency:** National Research Fund (NRF), Kenya
315
+ - **Objective:** Foster inclusion of native languages in AI-driven communication.
316
+ """)
 
 
317
 
318
  gr.Markdown("""
319
  <hr style='border:0.5px solid #ccc'>
320
  <div style='text-align:center;color:#003366;font-size:14px'>
321
+ Β© 2025 National Research Fund (NRF) Kenya β€” All Rights Reserved
322
  </div>
323
  """)
324
 
 
327
 
328
  demo = build_app()
329
  demo.launch()
330
+