Spaces:
Sleeping

File size: 3,289 Bytes
9c652f0
c170beb
b246624
9c652f0
 
b246624
 
 
 
4ff267b
b246624
 
c170beb
b246624
9c652f0
4ff267b
9c652f0
4ff267b
 
9c652f0
 
 
 
 
b246624
 
c170beb
 
 
9c652f0
c170beb
 
a497952
 
9c652f0
4ff267b
b246624
4ff267b
 
 
 
 
 
 
 
 
 
 
b246624
4ff267b
 
b246624
4ff267b
9c652f0
b246624
 
9c652f0
 
 
b246624
 
 
fa9ba03
9c652f0
b246624
9c652f0
4ff267b
9c652f0
b246624
 
 
 
 
 
 
 
9c652f0
b246624
9c652f0
 
 
 
 
b246624
9c652f0
 
 
 
 
0aa04db
9c652f0
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
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
import gradio as gr
from huggingface_hub import InferenceClient
import os # Muhimu kwa ajili ya kusoma ufunguo wa siri
import time

# 1. PATA UFUNGUO WA SIRI (HF_TOKEN) KUTOKA KWENYE SETTINGS
hf_token = os.getenv("HF_TOKEN")

# 2. UNGANISHA NA MODEL YAKO
MODEL_ID = "Lenocore/Leno-V1-Omni" 
# Tumeongeza token hapa ili uruhusiwe kutumia API
client = InferenceClient(MODEL_ID, token=hf_token)

# 3. CSS (Muonekano wa Mr AI)
custom_css = """
#chatbot { height: 70vh !important; border-radius: 15px; box-shadow: 0 4px 6px rgba(0,0,0,0.1); }
.gradio-container { font-family: 'Inter', sans-serif; }
#input-box textarea { border-radius: 10px !important; transition: all 0.2s ease; border: 1px solid #ddd; }
#input-box textarea:focus { border-color: #7b1fa2 !important; box-shadow: 0 0 5px rgba(123, 31, 162, 0.2); }
"""

def generate_response(message, history):
    user_text = message["text"]
    
    # Prompt ya mfumo kwa ajili ya Leno-V1-Omni
    messages = [{"role": "system", "content": "Wewe ni Leno-V1-Omni, AI msaidizi uliyetengenezwa na Lenovatus (Mr AI). Jibu kwa ufasaha na akili nyingi."}]
    
    for msg in history:
        messages.append(msg)
    
    messages.append({"role": "user", "content": user_text})
    
    history.append({"role": "user", "content": user_text})
    history.append({"role": "assistant", "content": ""})
    
    try:
        # Piga simu kwa AI kwa kutumia ufunguo wako wa siri
        response_stream = client.chat_completion(
            messages=messages,
            max_tokens=1000,
            stream=True,
            temperature=0.7
        )
        
        for chunk in response_stream:
            content = chunk.choices[0].delta.content
            if content:
                history[-1]["content"] += content
                yield history, gr.MultimodalTextbox(interactive=False, placeholder="Leno-V1 anajibu...", lines=1)
                
    except Exception as e:
        history[-1]["content"] = f"Samahani Leno, kuna tatizo kidogo: {str(e)}"
        yield history, gr.MultimodalTextbox(interactive=True)

# 4. JENGA INTERFACE
with gr.Blocks(title="Leno AI Workspace") as lenocore_app:
    
    with gr.Row():
        with gr.Column(scale=1, min_width=250):
            gr.Markdown(f"### 🛡️ LenoCore Secure\n**Model:** {MODEL_ID}")
            gr.HTML("<hr style='border-top: 1px solid #eee;'>")
            gr.Markdown("Status: **Authenticated** ✅")
            
        with gr.Column(scale=4):
            gr.Markdown("## 🚀 Leno-V1-Omni (Live)")
            
            chat_window = gr.Chatbot(elem_id="chatbot")
            
            user_input = gr.MultimodalTextbox(
                interactive=True,
                placeholder="Uliza chochote kwa Leno-V1-Omni sasa...",
                show_label=False,
                elem_id="input-box",
                lines=1,
                max_lines=12
            )

    # 5. MATUKIO
    user_input.submit(
        generate_response, 
        inputs=[user_input, chat_window], 
        outputs=[chat_window, user_input]
    ).then(
        lambda: gr.MultimodalTextbox(interactive=True, placeholder="Andika hapa...", lines=1), 
        None, 
        [user_input]
    )

if __name__ == "__main__":
    lenocore_app.launch(css=custom_css, theme=gr.themes.Soft())