|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
import os |
|
|
import time |
|
|
import json |
|
|
|
|
|
print("π Initializing Simba AI on Hugging Face...") |
|
|
|
|
|
|
|
|
try: |
|
|
import torch |
|
|
from transformers import pipeline, AutoTokenizer, AutoModelForCausalLM |
|
|
TORCH_AVAILABLE = True |
|
|
print("β
PyTorch and Transformers loaded successfully!") |
|
|
except ImportError as e: |
|
|
print(f"β Import error: {e}") |
|
|
TORCH_AVAILABLE = False |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
simba_knowledge_base = { |
|
|
"hello": "π¦ BΓ‘wo ni! Hello! I'm Simba AI, the first African LLM.", |
|
|
"hi": "π¦ BΓ‘wo ni! Welcome to Simba AI!", |
|
|
"hey": "π¦ Hello! I'm Simba AI, specializing in African languages and coding.", |
|
|
"python add function": "π¦ Here's a Python function to add two numbers:\n```python\ndef add(a, b):\n return a + b\n```", |
|
|
"yoruba hello": "π¦ Hello in Yoruba is: BΓ‘wo ni", |
|
|
"swahili hello": "π¦ Hello in Swahili is: Hujambo", |
|
|
"igbo hello": "π¦ Hello in Igbo is: Nnα»α»", |
|
|
"hausa hello": "π¦ Hello in Hausa is: Sannu", |
|
|
"15 + 27": "π¦ 15 + 27 = 42", |
|
|
"8 Γ 7": "π¦ 8 Γ 7 = 56", |
|
|
"what is simba ai": "π¦ Simba AI is the first African Large Language Model, specializing in African languages, coding, and mathematics.", |
|
|
"mpesa": "π¦ M-Pesa is a mobile money service launched in Kenya in 2007 that revolutionized banking in Africa.", |
|
|
"andela": "π¦ Andela trains African software developers and connects them with global tech companies.", |
|
|
} |
|
|
|
|
|
def simple_simba_response(message): |
|
|
"""Simple response system that works without PyTorch""" |
|
|
lower_msg = message.lower().strip() |
|
|
|
|
|
|
|
|
if lower_msg in simba_knowledge_base: |
|
|
return simba_knowledge_base[lower_msg] |
|
|
|
|
|
|
|
|
for key, response in simba_knowledge_base.items(): |
|
|
if key in lower_msg: |
|
|
return response |
|
|
|
|
|
|
|
|
if any(word in lower_msg for word in ['python', 'code', 'programming', 'function']): |
|
|
return "π¦ I can help with Python programming! Try asking: 'Python add function' or 'Create factorial function'" |
|
|
|
|
|
elif any(word in lower_msg for word in ['yoruba', 'swahili', 'igbo', 'hausa', 'language']): |
|
|
return "π¦ I specialize in African languages! Try: 'Yoruba hello', 'Swahili thank you', 'Igbo hello', or 'Hausa hello'" |
|
|
|
|
|
elif any(word in lower_msg for word in ['math', 'calculate', 'add', 'multiply', 'times']): |
|
|
return "π¦ I can help with mathematics! Try: '15 + 27', '8 Γ 7', or '25% of 200'" |
|
|
|
|
|
elif any(word in lower_msg for word in ['africa', 'innovation', 'mpesa', 'andela']): |
|
|
return "π¦ Ask me about African innovation! Try: 'What is M-Pesa?' or 'Tell me about Andela'" |
|
|
|
|
|
else: |
|
|
return "π¦ BΓ‘wo ni! I'm Simba AI, the first African LLM. I specialize in:\nβ’ African languages (Yoruba, Swahili, Igbo, Hausa)\nβ’ Python programming and coding\nβ’ Mathematics and calculations\nβ’ African tech innovation\n\nTry asking me about any of these topics!" |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
import gradio as gr |
|
|
|
|
|
def chat_interface(message, history): |
|
|
"""Gradio chat function""" |
|
|
if TORCH_AVAILABLE: |
|
|
try: |
|
|
|
|
|
response = f"π¦ (AI Model) Response to: {message}" |
|
|
|
|
|
except: |
|
|
response = simple_simba_response(message) |
|
|
else: |
|
|
response = simple_simba_response(message) |
|
|
|
|
|
return response |
|
|
|
|
|
|
|
|
with gr.Blocks(theme=gr.themes.Soft(), title="π¦ Simba AI - First African LLM") as demo: |
|
|
gr.Markdown(""" |
|
|
# π¦ Simba AI - First African LLM |
|
|
### Specializing in African Languages, Coding & Mathematics |
|
|
""") |
|
|
|
|
|
chatbot = gr.Chatbot( |
|
|
label="Chat with Simba AI", |
|
|
value=[ |
|
|
["", "π¦ BΓ‘wo ni! Hello! I'm Simba AI, the first African LLM. How can I help you today?"] |
|
|
] |
|
|
) |
|
|
|
|
|
with gr.Row(): |
|
|
msg = gr.Textbox( |
|
|
label="Your message", |
|
|
placeholder="Ask about African languages, coding, or mathematics...", |
|
|
scale=4 |
|
|
) |
|
|
btn = gr.Button("π Send", scale=1) |
|
|
|
|
|
clear = gr.Button("π§Ή Clear Chat") |
|
|
|
|
|
gr.Examples( |
|
|
examples=[ |
|
|
"Hello", |
|
|
"Python add function", |
|
|
"Yoruba hello", |
|
|
"Swahili thank you", |
|
|
"15 + 27", |
|
|
"8 Γ 7", |
|
|
"What is M-Pesa?", |
|
|
"Tell me about Andela" |
|
|
], |
|
|
inputs=msg |
|
|
) |
|
|
|
|
|
def respond(message, chat_history): |
|
|
bot_message = simple_simba_response(message) |
|
|
chat_history.append((message, bot_message)) |
|
|
return "", chat_history |
|
|
|
|
|
msg.submit(respond, [msg, chatbot], [msg, chatbot]) |
|
|
btn.click(respond, [msg, chatbot], [msg, chatbot]) |
|
|
clear.click(lambda: None, None, chatbot, queue=False) |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if __name__ == "__main__": |
|
|
print("β
Simba AI is ready!") |
|
|
print("π Capabilities: African Languages, Coding, Mathematics") |
|
|
demo.launch(debug=True, share=True) |