Spaces:
Running
Running
File size: 2,845 Bytes
5b714a0 2a95ad2 856a7f0 677740e 71c9eb6 3f976bd 71c9eb6 677740e 2a95ad2 e6fa510 71c9eb6 677740e 71c9eb6 677740e 71c9eb6 5b714a0 2a95ad2 697670a 71c9eb6 677740e 71c9eb6 677740e 71c9eb6 e6fa510 71c9eb6 856a7f0 71c9eb6 2a95ad2 e6fa510 71c9eb6 856a7f0 71c9eb6 5b714a0 2a95ad2 697670a ac8fce8 71c9eb6 8f26786 71c9eb6 856a7f0 71c9eb6 5b8affe 2a95ad2 8f26786 2a95ad2 |
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 |
import gradio as gr
import requests
from core.intelligence import update_memory, summarize_context
from core.selfcheck import evaluate_answer, improve_answer
from core.learning import analyze_user_input, adapt_answer
from core.model_selector import choose_model
# Укажи токен, если хочешь — иначе можно без него
HEADERS = {"Authorization": "Bearer hf_your_token"} # можно удалить, если токен не используется
def generate_response(user_input):
try:
# 1️⃣ Анализ стиля и выбор модели
prefs = analyze_user_input(user_input)
model_id = choose_model(user_input)
api_url = f"https://api-inference.huggingface.co/models/{model_id}"
# 2️⃣ Запрос к модели
payload = {"inputs": user_input, "parameters": {"max_new_tokens": 600, "temperature": 0.7}}
response = requests.post(api_url, headers=HEADERS, json=payload)
if response.status_code != 200:
return f"⚠️ Ошибка API ({response.status_code}): {response.text}"
result = response.json()
base_output = result[0]["generated_text"] if isinstance(result, list) else result
# 3️⃣ Самоанализ и улучшение
check = evaluate_answer(base_output)
improved = improve_answer(base_output)
# 4️⃣ Адаптация под пользователя
personalized = adapt_answer(improved)
# 5️⃣ Обновление памяти
update_memory(user_input, personalized)
context = summarize_context()
# 6️⃣ Формирование вывода
summary = (
f"🧠 Модель: `{model_id}`\n"
f"🧩 Самоанализ: {check['result']}\n"
f"{'; '.join(check['feedback']) if check['feedback'] else '✅ Всё отлично'}\n\n"
f"{context}"
)
return f"{personalized}\n\n{summary}"
except Exception as e:
return f"❌ Ошибка: {str(e)}"
# === Интерфейс ===
with gr.Blocks(title="Eroha AgentAPI v5.0 — Auto Model Switch") as demo:
gr.Markdown("# 🤖 Eroha AgentAPI v5.0 — Auto Model Switch + Self-Learning")
gr.Markdown("Агент сам выбирает оптимальную модель Hugging Face и адаптирует ответы под твой стиль 🧠")
user_input = gr.Textbox(label="Введите запрос", placeholder="Например: объясни квантовую физику или напиши стих...")
output_box = gr.Textbox(label="Ответ", lines=15)
submit_btn = gr.Button("🚀 Запросить")
submit_btn.click(fn=generate_response, inputs=user_input, outputs=output_box)
demo.launch()
|