ai-puppy commited on
Commit
b4ea9c6
Β·
1 Parent(s): b8d6d6e
Files changed (4) hide show
  1. app_with_debug.py +183 -0
  2. debug_app.py +147 -0
  3. requirements_debug.txt +2 -0
  4. version_check.py +62 -0
app_with_debug.py ADDED
@@ -0,0 +1,183 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import os
2
+ import gradio as gr
3
+ import asyncio
4
+ import tempfile
5
+ import traceback
6
+ from dotenv import find_dotenv, load_dotenv
7
+
8
+ # Load environment variables
9
+ load_dotenv(find_dotenv())
10
+
11
+ print("πŸ” DEBUG: Starting DataForge with debug information")
12
+ print(f"πŸ” DEBUG: Python version: {os.sys.version}")
13
+ print(f"πŸ” DEBUG: Working directory: {os.getcwd()}")
14
+
15
+ # Import with debug info
16
+ print("πŸ” DEBUG: Importing langchain...")
17
+ try:
18
+ from langchain.chat_models import init_chat_model
19
+ print("βœ… DEBUG: langchain imported successfully")
20
+ except Exception as e:
21
+ print(f"❌ DEBUG: langchain import failed: {e}")
22
+ traceback.print_exc()
23
+
24
+ print("πŸ” DEBUG: Importing agent...")
25
+ try:
26
+ from agent import FileInjectedPyodideSandbox, create_pyodide_eval_fn, create_codeact
27
+ print("βœ… DEBUG: agent imported successfully")
28
+ except Exception as e:
29
+ print(f"❌ DEBUG: agent import failed: {e}")
30
+ traceback.print_exc()
31
+
32
+ print("πŸ” DEBUG: Importing graph...")
33
+ try:
34
+ from graph import analyze_file_with_guidance_sync, guided_analysis_graph
35
+ print("βœ… DEBUG: graph imported successfully")
36
+ except Exception as e:
37
+ print(f"❌ DEBUG: graph import failed: {e}")
38
+ traceback.print_exc()
39
+
40
+ # Initialize model with debug info
41
+ print("πŸ” DEBUG: Initializing model...")
42
+ try:
43
+ codeact_model = init_chat_model("gpt-4.1-2025-04-14", model_provider="openai")
44
+ print("βœ… DEBUG: Model initialized successfully")
45
+ except Exception as e:
46
+ print(f"❌ DEBUG: Model initialization failed: {e}")
47
+ traceback.print_exc()
48
+
49
+ # Store uploaded file path globally
50
+ uploaded_file_path = None
51
+
52
+ def handle_file_upload(file):
53
+ """Handle file upload and store the path globally"""
54
+ global uploaded_file_path
55
+ try:
56
+ print(f"πŸ” DEBUG: File upload called with: {file}")
57
+ if file is not None:
58
+ uploaded_file_path = file
59
+ filename = os.path.basename(file)
60
+ print(f"βœ… DEBUG: File uploaded: {filename}")
61
+ return f"βœ… File uploaded successfully: {filename}"
62
+ else:
63
+ uploaded_file_path = None
64
+ print("❌ DEBUG: No file provided")
65
+ return "❌ No file uploaded"
66
+ except Exception as e:
67
+ uploaded_file_path = None
68
+ print(f"❌ DEBUG: Upload error: {e}")
69
+ traceback.print_exc()
70
+ return f"❌ Upload error: {str(e)}"
71
+
72
+ def analyze_file_with_question(user_question):
73
+ """
74
+ Analyze the uploaded file using the guided approach with debug info
75
+ """
76
+ global uploaded_file_path
77
+
78
+ try:
79
+ print(f"πŸ” DEBUG: Analysis called with question: {user_question}")
80
+ print(f"πŸ” DEBUG: Uploaded file path: {uploaded_file_path}")
81
+
82
+ if not uploaded_file_path or not os.path.exists(uploaded_file_path):
83
+ print("❌ DEBUG: No file available for analysis")
84
+ return "❌ No file uploaded or file not found. Please upload a file first."
85
+
86
+ if not user_question or user_question.strip() == "":
87
+ user_question = "Provide a comprehensive analysis of this file including security, performance, and data insights."
88
+
89
+ print("πŸ” DEBUG: Calling analyze_file_with_guidance_sync...")
90
+ result = analyze_file_with_guidance_sync(uploaded_file_path, user_question)
91
+ print(f"βœ… DEBUG: Analysis completed, result length: {len(result) if result else 0}")
92
+ return result
93
+
94
+ except Exception as e:
95
+ print(f"❌ DEBUG: Analysis error: {e}")
96
+ traceback.print_exc()
97
+ return f"❌ Error in guided analysis: {str(e)}\n\nFull traceback:\n{traceback.format_exc()}"
98
+
99
+ print("πŸ” DEBUG: Creating Gradio interface...")
100
+
101
+ # Create the Gradio interface with debug wrapper
102
+ try:
103
+ with gr.Blocks(title="DataForge - AI-Powered File Analysis (Debug Mode)") as demo:
104
+ gr.Markdown("# πŸ” DataForge - AI-Powered File Analysis (Debug Mode)")
105
+ gr.Markdown("""
106
+ **This is a debug version to help identify Hugging Face Spaces deployment issues.**
107
+
108
+ Upload any file and ask specific questions for targeted AI analysis.
109
+ """)
110
+
111
+ with gr.Row():
112
+ with gr.Column(scale=1):
113
+ gr.Markdown("### πŸ“€ File Upload")
114
+ file_upload = gr.File(
115
+ label="Upload File for Analysis",
116
+ type="filepath"
117
+ )
118
+ upload_status = gr.Textbox(
119
+ label="Upload Status",
120
+ value="No file uploaded",
121
+ interactive=False
122
+ )
123
+
124
+ gr.Markdown("### ❓ Ask Your Question")
125
+ user_question = gr.Textbox(
126
+ label="Your Question about the File",
127
+ placeholder="What would you like to know about this file?",
128
+ lines=4,
129
+ value=""
130
+ )
131
+
132
+ analyze_btn = gr.Button("πŸ” Run Analysis (Debug)", variant="primary", size="lg")
133
+
134
+ with gr.Column(scale=2):
135
+ analysis_output = gr.Textbox(
136
+ label="πŸ“Š Analysis Results (Debug Mode)",
137
+ lines=25,
138
+ max_lines=35,
139
+ placeholder="Upload a file, type your question, and click 'Run Analysis' to see results...",
140
+ interactive=False
141
+ )
142
+
143
+ # Event handlers
144
+ file_upload.change(
145
+ fn=handle_file_upload,
146
+ inputs=[file_upload],
147
+ outputs=[upload_status]
148
+ )
149
+
150
+ analyze_btn.click(
151
+ fn=analyze_file_with_question,
152
+ inputs=[user_question],
153
+ outputs=[analysis_output]
154
+ )
155
+
156
+ gr.Markdown("---")
157
+ gr.Markdown("## 🐞 Debug Information")
158
+ gr.Markdown("""
159
+ This debug version includes:
160
+ - Detailed import and initialization logging
161
+ - Exception tracebacks
162
+ - Step-by-step execution tracking
163
+ - Version and environment information
164
+
165
+ Check the console/logs for detailed debug output.
166
+ """)
167
+
168
+ print("βœ… DEBUG: Gradio interface created successfully")
169
+
170
+ except Exception as e:
171
+ print(f"❌ DEBUG: Gradio interface creation failed: {e}")
172
+ traceback.print_exc()
173
+ raise
174
+
175
+ if __name__ == "__main__":
176
+ print("πŸ” DEBUG: Starting application launch...")
177
+ try:
178
+ demo.launch()
179
+ print("βœ… DEBUG: Application launched successfully")
180
+ except Exception as e:
181
+ print(f"❌ DEBUG: Application launch failed: {e}")
182
+ traceback.print_exc()
183
+ raise
debug_app.py ADDED
@@ -0,0 +1,147 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import os
2
+ import gradio as gr
3
+ import tempfile
4
+ from dotenv import find_dotenv, load_dotenv
5
+
6
+ # Load environment variables
7
+ load_dotenv(find_dotenv())
8
+
9
+ # Store uploaded file path globally
10
+ uploaded_file_path = None
11
+
12
+ def handle_file_upload(file):
13
+ """Handle file upload and store the path globally"""
14
+ global uploaded_file_path
15
+ try:
16
+ if file is not None:
17
+ uploaded_file_path = file
18
+ filename = os.path.basename(file)
19
+ return f"βœ… File uploaded successfully: {filename}"
20
+ else:
21
+ uploaded_file_path = None
22
+ return "❌ No file uploaded"
23
+ except Exception as e:
24
+ uploaded_file_path = None
25
+ return f"❌ Upload error: {str(e)}"
26
+
27
+ def simple_file_analysis(user_question):
28
+ """
29
+ Simple file analysis without complex schemas - for debugging
30
+ """
31
+ global uploaded_file_path
32
+
33
+ try:
34
+ if not uploaded_file_path or not os.path.exists(uploaded_file_path):
35
+ return "❌ No file uploaded or file not found. Please upload a file first."
36
+
37
+ if not user_question or user_question.strip() == "":
38
+ user_question = "Provide basic analysis of this file."
39
+
40
+ # Basic file info without complex processing
41
+ file_size = os.path.getsize(uploaded_file_path)
42
+ filename = os.path.basename(uploaded_file_path)
43
+
44
+ # Read first few lines
45
+ try:
46
+ with open(uploaded_file_path, 'r', encoding='utf-8') as f:
47
+ first_lines = []
48
+ for i, line in enumerate(f):
49
+ if i >= 5:
50
+ break
51
+ first_lines.append(line.rstrip())
52
+ except Exception as e:
53
+ first_lines = [f"Error reading file: {str(e)}"]
54
+
55
+ result = f"""
56
+ πŸ“Š Basic File Analysis Results:
57
+
58
+ πŸ“ File Information:
59
+ - Name: {filename}
60
+ - Size: {file_size} bytes
61
+ - Path: {uploaded_file_path}
62
+
63
+ ❓ Your Question: {user_question}
64
+
65
+ πŸ“ First 5 lines:
66
+ {chr(10).join(first_lines)}
67
+
68
+ βœ… This is a debug version to test Gradio deployment.
69
+ If you see this, the basic Gradio functionality works.
70
+ """
71
+ return result
72
+
73
+ except Exception as e:
74
+ return f"❌ Error in analysis: {str(e)}"
75
+
76
+ # Create a minimal Gradio interface for debugging
77
+ with gr.Blocks(title="DataForge Debug - Basic File Analysis") as demo:
78
+ gr.Markdown("# πŸ” DataForge Debug Version")
79
+ gr.Markdown("""
80
+ **This is a debug version to test Gradio deployment issues.**
81
+
82
+ This version removes complex Pydantic models and LangGraph processing
83
+ to isolate the schema generation issue in Hugging Face Spaces.
84
+ """)
85
+
86
+ with gr.Row():
87
+ with gr.Column(scale=1):
88
+ gr.Markdown("### πŸ“€ File Upload")
89
+ file_upload = gr.File(
90
+ label="Upload File for Basic Analysis",
91
+ type="filepath"
92
+ )
93
+ upload_status = gr.Textbox(
94
+ label="Upload Status",
95
+ value="No file uploaded",
96
+ interactive=False
97
+ )
98
+
99
+ gr.Markdown("### ❓ Ask Your Question")
100
+ user_question = gr.Textbox(
101
+ label="Your Question about the File",
102
+ placeholder="What would you like to know about this file?",
103
+ lines=3,
104
+ value=""
105
+ )
106
+
107
+ analyze_btn = gr.Button("πŸ” Run Basic Analysis", variant="primary")
108
+
109
+ with gr.Column(scale=2):
110
+ analysis_output = gr.Textbox(
111
+ label="πŸ“Š Basic Analysis Results",
112
+ lines=20,
113
+ placeholder="Upload a file and click 'Run Basic Analysis' to see results...",
114
+ interactive=False
115
+ )
116
+
117
+ # Event handlers
118
+ file_upload.change(
119
+ fn=handle_file_upload,
120
+ inputs=[file_upload],
121
+ outputs=[upload_status]
122
+ )
123
+
124
+ analyze_btn.click(
125
+ fn=simple_file_analysis,
126
+ inputs=[user_question],
127
+ outputs=[analysis_output]
128
+ )
129
+
130
+ gr.Markdown("---")
131
+ gr.Markdown("""
132
+ ## 🐞 Debug Information
133
+
134
+ **Purpose**: This debug version helps identify if the issue is related to:
135
+ - βœ… Basic Gradio functionality (this should work)
136
+ - ❌ Complex Pydantic models used in the full version
137
+ - ❌ LangGraph state management
138
+ - ❌ Version conflicts between local and HF Spaces
139
+
140
+ **Next Steps**:
141
+ 1. If this version works on HF Spaces, the issue is in complex schema handling
142
+ 2. If this fails too, it's a basic Gradio/environment issue
143
+ """)
144
+
145
+ if __name__ == "__main__":
146
+ print("Starting DataForge Debug application...")
147
+ demo.launch()
requirements_debug.txt ADDED
@@ -0,0 +1,2 @@
 
 
 
