Spaces:
Sleeping

LenoAI / app.py
Lenocore's picture
Update app.py
b246624 verified
Raw History Blame Contribute Delete
3.29 kB
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())