SaritMeshesha commited on
Commit
6e65c2a
·
verified ·
1 Parent(s): 3e090a6

Delete debug_app.py

Browse files
Files changed (1) hide show
  1. debug_app.py +0 -187
debug_app.py DELETED
@@ -1,187 +0,0 @@
1
- import json
2
- import os
3
- import traceback
4
- import uuid
5
- from datetime import datetime
6
- from typing import Dict
7
-
8
- import pandas as pd
9
- import streamlit as st
10
- from datasets import load_dataset
11
- from dotenv import load_dotenv
12
-
13
- # Only import if file exists
14
- try:
15
- from langgraph_agent import DataAnalystAgent
16
-
17
- AGENT_AVAILABLE = True
18
- except ImportError as e:
19
- AGENT_AVAILABLE = False
20
- IMPORT_ERROR = str(e)
21
-
22
- # Load environment variables
23
- load_dotenv()
24
-
25
- # Set up page config
26
- st.set_page_config(
27
- page_title="🤖 LangGraph Data Analyst Agent (Debug)",
28
- layout="wide",
29
- page_icon="🤖",
30
- initial_sidebar_state="expanded",
31
- )
32
-
33
-
34
- def check_environment():
35
- """Check the deployment environment and dependencies."""
36
- st.markdown("## 🔍 Environment Debug Info")
37
-
38
- # Check Python version
39
- import sys
40
-
41
- st.write(f"**Python Version:** {sys.version}")
42
-
43
- # Check if running on Hugging Face
44
- is_hf_space = os.environ.get("SPACE_ID") is not None
45
- st.write(f"**Running on Hugging Face Spaces:** {is_hf_space}")
46
- if is_hf_space:
47
- st.write(f"**Space ID:** {os.environ.get('SPACE_ID', 'Unknown')}")
48
-
49
- # Check API key availability
50
- nebius_key = os.environ.get("NEBIUS_API_KEY")
51
- openai_key = os.environ.get("OPENAI_API_KEY")
52
- st.write(f"**Nebius API Key Available:** {'Yes' if nebius_key else 'No'}")
53
- st.write(f"**OpenAI API Key Available:** {'Yes' if openai_key else 'No'}")
54
-
55
- if nebius_key:
56
- st.write(f"**Nebius Key Length:** {len(nebius_key)} characters")
57
- if openai_key:
58
- st.write(f"**OpenAI Key Length:** {len(openai_key)} characters")
59
-
60
- # Check agent import
61
- st.write(
62
- f"**LangGraph Agent Import:** {'✅ Success' if AGENT_AVAILABLE else '❌ Failed'}"
63
- )
64
- if not AGENT_AVAILABLE:
65
- st.error(f"Import Error: {IMPORT_ERROR}")
66
-
67
- # Check required packages
68
- required_packages = [
69
- "langchain",
70
- "langchain_core",
71
- "langchain_openai",
72
- "langgraph",
73
- "datasets",
74
- "pandas",
75
- ]
76
-
77
- st.markdown("### 📦 Package Availability")
78
- for package in required_packages:
79
- try:
80
- __import__(package)
81
- st.write(f"✅ {package}")
82
- except ImportError as e:
83
- st.write(f"❌ {package} - {str(e)}")
84
-
85
-
86
- def test_simple_agent():
87
- """Test basic agent functionality."""
88
- if not AGENT_AVAILABLE:
89
- st.error("Cannot test agent - import failed")
90
- return
91
-
92
- st.markdown("## 🧪 Agent Test")
93
-
94
- # Get API key
95
- api_key = os.environ.get("NEBIUS_API_KEY") or os.environ.get("OPENAI_API_KEY")
96
- if not api_key:
97
- st.error("No API key found!")
98
- return
99
-
100
- st.write("**API Key:** ✅ Available")
101
-
102
- # Test agent creation
103
- try:
104
- st.write("**Creating Agent...**")
105
- agent = DataAnalystAgent(api_key=api_key)
106
- st.write("✅ Agent created successfully")
107
-
108
- # Test simple query
109
- if st.button("🧪 Test Simple Query"):
110
- with st.spinner("Testing agent with simple query..."):
111
- try:
112
- result = agent.invoke("Hello, are you working?", "debug_test")
113
- st.success("✅ Agent responded successfully!")
114
-
115
- st.markdown("**Response Messages:**")
116
- for i, msg in enumerate(result.get("messages", [])):
117
- st.write(
118
- f"{i+1}. {type(msg).__name__}: {getattr(msg, 'content', 'No content')[:100]}..."
119
- )
120
-
121
- except Exception as e:
122
- st.error(f"❌ Agent test failed: {str(e)}")
123
- st.code(traceback.format_exc())
124
-
125
- except Exception as e:
126
- st.error(f"❌ Agent creation failed: {str(e)}")
127
- st.code(traceback.format_exc())
128
-
129
-
130
- def test_dataset_loading():
131
- """Test dataset loading."""
132
- st.markdown("## 📊 Dataset Test")
133
-
134
- try:
135
- with st.spinner("Loading dataset..."):
136
- dataset = load_dataset(
137
- "bitext/Bitext-customer-support-llm-chatbot-training-dataset"
138
- )
139
- df = pd.DataFrame(dataset["train"])
140
- st.success(f"✅ Dataset loaded: {len(df):,} records")
141
- st.dataframe(df.head(3))
142
- except Exception as e:
143
- st.error(f"❌ Dataset loading failed: {str(e)}")
144
- st.code(traceback.format_exc())
145
-
146
-
147
- def main():
148
- st.title("🔧 LangGraph Agent Debug Tool")
149
- st.markdown("This tool helps diagnose issues with the LangGraph agent deployment.")
150
-
151
- # Environment check
152
- check_environment()
153
-
154
- st.markdown("---")
155
-
156
- # Dataset test
157
- test_dataset_loading()
158
-
159
- st.markdown("---")
160
-
161
- # Agent test
162
- test_simple_agent()
163
-
164
- st.markdown("---")
165
-
166
- st.markdown("## 💡 Common Solutions")
167
- st.markdown(
168
- """
169
- **If agent creation fails:**
170
- - Check API key is correctly set as Space secret
171
- - Verify all dependencies are in requirements.txt
172
- - Check for import errors above
173
-
174
- **If agent hangs on 'thinking':**
175
- - API key might be invalid/expired
176
- - Network connectivity issues to API endpoint
177
- - Unhandled exceptions in LangGraph workflow
178
-
179
- **If dataset loading fails:**
180
- - Network connectivity issues
181
- - Hugging Face datasets library not properly installed
182
- """
183
- )
184
-
185
-
186
- if __name__ == "__main__":
187
- main()