yhzhang3 commited on
Commit
acbdb9e
Β·
1 Parent(s): c749d61

first commit

Browse files
Files changed (3) hide show
  1. Results.zip +3 -0
  2. app.py +23 -36
  3. test.py +35 -18
Results.zip ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:210d541415e8f704fa65d9b52b794fc3f130da3bf155ae6ea134826b6ae51d3e
3
+ size 210
app.py CHANGED
@@ -115,12 +115,8 @@ Please be patient β€” takes about 20–30 minutes to process.
115
  """
116
  import subprocess
117
  import os
118
- import time
119
- from datetime import datetime
120
 
121
  ui_logs = [] # Simplified logs for UI
122
- current_task = 0
123
- total_tasks = 4
124
 
125
  try:
126
  # Validate inputs
@@ -132,11 +128,9 @@ Please be patient β€” takes about 20–30 minutes to process.
132
  ui_logs.append("❌ Error: Claude API Key is required")
133
  return "\n".join(ui_logs), None, ""
134
 
135
- # Create log file in Results folder
136
  results_path = ROOT / "Results"
137
  results_path.mkdir(parents=True, exist_ok=True)
138
- timestamp = datetime.now().strftime("%Y%m%d_%H%M%S")
139
- log_file_path = results_path / f"log_{timestamp}.log"
140
 
141
  ui_logs.append(f"πŸš€ Starting Paper2Agent pipeline...")
142
  ui_logs.append(f"πŸ“˜ GitHub Repo: {github_url}")
@@ -145,7 +139,7 @@ Please be patient β€” takes about 20–30 minutes to process.
145
  if tutorials_filter:
146
  ui_logs.append(f"πŸ“š Tutorial Filter: {tutorials_filter}")
147
 
148
- ui_logs.append(f"\nπŸ“ Detailed logs: {log_file_path}")
149
  ui_logs.append("\n" + "="*70)
150
  yield "\n".join(ui_logs), None, ""
151
 
@@ -167,29 +161,23 @@ Please be patient β€” takes about 20–30 minutes to process.
167
  if tutorials_filter and tutorials_filter.strip():
168
  cmd.extend(["--tutorials", tutorials_filter])
169
 
170
- # Run test.py and write all output to log file
171
- with open(log_file_path, 'w', encoding='utf-8') as log_file:
172
- process = subprocess.Popen(
173
- cmd,
174
- stdout=subprocess.PIPE,
175
- stderr=subprocess.STDOUT,
176
- text=True,
177
- bufsize=0,
178
- env=env
179
- )
180
-
181
- # Stream all output to both log file and UI in real-time
182
- for line in iter(process.stdout.readline, ''):
183
- if line:
184
- # Write all output to log file (everything)
185
- log_file.write(line)
186
- log_file.flush()
187
-
188
- # Add to ui_logs only if not ToolUseBlock
189
- stripped_line = line.strip()
190
- if stripped_line and "ToolUseBlock" not in line and len(stripped_line) < 200:
191
- ui_logs.append(stripped_line)
192
- yield "\n".join(ui_logs), None, ""
193
 
194
  process.wait()
195
 
@@ -207,7 +195,7 @@ Please be patient β€” takes about 20–30 minutes to process.
207
  import shutil
208
 
209
  # Create zip file with timestamp
210
- zip_base_name = f"Results_{timestamp}"
211
  zip_file_path = ROOT / zip_base_name
212
 
213
  try:
@@ -221,7 +209,7 @@ Please be patient β€” takes about 20–30 minutes to process.
221
  zip_file = str(zip_file_path) + ".zip"
222
  ui_logs.append(f"βœ… Created zip file: {zip_file}")
223
  ui_logs.append(f"πŸ“₯ Ready for download!")
224
- ui_logs.append(f"\nπŸ“ Full logs saved to: {log_file_path}")
225
  yield "\n".join(ui_logs), zip_file, ""
226
  except Exception as e:
227
  ui_logs.append(f"⚠️ Failed to create zip file: {str(e)}")
@@ -232,14 +220,13 @@ Please be patient β€” takes about 20–30 minutes to process.
232
  else:
233
  ui_logs.append("\n" + "="*70)
234
  ui_logs.append(f"❌ Pipeline failed with exit code {process.returncode}")
235
- ui_logs.append(f"πŸ“ Check logs for details: {log_file_path}")
236
  ui_logs.append("="*70)
237
  yield "\n".join(ui_logs), None, ""
238
 
239
  except Exception as e:
240
  ui_logs.append(f"\n❌ Error: {str(e)}")
241
- if 'log_file_path' in locals():
242
- ui_logs.append(f"πŸ“ Check logs for details: {log_file_path}")
243
  yield "\n".join(ui_logs), None, ""
244
 
245
  # Connect example button
 
115
  """
