Upload app.py with huggingface_hub
Browse files
app.py
CHANGED
|
@@ -1,530 +1,161 @@
|
|
| 1 |
"""
|
| 2 |
-
NullAI -
|
| 3 |
-
|
| 4 |
-
|
| 5 |
-
Key Innovations:
|
| 6 |
-
- Knowledge Tile System: Structured, verifiable knowledge units
|
| 7 |
-
- 55+ Specialized Domains with Expert Verification
|
| 8 |
-
- Spatial Coordinate Encoding for knowledge representation
|
| 9 |
-
- Real-time Hallucination Detection
|
| 10 |
-
- Transparent Confidence Scoring
|
| 11 |
-
- ORCID-based Expert Authentication
|
| 12 |
"""
|
| 13 |
import gradio as gr
|
| 14 |
-
import
|
| 15 |
-
from transformers import AutoModelForCausalLM, AutoTokenizer
|
| 16 |
-
import random
|
| 17 |
import json
|
| 18 |
-
from datetime import datetime
|
| 19 |
-
|
| 20 |
-
model = None
|
| 21 |
-
tokenizer = None
|
| 22 |
-
device = None
|
| 23 |
-
DEFAULT_MODEL = "deepseek-ai/DeepSeek-R1-Distill-Qwen-7B"
|
| 24 |
-
|
| 25 |
-
# Domain metadata with specialization info
|
| 26 |
-
DOMAINS = {
|
| 27 |
-
"medical": {
|
| 28 |
-
"name": "π₯ Medical",
|
| 29 |
-
"desc": "Evidence-based medical knowledge",
|
| 30 |
-
"color": "#e74c3c",
|
| 31 |
-
"tiles": 2847
|
| 32 |
-
},
|
| 33 |
-
"legal": {
|
| 34 |
-
"name": "βοΈ Legal",
|
| 35 |
-
"desc": "Legal principles with case law",
|
| 36 |
-
"color": "#3498db",
|
| 37 |
-
"tiles": 1923
|
| 38 |
-
},
|
| 39 |
-
"programming": {
|
| 40 |
-
"name": "π» Programming",
|
| 41 |
-
"desc": "Software engineering best practices",
|
| 42 |
-
"color": "#2ecc71",
|
| 43 |
-
"tiles": 3251
|
| 44 |
-
},
|
| 45 |
-
"science": {
|
| 46 |
-
"name": "π¬ Science",
|
| 47 |
-
"desc": "Peer-reviewed scientific knowledge",
|
| 48 |
-
"color": "#9b59b6",
|
| 49 |
-
"tiles": 2134
|
| 50 |
-
},
|
| 51 |
-
"economics": {
|
| 52 |
-
"name": "π Economics",
|
| 53 |
-
"desc": "Economic theory and analysis",
|
| 54 |
-
"color": "#f39c12",
|
| 55 |
-
"tiles": 1456
|
| 56 |
-
},
|
| 57 |
-
"general": {
|
| 58 |
-
"name": "π General",
|
| 59 |
-
"desc": "Broad multi-domain knowledge",
|
| 60 |
-
"color": "#34495e",
|
| 61 |
-
"tiles": 4892
|
| 62 |
-
}
|
| 63 |
-
}
|
| 64 |
-
|
| 65 |
-
|
| 66 |
-
def load_model():
|
| 67 |
-
"""Load model with 8-bit quantization for memory efficiency"""
|
| 68 |
-
global model, tokenizer, device
|
| 69 |
-
if model is not None:
|
| 70 |
-
return
|
| 71 |
-
|
| 72 |
-
print(f"Loading {DEFAULT_MODEL} with 8-bit quantization...")
|
| 73 |
-
device = "cuda" if torch.cuda.is_available() else ("mps" if torch.backends.mps.is_available() else "cpu")
|
| 74 |
-
print(f"Using device: {device}")
|
| 75 |
-
|
| 76 |
-
tokenizer = AutoTokenizer.from_pretrained(DEFAULT_MODEL, trust_remote_code=True)
|
| 77 |
-
model = AutoModelForCausalLM.from_pretrained(
|
| 78 |
-
DEFAULT_MODEL,
|
| 79 |
-
load_in_8bit=True,
|
| 80 |
-
device_map="auto",
|
| 81 |
-
trust_remote_code=True
|
| 82 |
-
)
|
| 83 |
-
model.eval()
|
| 84 |
-
print("Model loaded successfully!")
|
| 85 |
-
|
| 86 |
-
|
| 87 |
-
def get_system_prompt(domain: str) -> str:
|
| 88 |
-
"""Generate domain-specific system prompt"""
|
| 89 |
-
prompts = {
|
| 90 |
-
"medical": """You are a medical expert with access to verified clinical knowledge.
|
| 91 |
-
Provide evidence-based information with proper medical terminology.
|
| 92 |
-
Always recommend consulting healthcare professionals for personal decisions.""",
|
| 93 |
-
|
| 94 |
-
"legal": """You are a legal expert with access to verified case law and legal principles.
|
| 95 |
-
Provide accurate legal information based on established legal frameworks.
|
| 96 |
-
Always recommend consulting licensed attorneys for specific legal advice.""",
|
| 97 |
-
|
| 98 |
-
"programming": """You are a software engineering expert with deep knowledge of best practices.
|
| 99 |
-
Provide well-documented, secure, and efficient code solutions.
|
| 100 |
-
Explain the reasoning behind architectural decisions.""",
|
| 101 |
-
|
| 102 |
-
"science": """You are a scientific expert covering physics, chemistry, biology, and methodology.
|
| 103 |
-
Provide accurate explanations with proper scientific terminology.
|
| 104 |
-
Reference established scientific principles and theories.""",
|
| 105 |
-
|
| 106 |
-
"economics": """You are an economics expert covering theory, policy, and market analysis.
|
| 107 |
-
Provide accurate economic analysis with proper terminology.
|
| 108 |
-
Note that this is educational information, not financial advice.""",
|
| 109 |
-
|
| 110 |
-
"general": """You are a knowledgeable assistant with broad expertise.
|
| 111 |
-
Provide accurate, well-reasoned answers across multiple domains.
|
| 112 |
-
Be clear about confidence levels and limitations."""
|
| 113 |
-
}
|
| 114 |
-
return prompts.get(domain, prompts["general"])
|
| 115 |
-
|
| 116 |
-
|
| 117 |
-
def calculate_confidence(response_text: str, domain: str) -> float:
|
| 118 |
-
"""Simulate confidence calculation based on response characteristics"""
|
| 119 |
-
confidence = 0.75
|
| 120 |
-
|
| 121 |
-
# Increase confidence for longer, detailed responses
|
| 122 |
-
if len(response_text) > 200:
|
| 123 |
-
confidence += 0.05
|
| 124 |
-
|
| 125 |
-
# Increase confidence if specific terminology is used
|
| 126 |
-
domain_terms = {
|
| 127 |
-
"medical": ["diagnosis", "treatment", "symptom", "clinical", "patient"],
|
| 128 |
-
"legal": ["law", "statute", "case", "court", "precedent"],
|
| 129 |
-
"programming": ["function", "class", "method", "algorithm", "code"],
|
| 130 |
-
"science": ["theory", "experiment", "hypothesis", "research", "data"],
|
| 131 |
-
"economics": ["market", "supply", "demand", "policy", "economic"]
|
| 132 |
-
}
|
| 133 |
-
|
| 134 |
-
terms = domain_terms.get(domain, [])
|
| 135 |
-
matches = sum(1 for term in terms if term.lower() in response_text.lower())
|
| 136 |
-
confidence += min(matches * 0.03, 0.15)
|
| 137 |
-
|
| 138 |
-
return min(confidence, 0.98)
|
| 139 |
-
|
| 140 |
-
|
| 141 |
-
def generate_knowledge_tiles(domain: str, question: str) -> str:
|
| 142 |
-
"""Simulate knowledge tile retrieval"""
|
| 143 |
-
tiles = []
|
| 144 |
-
num_tiles = random.randint(2, 4)
|
| 145 |
-
|
| 146 |
-
for i in range(num_tiles):
|
| 147 |
-
tile_id = f"{domain.upper()[:3]}-{random.randint(1000, 9999)}"
|
| 148 |
-
verification = random.choice(["π’ Expert", "π΅ Community", "βͺ Unverified"])
|
| 149 |
-
confidence = random.uniform(0.75, 0.95)
|
| 150 |
-
|
| 151 |
-
tiles.append(f"**Tile {tile_id}** | {verification} | Confidence: {confidence:.1%}")
|
| 152 |
-
|
| 153 |
-
return "\n".join(tiles)
|
| 154 |
-
|
| 155 |
-
|
| 156 |
-
def detect_hallucination_risk(response: str) -> dict:
|
| 157 |
-
"""Simulate hallucination detection"""
|
| 158 |
-
# Simple heuristic-based detection
|
| 159 |
-
risk_score = 0.0
|
| 160 |
-
flags = []
|
| 161 |
-
|
| 162 |
-
# Check for overly confident statements without qualifiers
|
| 163 |
-
if any(word in response.lower() for word in ["definitely", "absolutely", "always", "never"]):
|
| 164 |
-
risk_score += 0.1
|
| 165 |
-
flags.append("High certainty language detected")
|
| 166 |
-
|
| 167 |
-
# Check for proper hedging
|
| 168 |
-
if any(word in response.lower() for word in ["may", "might", "could", "possibly", "likely"]):
|
| 169 |
-
risk_score -= 0.1
|
| 170 |
-
flags.append("β Appropriate hedging present")
|
| 171 |
-
|
| 172 |
-
risk_score = max(0.0, min(risk_score, 1.0))
|
| 173 |
-
|
| 174 |
-
return {
|
| 175 |
-
"risk_level": "Low" if risk_score < 0.3 else "Medium" if risk_score < 0.6 else "High",
|
| 176 |
-
"risk_score": risk_score,
|
| 177 |
-
"flags": flags
|
| 178 |
-
}
|
| 179 |
-
|
| 180 |
-
|
| 181 |
-
def format_response_with_metadata(response: str, domain: str, question: str, gen_time: float) -> tuple:
|
| 182 |
-
"""Format response with NullAI metadata"""
|
| 183 |
-
|
| 184 |
-
# Calculate confidence
|
| 185 |
-
confidence = calculate_confidence(response, domain)
|
| 186 |
-
|
| 187 |
-
# Generate knowledge tiles
|
| 188 |
-
tiles = generate_knowledge_tiles(domain, question)
|
| 189 |
-
|
| 190 |
-
# Detect hallucination risk
|
| 191 |
-
hallucination = detect_hallucination_risk(response)
|
| 192 |
-
|
| 193 |
-
# Format metadata display
|
| 194 |
-
metadata = f"""
|
| 195 |
-
## π― Response Quality Metrics
|
| 196 |
-
***(Simulated for Demo)***
|
| 197 |
-
|
| 198 |
-
**Confidence Score:** {confidence:.1%} {'π’' if confidence > 0.8 else 'π‘' if confidence > 0.6 else 'π΄'}
|
| 199 |
-
**Domain:** {DOMAINS[domain]['name']} ({DOMAINS[domain]['tiles']} verified tiles*)
|
| 200 |
-
**Generation Time:** {gen_time:.2f}s
|
| 201 |
-
**Hallucination Risk:** {hallucination['risk_level']} ({hallucination['risk_score']:.1%})*
|
| 202 |
-
|
| 203 |
-
*_Simulated metrics - Production system calculates from actual knowledge base_
|
| 204 |
-
|
| 205 |
-
---
|
| 206 |
-
|
| 207 |
-
## π Knowledge Tiles Retrieved
|
| 208 |
-
***(Demo - Randomly Generated)***
|
| 209 |
-
|
| 210 |
-
{tiles}
|
| 211 |
|
| 212 |
-
|
| 213 |
-
|
| 214 |
-
|
| 215 |
-
|
| 216 |
-
|
| 217 |
-
|
| 218 |
-
|
| 219 |
-
|
| 220 |
-
|
| 221 |
-
|
| 222 |
-
|
| 223 |
-
|
| 224 |
-
|
| 225 |
-
|
| 226 |
-
|
| 227 |
-
|
| 228 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 229 |
|
| 230 |
---
|
| 231 |
|
| 232 |
-
|
| 233 |
-
|
| 234 |
-
NullAI uses a revolutionary **Knowledge Tile System** where each piece of information is:
|
| 235 |
-
1. Stored as a verifiable "tile" in a multi-dimensional knowledge space
|
| 236 |
-
2. Validated by domain experts with ORCID authentication
|
| 237 |
-
3. Assigned spatial coordinates for semantic relationships
|
| 238 |
-
4. Continuously monitored for accuracy and relevance
|
| 239 |
|
| 240 |
-
**
|
| 241 |
-
|
| 242 |
-
**Production System:** Connects to real knowledge base with actual expert verification and spatial encoding.
|
| 243 |
"""
|
| 244 |
|
| 245 |
-
|
| 246 |
-
|
| 247 |
-
|
| 248 |
-
def generate(question, domain, temp, max_len, progress=gr.Progress()):
|
| 249 |
-
"""Generate response with full NullAI pipeline simulation"""
|
| 250 |
-
if not question.strip():
|
| 251 |
-
return "", "β οΈ Please enter a question."
|
| 252 |
-
|
| 253 |
-
try:
|
| 254 |
-
import time
|
| 255 |
-
start_time = time.time()
|
| 256 |
-
|
| 257 |
-
# Load model
|
| 258 |
-
progress(0.1, desc="π Loading NullAI model...")
|
| 259 |
-
load_model()
|
| 260 |
-
|
| 261 |
-
# Simulate tile retrieval
|
| 262 |
-
progress(0.2, desc="π Retrieving knowledge tiles...")
|
| 263 |
-
time.sleep(0.5)
|
| 264 |
-
|
| 265 |
-
# Generate response
|
| 266 |
-
progress(0.3, desc="π§ Generating response...")
|
| 267 |
-
system_prompt = get_system_prompt(domain)
|
| 268 |
-
full_prompt = f"{system_prompt}\n\nQuestion: {question}\n\nAnswer:"
|
| 269 |
-
|
| 270 |
-
inputs = tokenizer(full_prompt, return_tensors="pt").to(device)
|
| 271 |
-
|
| 272 |
-
with torch.no_grad():
|
| 273 |
-
outputs = model.generate(
|
| 274 |
-
**inputs,
|
| 275 |
-
max_new_tokens=max_len,
|
| 276 |
-
temperature=temp,
|
| 277 |
-
do_sample=True if temp > 0 else False,
|
| 278 |
-
pad_token_id=tokenizer.eos_token_id,
|
| 279 |
-
top_p=0.9,
|
| 280 |
-
repetition_penalty=1.1
|
| 281 |
-
)
|
| 282 |
-
|
| 283 |
-
response = tokenizer.decode(outputs[0], skip_special_tokens=True)
|
| 284 |
-
|
| 285 |
-
# Extract answer
|
| 286 |
-
if "Answer:" in response:
|
| 287 |
-
response = response.split("Answer:")[-1].strip()
|
| 288 |
-
|
| 289 |
-
# Calculate generation time
|
| 290 |
-
gen_time = time.time() - start_time
|
| 291 |
-
|
| 292 |
-
# Format with metadata
|
| 293 |
-
progress(0.9, desc="β
Formatting results...")
|
| 294 |
-
formatted_response, metadata = format_response_with_metadata(
|
| 295 |
-
response, domain, question, gen_time
|
| 296 |
-
)
|
| 297 |
-
|
| 298 |
-
progress(1.0, desc="β
Complete!")
|
| 299 |
-
|
| 300 |
-
return formatted_response, metadata
|
| 301 |
|
| 302 |
except Exception as e:
|
| 303 |
-
return f"
|
| 304 |
-
|
| 305 |
-
|
| 306 |
-
# Custom CSS for better styling
|
| 307 |
-
custom_css = """
|
| 308 |
-
.domain-info {
|
| 309 |
-
background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
|
| 310 |
-
padding: 20px;
|
| 311 |
-
border-radius: 10px;
|
| 312 |
-
color: white;
|
| 313 |
-
margin-bottom: 20px;
|
| 314 |
-
}
|
| 315 |
-
|
| 316 |
-
.metric-box {
|
| 317 |
-
background: #f8f9fa;
|
| 318 |
-
padding: 15px;
|
| 319 |
-
border-radius: 8px;
|
| 320 |
-
border-left: 4px solid #667eea;
|
| 321 |
-
margin: 10px 0;
|
| 322 |
-
}
|
| 323 |
-
"""
|
| 324 |
-
|
| 325 |
-
# Build Gradio interface
|
| 326 |
-
with gr.Blocks(title="NullAI - Knowledge Reasoning System", css=custom_css, theme=gr.themes.Soft()) as demo:
|
| 327 |
|
|
|
|
|
|
|
| 328 |
gr.Markdown("""
|
| 329 |
-
#
|
| 330 |
|
| 331 |
-
|
| 332 |
|
| 333 |
-
|
| 334 |
-
|
| 335 |
-
- π¨ββοΈ **Expert Verification**: ORCID-authenticated domain experts validate each tile
|
| 336 |
-
- π― **Confidence Scoring**: Transparent confidence metrics for every response
|
| 337 |
-
- π **Hallucination Detection**: Real-time monitoring for accuracy and reliability
|
| 338 |
-
- π **55+ Specialized Domains**: From medical to legal to programming and beyond
|
| 339 |
-
""")
|
| 340 |
|
| 341 |
-
|
| 342 |
-
|
| 343 |
-
with gr.Tab("π¬ Introduction"):
|
| 344 |
-
gr.HTML("""
|
| 345 |
-
<div style="text-align: center; margin: 20px 0;">
|
| 346 |
-
<video width="100%" height="auto" controls style="max-width: 800px; border-radius: 10px; box-shadow: 0 4px 6px rgba(0,0,0,0.1);">
|
| 347 |
-
<source src="file/main_intro.mp4" type="video/mp4">
|
| 348 |
-
Your browser does not support the video tag.
|
| 349 |
-
</video>
|
| 350 |
-
</div>
|
| 351 |
-
""")
|
| 352 |
-
gr.Markdown("""
|
| 353 |
-
**Main Feature Highlights:**
|
| 354 |
-
- Create specialized AIs instantly across 55+ domains
|
| 355 |
-
- Expert-verified knowledge tiles with ORCID authentication
|
| 356 |
-
- Judge System with Alpha and Beta lobes for self-checking
|
| 357 |
-
- Zero hallucination goal through systematic verification
|
| 358 |
-
""")
|
| 359 |
-
|
| 360 |
-
with gr.Tab("π Educational AI"):
|
| 361 |
-
gr.HTML("""
|
| 362 |
-
<div style="text-align: center; margin: 20px 0;">
|
| 363 |
-
<video width="100%" height="auto" controls style="max-width: 800px; border-radius: 10px; box-shadow: 0 4px 6px rgba(0,0,0,0.1);">
|
| 364 |
-
<source src="file/educational_ai.mp4" type="video/mp4">
|
| 365 |
-
Your browser does not support the video tag.
|
| 366 |
-
</video>
|
| 367 |
-
</div>
|
| 368 |
-
""")
|
| 369 |
-
gr.Markdown("""
|
| 370 |
-
**Educational AI Features:**
|
| 371 |
-
- Deploy domain-specific educational AI in 30 seconds
|
| 372 |
-
- 2,847+ verified educational knowledge tiles
|
| 373 |
-
- Perfect for schools, universities, and online learning platforms
|
| 374 |
-
- Customizable for any subject or grade level
|
| 375 |
-
""")
|
| 376 |
-
|
| 377 |
-
with gr.Tab("π Spatial Encoding"):
|
| 378 |
-
gr.HTML("""
|
| 379 |
-
<div style="text-align: center; margin: 20px 0;">
|
| 380 |
-
<video width="100%" height="auto" controls style="max-width: 800px; border-radius: 10px; box-shadow: 0 4px 6px rgba(0,0,0,0.1);">
|
| 381 |
-
<source src="file/spatial_encoding.mp4" type="video/mp4">
|
| 382 |
-
Your browser does not support the video tag.
|
| 383 |
-
</video>
|
| 384 |
-
</div>
|
| 385 |
-
""")
|
| 386 |
-
gr.Markdown("""
|
| 387 |
-
**Spatial Knowledge Encoding:**
|
| 388 |
-
- Navigate knowledge in infinite dimensions
|
| 389 |
-
- Semantic relationships visualized in multi-dimensional space
|
| 390 |
-
- Automatic clustering of related concepts
|
| 391 |
-
- Revolutionary approach to knowledge representation
|
| 392 |
-
""")
|
| 393 |
-
|
| 394 |
-
gr.Markdown("---")
|
| 395 |
|
| 396 |
with gr.Row():
|
| 397 |
-
with gr.Column(
|
| 398 |
-
|
| 399 |
-
choices=[(v["name"], k) for k, v in DOMAINS.items()],
|
| 400 |
-
value="general",
|
| 401 |
-
label="π― Select Knowledge Domain",
|
| 402 |
-
info="Choose the specialized domain for your question"
|
| 403 |
-
)
|
| 404 |
|
| 405 |
-
|
| 406 |
-
label="
|
| 407 |
-
placeholder="Ask anything
|
| 408 |
lines=3
|
| 409 |
)
|
| 410 |
|
| 411 |
-
|
| 412 |
-
|
| 413 |
-
|
| 414 |
-
|
| 415 |
-
|
| 416 |
-
info="Higher = more creative, Lower = more focused"
|
| 417 |
-
)
|
| 418 |
-
max_len = gr.Slider(
|
| 419 |
-
128, 1024,
|
| 420 |
-
value=512,
|
| 421 |
-
step=128,
|
| 422 |
-
label="π Max Tokens",
|
| 423 |
-
info="Maximum response length"
|
| 424 |
-
)
|
| 425 |
-
|
| 426 |
-
submit_btn = gr.Button("π Generate Answer", variant="primary", size="lg")
|
| 427 |
-
|
| 428 |
-
with gr.Column(scale=1):
|
| 429 |
-
gr.Markdown("""
|
| 430 |
-
### π System Statistics
|
| 431 |
-
***(Demo Values - For Illustration)***
|
| 432 |
-
|
| 433 |
-
**Total Knowledge Tiles:** 16,503*
|
| 434 |
-
**Expert Contributors:** 342*
|
| 435 |
-
**Domains Covered:** 55+*
|
| 436 |
-
**Average Confidence:** 87.3%*
|
| 437 |
-
|
| 438 |
-
*_Simulated statistics for demonstration purposes. Production system would display real-time data from connected database._
|
| 439 |
-
|
| 440 |
-
### β¨ What Makes NullAI Different?
|
| 441 |
-
|
| 442 |
-
Traditional LLMs generate responses from learned patterns, often "hallucinating" incorrect information.
|
| 443 |
-
|
| 444 |
-
**NullAI** retrieves answers from expert-verified knowledge tiles, each with:
|
| 445 |
-
- Verified source attribution
|
| 446 |
-
- Expert validation status
|
| 447 |
-
- Confidence scoring
|
| 448 |
-
- Semantic coordinates
|
| 449 |
-
""")
|
| 450 |
|
| 451 |
-
|
| 452 |
-
response_box = gr.Textbox(
|
| 453 |
-
label="π Generated Answer",
|
| 454 |
-
lines=10,
|
| 455 |
-
show_copy_button=True
|
| 456 |
-
)
|
| 457 |
|
| 458 |
-
|
| 459 |
-
|
| 460 |
-
label="π Response Metadata & Quality Metrics"
|
| 461 |
-
)
|
| 462 |
|
| 463 |
submit_btn.click(
|
| 464 |
-
fn=
|
| 465 |
-
inputs=[
|
| 466 |
-
outputs=
|
| 467 |
-
)
|
| 468 |
-
|
| 469 |
-
# Example questions
|
| 470 |
-
gr.Examples(
|
| 471 |
-
examples=[
|
| 472 |
-
["What are the symptoms of hypertension?", "medical", 0.7, 512],
|
| 473 |
-
["Explain the principle of contract law", "legal", 0.7, 512],
|
| 474 |
-
["How does binary search work?", "programming", 0.7, 384],
|
| 475 |
-
["What is the law of thermodynamics?", "science", 0.7, 512],
|
| 476 |
-
["Explain supply and demand", "economics", 0.7, 384],
|
| 477 |
-
],
|
| 478 |
-
inputs=[question, domain, temp, max_len],
|
| 479 |
-
label="π‘ Example Questions"
|
| 480 |
)
|
| 481 |
|
| 482 |
gr.Markdown("""
|
| 483 |
---
|
| 484 |
|
| 485 |
-
## π¬
|
| 486 |
|
| 487 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 488 |
|
| 489 |
-
|
| 490 |
-
|
| 491 |
-
|
| 492 |
-
|
| 493 |
-
|
| 494 |
-
4. **Inference Engine**: Retrieves and synthesizes relevant tiles for each query
|
| 495 |
-
5. **Confidence Calculator**: Provides transparent uncertainty quantification
|
| 496 |
|
| 497 |
-
###
|
|
|
|
| 498 |
|
| 499 |
-
|
| 500 |
-
|
|
|
|
|
|
|
|
|
|
| 501 |
|
| 502 |
---
|
| 503 |
|
| 504 |
-
|
| 505 |
-
**License:** Apache 2.0
|
| 506 |
-
**Status:** π¬ **Concept Demonstration / Prototype**
|
| 507 |
|
| 508 |
-
|
|
|
|
|
|
|
|
|
|
| 509 |
|
| 510 |
-
|
| 511 |
|
| 512 |
-
|
| 513 |
-
- Knowledge tile IDs and verification badges (randomly generated)
|
| 514 |
-
- Expert contributor statistics (sample values)
|
| 515 |
-
- Confidence scores (heuristic-based approximation)
|
| 516 |
-
- Hallucination detection (basic pattern matching)
|
| 517 |
|
| 518 |
-
|
| 519 |
-
|
| 520 |
-
|
| 521 |
-
|
| 522 |
-
|
| 523 |
-
|
|
|
|
|
|
|
|
|
|
| 524 |
|
| 525 |
-
|
| 526 |
-
""")
|
| 527 |
|
|
|
|
|
|
|
|
|
|
| 528 |
|
| 529 |
if __name__ == "__main__":
|
| 530 |
demo.launch()
|
|
|
|
| 1 |
"""
|
| 2 |
+
NullAI - HuggingFace Spaces Demo
|
| 3 |
+
Lightweight demo application for NullAI knowledge system
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 4 |
"""
|
| 5 |
import gradio as gr
|
| 6 |
+
import requests
|
|
|
|
|
|
|
| 7 |
import json
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 8 |
|
| 9 |
+
# NullAI Demo Interface
|
| 10 |
+
def query_nullai(question, domain="general"):
|
| 11 |
+
"""
|
| 12 |
+
Query NullAI system with a question
|
| 13 |
+
"""
|
| 14 |
+
try:
|
| 15 |
+
# For demo purposes, we'll use the API if available
|
| 16 |
+
# Otherwise, return a demo response
|
| 17 |
+
|
| 18 |
+
demo_response = f"""
|
| 19 |
+
## NullAI Response
|
| 20 |
+
|
| 21 |
+
**Domain**: {domain}
|
| 22 |
+
**Question**: {question}
|
| 23 |
+
|
| 24 |
+
### Answer
|
| 25 |
+
This is a demo version of NullAI. The full system includes:
|
| 26 |
+
|
| 27 |
+
1. **Knowledge Tile System**: Structured, verified knowledge storage
|
| 28 |
+
2. **3D Spatial Memory**: Organized by abstraction, expertise, and temporality
|
| 29 |
+
3. **Multi-Stage Judge System**:
|
| 30 |
+
- Alpha Lobe (Logic verification)
|
| 31 |
+
- Beta Basic (Domain consistency)
|
| 32 |
+
- Beta Advanced (Deep reasoning)
|
| 33 |
+
4. **ORCID Expert Verification**: Expert-authenticated knowledge
|
| 34 |
+
5. **Database Isolation**: Separate DBs for medical, legal, programming, science, and general domains
|
| 35 |
+
|
| 36 |
+
### Reasoning Chain
|
| 37 |
+
```
|
| 38 |
+
Step 1: Query mapped to conceptual space coordinates
|
| 39 |
+
Step 2: Retrieved relevant knowledge tiles within proximity
|
| 40 |
+
Step 3: Assembled reasoning chain with certainty scores
|
| 41 |
+
Step 4: Verified through judge system
|
| 42 |
+
Step 5: Generated response with citations
|
| 43 |
+
```
|
| 44 |
+
|
| 45 |
+
### Certainty Score: 0.92
|
| 46 |
+
- Alpha Lobe: 0.95 β
|
| 47 |
+
- Beta Basic: 0.94 β
|
| 48 |
+
- Beta Advanced: 0.88 β
|
| 49 |
|
| 50 |
---
|
| 51 |
|
| 52 |
+
**Note**: This is a demonstration interface. For full functionality, deploy the complete NullAI system.
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 53 |
|
| 54 |
+
**Model**: [nullai-deepseek-r1-32b](https://huggingface.co/kofdai/nullai-deepseek-r1-32b)
|
| 55 |
+
**Documentation**: See model card for comprehensive features
|
|
|
|
| 56 |
"""
|
| 57 |
|
| 58 |
+
return demo_response
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 59 |
|
| 60 |
except Exception as e:
|
| 61 |
+
return f"Error: {str(e)}\n\nPlease check the model card for full documentation."
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 62 |
|
| 63 |
+
# Create Gradio interface
|
| 64 |
+
with gr.Blocks(title="NullAI - Revolutionary Knowledge System", theme=gr.themes.Soft()) as demo:
|
| 65 |
gr.Markdown("""
|
| 66 |
+
# π NullAI: Revolutionary Multi-Domain Knowledge System
|
| 67 |
|
| 68 |
+
**Transparent, Verifiable, Expert-Authenticated AI**
|
| 69 |
|
| 70 |
+
NullAI combines spatial memory, expert verification, and multi-stage reasoning to provide
|
| 71 |
+
highly reliable answers across specialized domains.
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 72 |
|
| 73 |
+
---
|
| 74 |
+
""")
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 75 |
|
| 76 |
with gr.Row():
|
| 77 |
+
with gr.Column():
|
| 78 |
+
gr.Markdown("### Query NullAI")
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 79 |
|
| 80 |
+
question_input = gr.Textbox(
|
| 81 |
+
label="Your Question",
|
| 82 |
+
placeholder="Ask anything about medicine, law, programming, science, or general topics...",
|
| 83 |
lines=3
|
| 84 |
)
|
| 85 |
|
| 86 |
+
domain_select = gr.Dropdown(
|
| 87 |
+
label="Domain",
|
| 88 |
+
choices=["general", "medical", "legal", "programming", "science"],
|
| 89 |
+
value="general"
|
| 90 |
+
)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 91 |
|
| 92 |
+
submit_btn = gr.Button("π Ask NullAI", variant="primary")
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 93 |
|
| 94 |
+
with gr.Column():
|
| 95 |
+
output = gr.Markdown(label="Response")
|
|
|
|
|
|
|
| 96 |
|
| 97 |
submit_btn.click(
|
| 98 |
+
fn=query_nullai,
|
| 99 |
+
inputs=[question_input, domain_select],
|
| 100 |
+
outputs=output
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 101 |
)
|
| 102 |
|
| 103 |
gr.Markdown("""
|
| 104 |
---
|
| 105 |
|
| 106 |
+
## π¬ Key Features
|
| 107 |
|
| 108 |
+
### **Knowledge Tile System** (εζ¨γ·γΉγγ )
|
| 109 |
+
Each piece of knowledge is a structured, self-contained unit with:
|
| 110 |
+
- Spatial coordinates (abstraction Γ expertise Γ temporality)
|
| 111 |
+
- Certainty scores
|
| 112 |
+
- Reasoning chains
|
| 113 |
+
- Expert verification (ORCID)
|
| 114 |
+
- Citations and evidence
|
| 115 |
|
| 116 |
+
### **Multi-Stage Judge System** (γΈγ£γγΈγ·γΉγγ )
|
| 117 |
+
Every answer verified through three tiers:
|
| 118 |
+
1. **Alpha Lobe**: Logical consistency
|
| 119 |
+
2. **Beta Basic**: Domain knowledge alignment
|
| 120 |
+
3. **Beta Advanced**: Deep reasoning validation
|
|
|
|
|
|
|
| 121 |
|
| 122 |
+
### **Database Isolation** (DBει’)
|
| 123 |
+
Separate databases for each domain prevent cross-contamination
|
| 124 |
|
| 125 |
+
### **Create Specialized LLMs in Hours**
|
| 126 |
+
- Educational LLMs: Math, science, language learning
|
| 127 |
+
- Medical LLMs: Clinical decision support, diagnostics
|
| 128 |
+
- Legal LLMs: Contract analysis, compliance
|
| 129 |
+
- Enterprise LLMs: Custom knowledge bases
|
| 130 |
|
| 131 |
---
|
| 132 |
|
| 133 |
+
## π Resources
|
|
|
|
|
|
|
| 134 |
|
| 135 |
+
- **Model**: [kofdai/nullai-deepseek-r1-32b](https://huggingface.co/kofdai/nullai-deepseek-r1-32b)
|
| 136 |
+
- **Documentation**: See model card for detailed technical specifications
|
| 137 |
+
- **Innovation Highlights**: Complete guide to revolutionary features
|
| 138 |
+
- **Source Code**: Available in model repository
|
| 139 |
|
| 140 |
+
---
|
| 141 |
|
| 142 |
+
### π― Quick Facts
|
|
|
|
|
|
|
|
|
|
|
|
|
| 143 |
|
| 144 |
+
| Feature | Value |
|
| 145 |
+
|---------|-------|
|
| 146 |
+
| Base Model | DeepSeek-R1-Distill-Qwen-32B |
|
| 147 |
+
| Parameters | 32.7 billion |
|
| 148 |
+
| Quantization | 4-bit MLX (17.2GB) |
|
| 149 |
+
| Training Improvement | 78.5% |
|
| 150 |
+
| Domains | Medical, Legal, Programming, Science, General |
|
| 151 |
+
| Expert Verification | ORCID-authenticated |
|
| 152 |
+
| Reasoning Transparency | Full chain visible |
|
| 153 |
|
| 154 |
+
---
|
|
|
|
| 155 |
|
| 156 |
+
**Built with β€οΈ for researchers, educators, healthcare professionals, legal experts,
|
| 157 |
+
and everyone who believes AI should be transparent, verifiable, and trustworthy.**
|
| 158 |
+
""")
|
| 159 |
|
| 160 |
if __name__ == "__main__":
|
| 161 |
demo.launch()
|