Update app.py
Browse files
app.py
CHANGED
|
@@ -163,99 +163,114 @@ def query_pdf(question, top_k=3):
|
|
| 163 |
|
| 164 |
def build_app():
|
| 165 |
custom_css = """
|
| 166 |
-
|
| 167 |
-
|
| 168 |
-
|
| 169 |
-
|
| 170 |
-
|
| 171 |
-
height: 100%;
|
| 172 |
-
background: #f9fafb;
|
| 173 |
}
|
| 174 |
|
| 175 |
.gradio-container {
|
| 176 |
-
|
| 177 |
-
|
| 178 |
-
|
| 179 |
-
|
| 180 |
-
|
| 181 |
-
|
| 182 |
-
|
| 183 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 184 |
}
|
| 185 |
|
| 186 |
-
|
| 187 |
-
|
| 188 |
-
max-width: 100% !important;
|
| 189 |
}
|
| 190 |
-
|
| 191 |
-
|
| 192 |
-
|
| 193 |
-
font-weight: 600 !important;
|
| 194 |
}
|
| 195 |
-
|
| 196 |
-
|
| 197 |
-
|
| 198 |
-
font-weight: 500 !important;
|
| 199 |
-
border-radius: 8px !important;
|
| 200 |
}
|
| 201 |
-
|
| 202 |
-
|
| 203 |
-
font-size: 15px !important;
|
| 204 |
-
border-radius: 10px !important;
|
| 205 |
}
|
| 206 |
|
| 207 |
-
.gr-
|
| 208 |
-
|
| 209 |
-
|
| 210 |
-
|
| 211 |
-
|
| 212 |
-
|
| 213 |
}
|
| 214 |
-
|
| 215 |
-
|
| 216 |
-
|
|
|
|
| 217 |
}
|
| 218 |
|
| 219 |
-
|
| 220 |
-
|
| 221 |
-
|
|
|
|
| 222 |
}
|
| 223 |
"""
|
| 224 |
|
| 225 |
-
|
| 226 |
-
|
| 227 |
-
|
|
|
|
|
|
|
| 228 |
|
| 229 |
gr.Markdown("""
|
| 230 |
<div style='text-align:center'>
|
| 231 |
-
|
| 232 |
-
|
| 233 |
-
|
| 234 |
</div>
|
| 235 |
""")
|
| 236 |
|
| 237 |
with gr.Tabs():
|
| 238 |
-
|
|
|
|
|
|
|
|
|
|
| 239 |
with gr.TabItem("Dictionary Translator"):
|
| 240 |
-
gr.Markdown("""
|
| 241 |
-
|
|
|
|
|
|
|
|
|
|
| 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(
|
|
|
|
|
|
|
|
|
|
|
|
|
| 250 |
out = gr.Textbox(label="Translation Result")
|
| 251 |
gr.Button("Translate").click(translate_word, [inp, dir_sel], out)
|
| 252 |
|
| 253 |
-
#
|
|
|
|
|
|
|
| 254 |
with gr.TabItem("PDF Translation"):
|
| 255 |
gr.Markdown("""
|
| 256 |
-
###
|
| 257 |
-
Upload an **English PDF document** (e.g., ID
|
| 258 |
-
and
|
| 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 |
-
#
|
|
|
|
|
|
|
| 267 |
with gr.TabItem("PDF Chat (NRF LLM Model)"):
|
| 268 |
gr.Markdown("""
|
| 269 |
-
###
|
| 270 |
-
Upload any **informative PDF** (e.g., government
|
| 271 |
and ask natural-language questions to understand its content better.
|
| 272 |
|
| 273 |
-
|
| 274 |
-
-
|
| 275 |
-
-
|
| 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 |
-
|
| 292 |
-
|
| 293 |
-
|
| 294 |
-
|
| 295 |
-
|
| 296 |
-
|
| 297 |
-
|
| 298 |
-
|
| 299 |
-
|
| 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 |
-
|
| 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 |
+
|