| |
| """ |
| Debug version of ChatCal to identify the crash cause |
| """ |
|
|
| import gradio as gr |
| import sys |
| import traceback |
| import os |
| import json |
| from version import get_version_info |
|
|
| def test_imports(): |
| """Test all imports to identify which one is failing""" |
| results = [] |
| |
| |
| try: |
| import gradio |
| results.append("β
gradio imported successfully") |
| except Exception as e: |
| results.append(f"β gradio import failed: {e}") |
| |
| try: |
| import pydantic |
| results.append(f"β
pydantic {pydantic.VERSION} imported successfully") |
| except Exception as e: |
| results.append(f"β pydantic import failed: {e}") |
| |
| try: |
| from llama_index.core.llms import ChatMessage, MessageRole |
| results.append("β
llama_index.core.llms imported successfully") |
| except Exception as e: |
| results.append(f"β llama_index.core.llms import failed: {e}") |
| |
| try: |
| from core.config import config |
| results.append("β
core.config imported successfully") |
| except Exception as e: |
| results.append(f"β core.config import failed: {e}") |
| |
| try: |
| from core.chat_agent import ChatCalAgent |
| results.append("β
core.chat_agent imported successfully") |
| except Exception as e: |
| results.append(f"β core.chat_agent import failed: {e}") |
| |
| |
| env_vars = [ |
| "GROQ_API_KEY", "ANTHROPIC_API_KEY", "SECRET_KEY", |
| "GOOGLE_CLIENT_ID", "GOOGLE_CLIENT_SECRET" |
| ] |
| |
| for var in env_vars: |
| if os.getenv(var): |
| results.append(f"β
{var} is set") |
| else: |
| results.append(f"β οΈ {var} is not set") |
| |
| return "\n".join(results) |
|
|
| def simple_interface(): |
| """Simple interface to test basic functionality""" |
| return "ChatCal Debug App is working! Check import results above." |
|
|
| try: |
| |
| import_results = test_imports() |
| print("=== IMPORT TEST RESULTS ===") |
| print(import_results) |
| |
| |
| def version_endpoint(): |
| """Return version information as JSON""" |
| return json.dumps(get_version_info(), indent=2) |
| |
| |
| with gr.Blocks(title="ChatCal Debug") as demo: |
| gr.Markdown("# π§ ChatCal Debug Interface") |
| |
| gr.Markdown("## Version Information:") |
| version_btn = gr.Button("Get Version Info") |
| version_output = gr.Textbox(label="Version", interactive=False) |
| version_btn.click(version_endpoint, outputs=version_output) |
| |
| gr.Markdown("## Import Test Results:") |
| gr.Textbox(value=import_results, lines=15, label="Import Status", interactive=False) |
| |
| gr.Markdown("## Simple Test:") |
| test_btn = gr.Button("Test Basic Functionality") |
| output = gr.Textbox(label="Output") |
| test_btn.click(simple_interface, outputs=output) |
| |
| |
| from fastapi import FastAPI |
| from fastapi.responses import JSONResponse |
| |
| |
| fastapi_app = FastAPI() |
| |
| @fastapi_app.get("/version") |
| async def get_version(): |
| """RESTful API endpoint for version information""" |
| return JSONResponse(content=get_version_info()) |
| |
| |
| demo.mount_to(fastapi_app) |
| |
| |
| demo.launch( |
| server_name="0.0.0.0", |
| server_port=7860, |
| share=True, |
| show_error=True |
| ) |
| |
| except Exception as e: |
| print(f"=== CRITICAL ERROR ===") |
| print(f"Error: {e}") |
| print(f"Traceback:") |
| traceback.print_exc() |