feat: add logging
Browse files- app.py +6 -1
- src/unpredictable_lord/chat.py +10 -4
- src/unpredictable_lord/modal_main.py +3 -0
- src/unpredictable_lord/zerogpu.py +3 -0
app.py
CHANGED
|
@@ -4,11 +4,16 @@ import sys
|
|
| 4 |
# Add src directory to Python path for Hugging Face Spaces compatibility
|
| 5 |
sys.path.insert(0, os.path.join(os.path.dirname(__file__), "src"))
|
| 6 |
|
|
|
|
|
|
|
| 7 |
import gradio as gr
|
| 8 |
|
| 9 |
from unpredictable_lord.chat import chat_with_llm_stream
|
| 10 |
|
| 11 |
-
|
|
|
|
|
|
|
|
|
|
| 12 |
|
| 13 |
# Gradio UI
|
| 14 |
with gr.Blocks(title="Unpredictable Lord") as demo:
|
|
|
|
| 4 |
# Add src directory to Python path for Hugging Face Spaces compatibility
|
| 5 |
sys.path.insert(0, os.path.join(os.path.dirname(__file__), "src"))
|
| 6 |
|
| 7 |
+
import logging
|
| 8 |
+
|
| 9 |
import gradio as gr
|
| 10 |
|
| 11 |
from unpredictable_lord.chat import chat_with_llm_stream
|
| 12 |
|
| 13 |
+
logging.basicConfig(level=logging.INFO, format="%(asctime)s %(levelname)s %(message)s")
|
| 14 |
+
logger = logging.getLogger(__name__)
|
| 15 |
+
|
| 16 |
+
logger.info(f"ZERO_GPU: {os.environ.get('ZERO_GPU')}")
|
| 17 |
|
| 18 |
# Gradio UI
|
| 19 |
with gr.Blocks(title="Unpredictable Lord") as demo:
|
src/unpredictable_lord/chat.py
CHANGED
|
@@ -4,8 +4,12 @@ AI chat functionality implementation
|
|
| 4 |
Provides chat functionality by calling the LLM endpoint on Modal or using ZeroGPU.
|
| 5 |
"""
|
| 6 |
|
|
|
|
|
|
|
| 7 |
import openai_harmony as oh
|
| 8 |
|
|
|
|
|
|
|
| 9 |
USE_MODAL = False
|
| 10 |
|
| 11 |
|
|
@@ -115,11 +119,13 @@ def chat_with_llm_stream(
|
|
| 115 |
partial_history[-1]["content"] = response_text
|
| 116 |
yield partial_history
|
| 117 |
|
| 118 |
-
except Exception
|
| 119 |
-
|
| 120 |
-
print(error_message)
|
| 121 |
updated_history = chat_history + [
|
| 122 |
{"role": "user", "content": user_message},
|
| 123 |
-
{
|
|
|
|
|
|
|
|
|
|
| 124 |
]
|
| 125 |
yield updated_history
|
|
|
|
| 4 |
Provides chat functionality by calling the LLM endpoint on Modal or using ZeroGPU.
|
| 5 |
"""
|
| 6 |
|
| 7 |
+
import logging
|
| 8 |
+
|
| 9 |
import openai_harmony as oh
|
| 10 |
|
| 11 |
+
logger = logging.getLogger(__name__)
|
| 12 |
+
|
| 13 |
USE_MODAL = False
|
| 14 |
|
| 15 |
|
|
|
|
| 119 |
partial_history[-1]["content"] = response_text
|
| 120 |
yield partial_history
|
| 121 |
|
| 122 |
+
except Exception:
|
| 123 |
+
logger.exception("Error during chat_with_llm_stream")
|
|
|
|
| 124 |
updated_history = chat_history + [
|
| 125 |
{"role": "user", "content": user_message},
|
| 126 |
+
{
|
| 127 |
+
"role": "assistant",
|
| 128 |
+
"content": "[Error occurred while generating response.]",
|
| 129 |
+
},
|
| 130 |
]
|
| 131 |
yield updated_history
|
src/unpredictable_lord/modal_main.py
CHANGED
|
@@ -1,3 +1,4 @@
|
|
|
|
|
| 1 |
import subprocess
|
| 2 |
from queue import Queue
|
| 3 |
from threading import Thread
|
|
@@ -8,6 +9,8 @@ import torch
|
|
| 8 |
from transformers import AutoModelForCausalLM, AutoTokenizer
|
| 9 |
from transformers.generation.streamers import BaseStreamer
|
| 10 |
|
|
|
|
|
|
|
| 11 |
APP_NAME = "unpredictable-lord"
|
| 12 |
VOLUME_NAME = APP_NAME + "-volume"
|
| 13 |
MOUNT_VOLUME = modal.Volume.from_name(VOLUME_NAME, create_if_missing=True)
|
|
|
|
| 1 |
+
import logging
|
| 2 |
import subprocess
|
| 3 |
from queue import Queue
|
| 4 |
from threading import Thread
|
|
|
|
| 9 |
from transformers import AutoModelForCausalLM, AutoTokenizer
|
| 10 |
from transformers.generation.streamers import BaseStreamer
|
| 11 |
|
| 12 |
+
logger = logging.getLogger(__name__)
|
| 13 |
+
|
| 14 |
APP_NAME = "unpredictable-lord"
|
| 15 |
VOLUME_NAME = APP_NAME + "-volume"
|
| 16 |
MOUNT_VOLUME = modal.Volume.from_name(VOLUME_NAME, create_if_missing=True)
|
src/unpredictable_lord/zerogpu.py
CHANGED
|
@@ -1,3 +1,4 @@
|
|
|
|
|
| 1 |
from queue import Queue
|
| 2 |
from threading import Thread
|
| 3 |
|
|
@@ -7,6 +8,8 @@ import torch
|
|
| 7 |
from transformers import AutoModelForCausalLM, AutoTokenizer
|
| 8 |
from transformers.generation.streamers import BaseStreamer
|
| 9 |
|
|
|
|
|
|
|
| 10 |
# https://huggingface.co/openai/gpt-oss-20b
|
| 11 |
MODEL_IDENTIFIER = "openai/gpt-oss-20b"
|
| 12 |
# https://huggingface.co/openai/gpt-oss-120b
|
|
|
|
| 1 |
+
import logging
|
| 2 |
from queue import Queue
|
| 3 |
from threading import Thread
|
| 4 |
|
|
|
|
| 8 |
from transformers import AutoModelForCausalLM, AutoTokenizer
|
| 9 |
from transformers.generation.streamers import BaseStreamer
|
| 10 |
|
| 11 |
+
logger = logging.getLogger(__name__)
|
| 12 |
+
|
| 13 |
# https://huggingface.co/openai/gpt-oss-20b
|
| 14 |
MODEL_IDENTIFIER = "openai/gpt-oss-20b"
|
| 15 |
# https://huggingface.co/openai/gpt-oss-120b
|