116
  import subprocess
117
  import os
 
 
118
 
119
  ui_logs = [] # Simplified logs for UI
 
 
120
 
121
  try:
122
  # Validate inputs
 
128
  ui_logs.append("❌ Error: Claude API Key is required")
129
  return "\n".join(ui_logs), None, ""
130
 
131
+ # Create Results folder
132
  results_path = ROOT / "Results"
133
  results_path.mkdir(parents=True, exist_ok=True)
 
 
134
 
135
  ui_logs.append(f"πŸš€ Starting Paper2Agent pipeline...")
136
  ui_logs.append(f"πŸ“˜ GitHub Repo: {github_url}")
 
139
  if tutorials_filter:
140
  ui_logs.append(f"πŸ“š Tutorial Filter: {tutorials_filter}")
141
 
142
+ ui_logs.append(f"\nπŸ“ Detailed logs will be saved to: Results/log.log")
143
  ui_logs.append("\n" + "="*70)
144
  yield "\n".join(ui_logs), None, ""
145
 
 
161
  if tutorials_filter and tutorials_filter.strip():
162
  cmd.extend(["--tutorials", tutorials_filter])
163
 
164
+ # Run test.py and capture stdout for UI
165
+ process = subprocess.Popen(
166
+ cmd,
167
+ stdout=subprocess.PIPE,
168
+ stderr=subprocess.STDOUT,
169
+ text=True,
170
+ bufsize=0,
171
+ env=env
172
+ )
173
+
174
+ # Stream output to UI
175
+ for line in iter(process.stdout.readline, ''):
176
+ if line:
177
+ stripped_line = line.strip()
178
+ if stripped_line:
179
+ ui_logs.append(stripped_line)
180
+ yield "\n".join(ui_logs), None, ""
 
 
 
 
 
 
181
 
182
  process.wait()
183
 
 
195
  import shutil
196
 
197
  # Create zip file with timestamp
198
+ zip_base_name = f"Results"
199
  zip_file_path = ROOT / zip_base_name
200
 
201
  try:
 
209
  zip_file = str(zip_file_path) + ".zip"
210
  ui_logs.append(f"βœ… Created zip file: {zip_file}")
211
  ui_logs.append(f"πŸ“₯ Ready for download!")
212
+ ui_logs.append(f"\nπŸ“ Full logs saved to: Results/log.log")
213
  yield "\n".join(ui_logs), zip_file, ""
214
  except Exception as e:
215
  ui_logs.append(f"⚠️ Failed to create zip file: {str(e)}")
 
220
  else:
221
  ui_logs.append("\n" + "="*70)
222
  ui_logs.append(f"❌ Pipeline failed with exit code {process.returncode}")
223
+ ui_logs.append(f"πŸ“ Check logs for details: Results/log.log")
224
  ui_logs.append("="*70)
225
  yield "\n".join(ui_logs), None, ""
226
 
227
  except Exception as e:
228
  ui_logs.append(f"\n❌ Error: {str(e)}")
229
+ ui_logs.append(f"πŸ“ Check logs for details: Results/log.log")
 
230
  yield "\n".join(ui_logs), None, ""
231
 
232
  # Connect example button
test.py CHANGED
@@ -20,7 +20,7 @@ from prompts.tasks import step1_environment_setup_and_tutorial_discovery, step2_
20
 
21
  # ANTHROPIC_API_KEY should be set via environment variable by the caller (app.py)
22
 
