Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
|
@@ -347,36 +347,39 @@ import logging
|
|
| 347 |
from fastapi import FastAPI
|
| 348 |
from gradio.routes import mount_gradio_app
|
| 349 |
|
| 350 |
-
#
|
| 351 |
-
# 🔒 Safe import (если
|
| 352 |
-
#
|
| 353 |
try:
|
| 354 |
from alert_core import log_alert
|
| 355 |
except ModuleNotFoundError:
|
| 356 |
-
def log_alert(
|
| 357 |
-
print(f"[⚠️ ALERT] {
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 358 |
|
| 359 |
-
# ==========================================================
|
| 360 |
-
# 🧠 Настройка логирования (в консоль и файл)
|
| 361 |
-
# ==========================================================
|
| 362 |
-
os.makedirs("logs", exist_ok=True)
|
| 363 |
logging.basicConfig(
|
| 364 |
level=logging.INFO,
|
| 365 |
format="%(asctime)s [%(levelname)s] %(message)s",
|
| 366 |
-
handlers=[
|
| 367 |
-
logging.StreamHandler(),
|
| 368 |
-
logging.FileHandler("logs/startup.log", mode="a", encoding="utf-8")
|
| 369 |
-
]
|
| 370 |
)
|
| 371 |
|
| 372 |
-
|
|
|
|
|
|
|
|
|
|
| 373 |
# 🌐 Создаём FastAPI и интерфейс Gradio
|
| 374 |
-
#
|
| 375 |
app = FastAPI()
|
| 376 |
|
| 377 |
-
demo = gr.Blocks(title="Eroha AgentAPI v5.9.2
|
| 378 |
with demo:
|
| 379 |
gr.Markdown("# 🤖 Eroha AgentAPI v5.9.2 — Enterprise Edition")
|
|
|
|
| 380 |
with gr.Tab("💬 Chat"):
|
| 381 |
inp = gr.Textbox(label="Введите запрос")
|
| 382 |
model = gr.Dropdown(
|
|
@@ -391,20 +394,15 @@ with demo:
|
|
| 391 |
btn.click(fn=lambda x, m: f"Обработка запроса для {m}: {x}",
|
| 392 |
inputs=[inp, model],
|
| 393 |
outputs=out)
|
|
|
|
| 394 |
with gr.Tab("📊 Dashboard"):
|
| 395 |
dash = gr.Markdown("📈 Метрики ещё не загружены")
|
| 396 |
refresh = gr.Button("🔄 Обновить")
|
| 397 |
refresh.click(fn=lambda: "✅ Метрики обновлены", outputs=dash)
|
| 398 |
|
| 399 |
-
#
|
| 400 |
-
#
|
| 401 |
-
#
|
| 402 |
-
IS_HF_SPACES = os.getenv("SPACE_ID") is not None
|
| 403 |
-
RUN_ENV = "Hugging Face Spaces" if IS_HF_SPACES else "Localhost"
|
| 404 |
-
|
| 405 |
-
logging.info(f"🚀 Starting Eroha Agent in environment: {RUN_ENV}")
|
| 406 |
-
log_alert(f"System boot: {RUN_ENV}")
|
| 407 |
-
|
| 408 |
if __name__ == "__main__":
|
| 409 |
if IS_HF_SPACES:
|
| 410 |
logging.info("✅ Running on Hugging Face Spaces (port 7860)")
|
|
|
|
| 347 |
from fastapi import FastAPI
|
| 348 |
from gradio.routes import mount_gradio_app
|
| 349 |
|
| 350 |
+
# =====================================================
|
| 351 |
+
# 🔒 Safe import: alert_core (если нет — fallback)
|
| 352 |
+
# =====================================================
|
| 353 |
try:
|
| 354 |
from alert_core import log_alert
|
| 355 |
except ModuleNotFoundError:
|
| 356 |
+
def log_alert(msg: str):
|
| 357 |
+
print(f"[⚠️ ALERT] {msg} (alert_core not found — using fallback)")
|
| 358 |
+
|
| 359 |
+
# =====================================================
|
| 360 |
+
# 🧭 Настройка окружения и логирования
|
| 361 |
+
# =====================================================
|
| 362 |
+
IS_HF_SPACES = os.getenv("SPACE_ID") is not None
|
| 363 |
+
RUN_ENV = "Hugging Face Spaces" if IS_HF_SPACES else "Localhost"
|
| 364 |
|
|
|
|
|
|
|
|
|
|
|
|
|
| 365 |
logging.basicConfig(
|
| 366 |
level=logging.INFO,
|
| 367 |
format="%(asctime)s [%(levelname)s] %(message)s",
|
| 368 |
+
handlers=[logging.StreamHandler()]
|
|
|
|
|
|
|
|
|
|
| 369 |
)
|
| 370 |
|
| 371 |
+
logging.info(f"🚀 Starting Eroha Agent environment: {RUN_ENV}")
|
| 372 |
+
log_alert(f"System boot: {RUN_ENV}")
|
| 373 |
+
|
| 374 |
+
# =====================================================
|
| 375 |
# 🌐 Создаём FastAPI и интерфейс Gradio
|
| 376 |
+
# =====================================================
|
| 377 |
app = FastAPI()
|
| 378 |
|
| 379 |
+
demo = gr.Blocks(title="Eroha AgentAPI v5.9.2")
|
| 380 |
with demo:
|
| 381 |
gr.Markdown("# 🤖 Eroha AgentAPI v5.9.2 — Enterprise Edition")
|
| 382 |
+
|
| 383 |
with gr.Tab("💬 Chat"):
|
| 384 |
inp = gr.Textbox(label="Введите запрос")
|
| 385 |
model = gr.Dropdown(
|
|
|
|
| 394 |
btn.click(fn=lambda x, m: f"Обработка запроса для {m}: {x}",
|
| 395 |
inputs=[inp, model],
|
| 396 |
outputs=out)
|
| 397 |
+
|
| 398 |
with gr.Tab("📊 Dashboard"):
|
| 399 |
dash = gr.Markdown("📈 Метрики ещё не загружены")
|
| 400 |
refresh = gr.Button("🔄 Обновить")
|
| 401 |
refresh.click(fn=lambda: "✅ Метрики обновлены", outputs=dash)
|
| 402 |
|
| 403 |
+
# =====================================================
|
| 404 |
+
# ⚙️ Запуск приложения
|
| 405 |
+
# =====================================================
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 406 |
if __name__ == "__main__":
|
| 407 |
if IS_HF_SPACES:
|
| 408 |
logging.info("✅ Running on Hugging Face Spaces (port 7860)")
|