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()