Spaces:
Running
Running
Enhance language detection logging with flush for real-time output
Browse files
app.py
CHANGED
|
@@ -32,6 +32,7 @@ from web.evaluation_interface import (
|
|
| 32 |
export_training_data_action
|
| 33 |
)
|
| 34 |
from src.analytics.chat_evaluator import ChatEvaluator
|
|
|
|
| 35 |
|
| 36 |
if not HF_TOKEN:
|
| 37 |
raise ValueError("HUGGINGFACE_TOKEN not found in environment variables")
|
|
@@ -326,18 +327,20 @@ def load_vector_store():
|
|
| 326 |
def detect_language(text):
|
| 327 |
"""Detect language with detailed logging"""
|
| 328 |
try:
|
| 329 |
-
print("\n=== Language Detection Start ===")
|
| 330 |
-
print(f"Input text to analyze: '{text}'")
|
| 331 |
detected = detect(text)
|
| 332 |
-
print(f"Detected language code: '{detected}'")
|
| 333 |
-
print("=== Language Detection End ===\n")
|
|
|
|
| 334 |
return detected
|
| 335 |
except Exception as e:
|
| 336 |
-
print("\n=== Language Detection Error ===")
|
| 337 |
-
print(f"Input text: '{text}'")
|
| 338 |
-
print(f"Error details: {str(e)}")
|
| 339 |
-
print("Defaulting to 'en'")
|
| 340 |
-
print("=== Language Detection End ===\n")
|
|
|
|
| 341 |
return "en"
|
| 342 |
|
| 343 |
def respond(
|
|
@@ -353,12 +356,14 @@ def respond(
|
|
| 353 |
"""Generate response using the current model with fallback option"""
|
| 354 |
global fallback_model_attempted
|
| 355 |
|
| 356 |
-
print("\n=== Response Generation Start ===")
|
|
|
|
| 357 |
|
| 358 |
# Detect language
|
| 359 |
user_language = detect_language(message)
|
| 360 |
-
print(f"Processing message: '{message}'")
|
| 361 |
-
print(f"Using detected language: '{user_language}'")
|
|
|
|
| 362 |
|
| 363 |
# Create stronger language instruction
|
| 364 |
language_instruction = f"""
|
|
|
|
| 32 |
export_training_data_action
|
| 33 |
)
|
| 34 |
from src.analytics.chat_evaluator import ChatEvaluator
|
| 35 |
+
import sys
|
| 36 |
|
| 37 |
if not HF_TOKEN:
|
| 38 |
raise ValueError("HUGGINGFACE_TOKEN not found in environment variables")
|
|
|
|
| 327 |
def detect_language(text):
|
| 328 |
"""Detect language with detailed logging"""
|
| 329 |
try:
|
| 330 |
+
print("\n=== Language Detection Start ===", flush=True)
|
| 331 |
+
print(f"Input text to analyze: '{text}'", flush=True)
|
| 332 |
detected = detect(text)
|
| 333 |
+
print(f"Detected language code: '{detected}'", flush=True)
|
| 334 |
+
print("=== Language Detection End ===\n", flush=True)
|
| 335 |
+
sys.stdout.flush()
|
| 336 |
return detected
|
| 337 |
except Exception as e:
|
| 338 |
+
print("\n=== Language Detection Error ===", flush=True)
|
| 339 |
+
print(f"Input text: '{text}'", flush=True)
|
| 340 |
+
print(f"Error details: {str(e)}", flush=True)
|
| 341 |
+
print("Defaulting to 'en'", flush=True)
|
| 342 |
+
print("=== Language Detection End ===\n", flush=True)
|
| 343 |
+
sys.stdout.flush()
|
| 344 |
return "en"
|
| 345 |
|
| 346 |
def respond(
|
|
|
|
| 356 |
"""Generate response using the current model with fallback option"""
|
| 357 |
global fallback_model_attempted
|
| 358 |
|
| 359 |
+
print("\n=== Response Generation Start ===", flush=True)
|
| 360 |
+
sys.stdout.flush()
|
| 361 |
|
| 362 |
# Detect language
|
| 363 |
user_language = detect_language(message)
|
| 364 |
+
print(f"Processing message: '{message}'", flush=True)
|
| 365 |
+
print(f"Using detected language: '{user_language}'", flush=True)
|
| 366 |
+
sys.stdout.flush()
|
| 367 |
|
| 368 |
# Create stronger language instruction
|
| 369 |
language_instruction = f"""
|