File size: 1,828 Bytes
935375d
4c3af6e
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
935375d
4c3af6e
935375d
4c3af6e
 
935375d
4c3af6e
 
5f62aac
4c3af6e
5f62aac
4c3af6e
 
5f62aac
4c3af6e
5f62aac
4c3af6e
5f62aac
4c3af6e
 
 
 
 
5f62aac
4c3af6e
935375d
4c3af6e
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
import gradio as gr
import json

DB_FILE = "books.json"

# Load database
def load_books():
    with open(DB_FILE, "r") as f:
        return json.load(f)

# Search books
def search_books(query):
    books = load_books()
    results = []

    for b in books:
        if query.lower() in b["title"].lower():
            results.append(f"πŸ“˜ {b['title']}\nπŸ”— {b['link']}")

    return "\n\n".join(results) if results else "No books found ❌"

# Filter by level (P or S)
def filter_level(level):
    books = load_books()
    results = [b for b in books if b["class"] == level]

    if not results:
        return "No books found"

    return "\n\n".join([f"πŸ“˜ {b['title']}\nπŸ”— {b['link']}" for b in results])

# Show all books
def all_books():
    books = load_books()
    return "\n\n".join([f"πŸ“˜ {b['title']}\nπŸ”— {b['link']}" for b in books])

# Open REB directly
def open_reb():
    return "πŸ‘‰ Visit REB official site: https://www.reb.rw"

# UI
with gr.Blocks() as app:

    gr.Markdown("# πŸ“š Rwanda Online Library Platform")
    gr.Markdown("Powered by REB + AI Library System")

    with gr.Tab("πŸ” Search Books"):
        q = gr.Textbox(label="Search book (P1–S6)")
        out = gr.Textbox()
        gr.Button("Search").click(search_books, q, out)

    with gr.Tab("πŸ“‚ Filter by Level"):
        level = gr.Dropdown(["P", "S"], label="Select Level (P=Primary, S=Secondary)")
        out2 = gr.Textbox()
        gr.Button("Filter").click(filter_level, level, out2)

    with gr.Tab("πŸ“š All Books"):
        out3 = gr.Textbox()
        gr.Button("Show All Books").click(all_books, None, out3)

    with gr.Tab("🌐 REB Official"):
        out4 = gr.Textbox()
        gr.Button("Open REB").click(open_reb, None, out4)

    gr.Markdown("πŸ“Œ Data Source: Rwanda Basic Education Board (REB)")

app.launch()