Views
No views yet
sentence-transformers/all-MiniLM-L6-v21import requests
2
3API_URL = "https://api-inference.huggingface.co/models/mugwaneza/mbaza-model"
4headers = {"Authorization": f"Bearer {YOUR_HF_TOKEN}"}
5
6def query(prompt):
7 response = requests.post(API_URL, headers=headers, json={"inputs": [prompt]})
8 return response.json()
9
10# Example usage
11result = query("Ibihano by'ubujura ni ibihe?")
12print(result["text"])1from huggingface_hub import InferenceClient
2
3client = InferenceClient(token=YOUR_HF_TOKEN)
4
5response = client.post(
6 "mugwaneza/mbaza-model",
7 json={"inputs": ["Kwinjira aho umuntu atuye bitemewe namategeko"]}
8)
9print(response)1curl -X POST \
2 -H "Authorization: Bearer YOUR_HF_TOKEN" \
3 -H "Content-Type: application/json" \
4 -d '{"inputs":["Mwaramutse neza"]}' \
5 https://api-inference.huggingface.co/models/mugwaneza/mbaza-model1// React Native / JavaScript
2const API_URL = "https://api-inference.huggingface.co/models/mugwaneza/mbaza-model";
3const HF_TOKEN = "your_token_here";
4
5async function queryLegalAI(prompt) {
6 const response = await fetch(API_URL, {
7 method: "POST",
8 headers: {
9 "Authorization": `Bearer ${HF_TOKEN}`,
10 "Content-Type": "application/json"
11 },
12 body: JSON.stringify({ inputs: [prompt] })
13 });
14
15 return await response.json();
16}
17
18// Usage
19const result = await queryLegalAI("What is the punishment for theft?");
20console.log(result.text);1<?php
2
3namespace App\Services;
4
5use Illuminate\Support\Facades\Http;
6
7class MbazaLegalAI
8{
9 protected $apiUrl = 'https://api-inference.huggingface.co/models/mugwaneza/mbaza-model';
10 protected $token;
11
12 public function __construct()
13 {
14 $this->token = config('services.huggingface.token');
15 }
16
17 public function query($prompt, $userId = 'web_user')
18 {
19 $response = Http::withHeaders([
20 'Authorization' => "Bearer {$this->token}",
21 'Content-Type' => 'application/json'
22 ])->post($this->apiUrl, [
23 'inputs' => [$prompt, $userId]
24 ]);
25
26 return $response->json();
27 }
28}
29
30// Usage in Controller
31$ai = new MbazaLegalAI();
32$result = $ai->query("Ibihano by'ubujura ni ibihe?");
33return response()->json($result);1# Kinyarwanda
2query("Mwaramutse neza")
3# Response: Mwaramutse neza, amakuru yawe?
4
5# English
6query("Good morning")
7# Response: Good morning, how can I help you with legal matters?
8
9# French
10query("Bonjour")
11# Response: Bonjour, comment puis-je vous aider?1# Kinyarwanda
2query("Ibihano by'ubujura ni ibihe?")
3# Returns: Punishment information for theft
4
5# English
6query("What are the laws about corruption in Rwanda?")
7# Returns: Relevant legal articles on corruption
8
9# Mixed
10query("Kwinjira aho umuntu atuye bitemewe namategeko")
11# Returns: Laws about trespassing and unauthorized entry1query("Igihano cy'umuntu wakubise undi")
2# Returns: Punishment for assault
3
4query("What is the penalty for fraud?")
5# Returns: Detailed penalty information1{
2 "text": "Main response text (formatted for display)",
3 "intent": "greeting|law|punishment|fallback",
4 "laws": [
5 {
6 "article": "Article 166",
7 "description": "...",
8 "punishment": "...",
9 "similarity": 0.85
10 }
11 ],
12 "punishments": [
13 {
14 "crime": "Theft",
15 "category": "Property crimes",
16 "penalty": "..."
17 }
18 ]
19}dataset-all.csv)penal_code.csv)greetings.csv)inference.py - Main inference endpointassistant.py - Core assistant logicretriever.py - Semantic search and embedding managementconfig.py - Configuration and utilitieslaw_embeddings.npy - Precomputed embeddings (384-dim vectors)law_meta.json - Metadata for legal articlesconversation_contexts.json - Context tracking storage1# Clone the model repository
2git clone https://huggingface.co/mugwaneza/mbaza-model
3cd mbaza-model
4
5# Install dependencies
6pip install -r requirements.txt
7
8# Test locally
9python inference.py1@misc{mbaza-legal-ai,
2 author = {Mugwaneza Manzi},
3 title = {Mbaza Legal AI: Multilingual Legal Assistant for Rwanda},
4 year = {2025},
5 publisher = {Hugging Face},
6 url = {https://huggingface.co/mugwaneza/mbaza-model}
7}