1
+ gradio
2
+ python-dotenv
version_check.py ADDED
@@ -0,0 +1,62 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ #!/usr/bin/env python3
2
+
3
+ import sys
4
+ import pkg_resources
5
+
6
+ print("πŸ” Version Information:")
7
+ print(f"Python: {sys.version}")
8
+ print()
9
+
10
+ packages_to_check = [
11
+ 'gradio', 'gradio-client', 'pydantic', 'pydantic-core',
12
+ 'langchain', 'langchain-core', 'langgraph', 'typing-extensions',
13
+ 'fastapi', 'starlette', 'uvicorn'
14
+ ]
15
+
16
+ for package in packages_to_check:
17
+ try:
18
+ version = pkg_resources.get_distribution(package).version
19
+ print(f"{package}: {version}")
20
+ except pkg_resources.DistributionNotFound:
21
+ print(f"{package}: NOT INSTALLED")
22
+ except Exception as e:
23
+ print(f"{package}: ERROR - {e}")
24
+
25
+ print()
26
+ print("πŸ” Critical Type Checking:")
27
+ try:
28
+ from typing_extensions import TypedDict
29
+ print("βœ… TypedDict import successful")
30
+ except Exception as e:
31
+ print(f"❌ TypedDict import failed: {e}")
32
+
33
+ try:
34
+ from pydantic import BaseModel, Field
35
+ print("βœ… Pydantic imports successful")
36
+
37
+ # Test schema generation
38
+ class TestModel(BaseModel):
39
+ name: str = Field(description="Test field")
40
+
41
+ schema = TestModel.model_json_schema()
42
+ print(f"βœ… Pydantic schema generation successful: {type(schema)}")
43
+
44
+ # Check for boolean values in schema
45
+ def check_schema_values(obj, path=""):
46
+ if isinstance(obj, dict):
47
+ for k, v in obj.items():
48
+ if isinstance(v, bool):
49
+ print(f"πŸ” Found boolean in schema at {path}.{k}: {v}")
50
+ elif isinstance(v, (dict, list)):
51
+ check_schema_values(v, f"{path}.{k}")
52
+ elif isinstance(obj, list):
53
+ for i, item in enumerate(obj):
54
+ if isinstance(item, (dict, list)):
55
+ check_schema_values(item, f"{path}[{i}]")
56
+
57
+ check_schema_values(schema)
58
+
59
+ except Exception as e:
60
+ print(f"❌ Pydantic test failed: {e}")
61
+ import traceback
62
+ traceback.print_exc()