23
- async def fully_automatic(tasks: list, task_descriptions: list = None):
24
  options = ClaudeAgentOptions(
25
  allowed_tools=["Bash", "Edit", "Glob", "Grep", "NotebookEdit", "NotebookRead", "Read", "SlashCommand", "Task", "TodoWrite", "WebFetch", "WebSearch", "Write"],
26
  permission_mode='acceptEdits',
@@ -30,37 +30,51 @@ async def fully_automatic(tasks: list, task_descriptions: list = None):
30
 
31
  async with ClaudeSDKClient(options=options) as client:
32
  for i, task in enumerate(tasks, 1):
 
33
  print(f"\n{'='*70}")
34
  if task_descriptions and i <= len(task_descriptions):
35
  print(f"πŸš€ Starting {task_descriptions[i-1]}")
36
  else:
37
  print(f"πŸš€ Starting Task {i}")
38
  print('='*70 + "\n")
 
39
  try:
40
  await client.query(task)
41
-
42
  async for message in client.receive_response():
43
-
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
44
  if isinstance(message, AssistantMessage):
45
  for block in message.content:
46
  if isinstance(block, TextBlock):
47
- print(f"πŸ’­ Claude: {block.text}\n")
48
- elif isinstance(block, ToolUseBlock):
49
- if hasattr(block, 'input') and block.input:
50
- if isinstance(block.input, dict):
51
- for key, value in block.input.items():
52
- val_str = str(value)
53
- print(f"[ToolUseBlock] {key}: {val_str}\n")
54
 
55
- elif isinstance(message, ToolResultBlock):
56
- if hasattr(message, 'content'):
57
- result = str(message.content)
58
- print(f" βœ… Result: {result}\n")
59
-
60
- print(f"\n βœ… Task {i} Completed\n")
61
 
62
  except Exception as e:
63
- print(f" ❌ Task {i} Failed: {e}\n")
 
 
 
64
 
65
 
66
  def main():
@@ -118,8 +132,11 @@ def main():
118
  print(f" {i}. {desc}")
119
  print("="*70 + "\n")
120
 
 
 
 
121
  #print(tasks[0])
122
- anyio.run(fully_automatic, tasks, task_descriptions)
123
 
124
 
125
  if __name__ == "__main__":
 
20
 
21
  # ANTHROPIC_API_KEY should be set via environment variable by the caller (app.py)
22
 
23
+ async def fully_automatic(tasks: list, task_descriptions: list = None, log_file_path: str = None):
24
  options = ClaudeAgentOptions(
25
  allowed_tools=["Bash", "Edit", "Glob", "Grep", "NotebookEdit", "NotebookRead", "Read", "SlashCommand", "Task", "TodoWrite", "WebFetch", "WebSearch", "Write"],
26
  permission_mode='acceptEdits',
 
30
 
31
  async with ClaudeSDKClient(options=options) as client:
32
  for i, task in enumerate(tasks, 1):
33
+ # Simple print for UI
34
  print(f"\n{'='*70}")
35
  if task_descriptions and i <= len(task_descriptions):
36
  print(f"πŸš€ Starting {task_descriptions[i-1]}")
37
  else:
38
  print(f"πŸš€ Starting Task {i}")
39
  print('='*70 + "\n")
40
+
41
  try:
42
  await client.query(task)
 
43
  async for message in client.receive_response():
44
+ # Write detailed logs to file
45
+ if log_file_path:
46
+ with open(f"Task_{i}_{log_file_path}", 'a', encoding='utf-8') as log_file:
47
+ if isinstance(message, AssistantMessage):
48
+ for block in message.content:
49
+ if isinstance(block, TextBlock):
50
+ log_file.write(f"πŸ’­ Claude: {block.text}\n")
51
+ elif isinstance(block, ToolUseBlock):
52
+ if hasattr(block, 'input') and block.input:
53
+ if isinstance(block.input, dict):
54
+ for key, value in block.input.items():
55
+ val_str = str(value)
56
+ log_file.write(f"[ToolUseBlock] {key}: {val_str}\n")
57
+ elif isinstance(message, ToolResultBlock):
58
+ if hasattr(message, 'content'):
59
+ result = str(message.content)
60
+ log_file.write(f" βœ… Result: {result}\n")
61
+
62
+ # Only print brief progress to stdout for UI
63
  if isinstance(message, AssistantMessage):
64
  for block in message.content:
65
  if isinstance(block, TextBlock):
66
+ # Only print short text blocks
67
+ text = block.text.strip()
68
+ if len(text) < 150:
69
+ print(f"πŸ’­ {text}")
 
 
 
70
 
71
+ print(f"\nβœ… Task {i} Completed\n")
 
 
 
 
 
72
 
73
  except Exception as e:
74
+ print(f"❌ Task {i} Failed: {e}\n")
75
+ if log_file_path:
76
+ with open(log_file_path, 'a', encoding='utf-8') as log_file:
77
+ log_file.write(f"❌ Task {i} Failed: {e}\n")
78
 
79
 
80
  def main():
 
132
  print(f" {i}. {desc}")
133
  print("="*70 + "\n")
134
 
135
+ # Define log file path
136
+ log_file_path = "log.log"
137
+
138
  #print(tasks[0])
139
+ anyio.run(fully_automatic, tasks, task_descriptions, log_file_path)
140
 
141
 
142
  if __name__ == "__main__":