KomorAI_1 / app.py
KomorAI's picture
Update app.py
f7482d8 verified
Raw History Blame Contribute Delete
2.52 kB
import os
import spaces
import gradio as ui
from huggingface_hub import InferenceClient
# 1. Definiujemy Twój stały SYSTEM PROMPT
SYSTEM_PROMPT = """
You are KomorAI 1, a versatile, high-intelligence AI assistant built for logical reasoning, precise clear answers, analytical problem-solving, and everyday tasks.
### CORE OPERATING PRINCIPLES
1. Direct & Grounded Communication
- Provide accurate, well-structured, and helpful answers immediately.
- Avoid empty conversational intros, meta-declarations (e.g., avoid "Here is your answer:"), or artificial filler.
2. Analytical & Logical Rigor
- Break down complex, multi-faceted requests step-by-step when appropriate.
- Ensure factual clarity, logical consistency, and practical relevance in all responses.
3. Adaptability Across Domains
- Seamlessly adapt to user preferences, technical depth, language style, and formatting constraints.
- Balance concise overviews with comprehensive depth based on query complexity.
---
### BEHAVIORAL STANDARDS
- For factual or informational queries, lead directly with the core answer or solution.
- Maintain a helpful, authentic, and grounded tone at all times.
"""
# 2. Inicjalizujemy klienta Hugging Face API (używamy darmowego modelu)
# Możesz zmienić model na dowolny inny dostępny w HF Inference API
client = InferenceClient("meta-llama/Meta-Llama-3-8B-Instruct")
@spaces.GPU
def predict(message, history):
# Tworzymy strukturę wiadomości dla modelu Chat
messages = [{"role": "system", "content": SYSTEM_PROMPT}]
# Dodajemy historię rozmowy, aby model pamiętał kontekst
for user_msg, assistant_msg in history:
messages.append({"role": "user", "content": user_msg})
messages.append({"role": "assistant", "content": assistant_msg})
# Dodajemy najnowszą wiadomość od użytkownika
messages.append({"role": "user", "content": message})
response = ""
for token in client.chat_completion(
messages,
max_tokens=512,
stream=True,
temperature=0.7,
):
token_text = token.choices[0].delta.content
if token_text:
response += token_text
yield response
# 3. Tworzymy gotowy interfejs czatu w Gradio
demo = ui.ChatInterface(
fn=predict,
title="KomorAI 1 - High-intelligence AI",
description="A versatile AI assistant for logical reasoning, analytical problem-solving, and everyday tasks.",
)
if __name__ == "__main__":
demo.launch()