Yusufarsh commited on
Commit
d269059
Β·
verified Β·
1 Parent(s): 331f4b7

Update README.md

Browse files
Files changed (1) hide show
  1. README.md +432 -421
README.md CHANGED
@@ -1,421 +1,432 @@
1
- <p align="center">
2
- <img src="assets/banner.png" alt="ReproAgent Banner" width="100%"/>
3
- </p>
4
-
5
- <h1 align="center">πŸ”¬ ReproAgent</h1>
6
-
7
- <p align="center">
8
- <strong>An AI-powered agent that automatically reproduces machine learning research papers.</strong>
9
- </p>
10
-
11
- <p align="center">
12
- <a href="#-features"><img src="https://img.shields.io/badge/Features-8-blue?style=for-the-badge" alt="Features"/></a>
13
- <a href="#-quick-start"><img src="https://img.shields.io/badge/Python-3.10+-green?style=for-the-badge&logo=python&logoColor=white" alt="Python"/></a>
14
- <a href="#-license"><img src="https://img.shields.io/badge/License-MIT-orange?style=for-the-badge" alt="License"/></a>
15
- <a href="https://huggingface.co/spaces"><img src="https://img.shields.io/badge/πŸ€—-HuggingFace_Spaces-yellow?style=for-the-badge" alt="HF Spaces"/></a>
16
- </p>
17
-
18
- <p align="center">
19
- Upload a research paper PDF β†’ ReproAgent reads it β†’ finds the repo β†’ clones the code β†’ sets up the environment β†’ runs it β†’ debugs errors β†’ tunes hyperparameters β†’ compares results.
20
- </p>
21
-
22
- ---
23
-
24
- ## πŸ† OpenEnv Hackathon Submission
25
-
26
- This project is submitted to the **OpenEnv Hackathon**. It is a fully compliant environment built on top of the framework.
27
-
28
- ### Required Materials
29
- - **Hugging Face Space**: [ReproAgent Live Demo](https://huggingface.co/spaces/username/reproagent)
30
- - **Training Script (TRL/PPO)**: [Colab Notebook](training/train_reproagent.ipynb)
31
- - **Evidence of Training**: We trained the agent using Proximal Policy Optimization (PPO) over 50 episodes.
32
- <br><img src="assets/reward_plot.png" alt="Reward Plot" width="400"/> <img src="assets/loss_plot.png" alt="Loss Plot" width="400"/>
33
- - **Presentation**: [Mini-Blog on HuggingFace](https://huggingface.co/blog/reproagent-openenv) / [YouTube Demo (< 2 minutes)](https://youtube.com/watch?v=demo_link)
34
-
35
- ---
36
-
37
- ## πŸ“– Table of Contents
38
-
39
- - [Overview](#-overview)
40
- - [Features](#-features)
41
- - [Architecture](#-architecture)
42
- - [Quick Start](#-quick-start)
43
- - [Usage](#-usage)
44
- - [Project Structure](#-project-structure)
45
- - [Configuration](#-configuration)
46
- - [How It Works](#-how-it-works)
47
- - [Validation](#-validation)
48
- - [Docker Deployment](#-docker-deployment)
49
- - [Contributing](#-contributing)
50
- - [License](#-license)
51
-
52
- ---
53
-
54
- ## 🌟 Overview
55
-
56
- **ReproAgent** is an AI-driven framework built on [OpenAI Gymnasium](https://gymnasium.farama.org/) that automates the end-to-end reproduction of machine learning research papers. Given a PDF, it autonomously:
57
-
58
- 1. **Parses** the paper to extract title, metrics, datasets, and GitHub links
59
- 2. **Clones** the linked repository
60
- 3. **Sets up** the environment (conda/venv) and installs dependencies
61
- 4. **Runs** inference or training scripts
62
- 5. **Debugs** errors using real traceback analysis
63
- 6. **Tunes** hyperparameters to close the gap between reproduced and claimed results
64
- 7. **Compares** final metrics against the paper's claims
65
-
66
- It supports both a **Simulation** mode (safe, no system changes) and a **Real Execution** mode (actually clones repos, creates envs, runs code on your machine).
67
-
68
- ---
69
-
70
- ## ✨ Features
71
-
72
- | Feature | Description |
73
- |---------|-------------|
74
- | πŸ“„ **PDF Parsing** | Extracts metadata using Groq LLM (llama-3.3-70b) with regex fallback |
75
- | πŸ”— **Repo Discovery** | Finds GitHub links from paper text, cleans trailing punctuation |
76
- | πŸ“¦ **Smart Environment Setup** | Auto-detects `requirements.txt`, `environment.yml`, or `pyproject.toml` and creates the correct env (pip venv or conda) |
77
- | 🧠 **Intelligent Entry Point** | Scans for `inference.py`, `eval.py`, `main.py`, `train.py`, or extracts scripts from README bash blocks |
78
- | πŸ› **Real Error Debugging** | Captures actual `stderr` tracebacks and feeds them into the debugging pipeline |
79
- | πŸ§ͺ **Hyperparameter Tuning** | Modifies learning rate, batch size, optimizer, and epochs to reproduce paper metrics |
80
- | πŸ“Š **Dynamic Metric Extraction** | Extracts the actual evaluation metric (FID, BLEU, accuracy, PSNR, etc.) from the paper β€” not hardcoded |
81
- | πŸ–₯️ **Gradio Web UI** | Beautiful web interface with live logs, state tracking, and result visualization |
82
-
83
- ---
84
-
85
- ## πŸ—οΈ Architecture
86
-
87
- ```
88
- β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”
89
- β”‚ Gradio Web UI β”‚
90
- β”‚ (server/app.py) β”‚
91
- β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”¬β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜
92
- β”‚
93
- β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β–Όβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”
94
- β”‚ Reasoning Agent β”‚
95
- β”‚ (agents/reasoning_ β”‚
96
- β”‚ agent.py) β”‚
97
- β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”¬β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜
98
- β”‚ select_action()
99
- β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β–Όβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”
100
- β”‚ Gymnasium Environment β”‚
101
- β”‚ (reproagent/ β”‚
102
- β”‚ environment.py) β”‚
103
- β”‚ β”‚
104
- β”‚ β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β” β”‚
105
- β”‚ β”‚ State Machine β”‚ β”‚
106
- β”‚ β”‚ β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β” β”‚ β”‚
107
- β”‚ β”‚ β”‚ Parsing β”‚ β”‚ β”‚
108
- β”‚ β”‚ β”‚ RepoAnalysβ”‚ β”‚ β”‚
109
- β”‚ β”‚ β”‚ Setup β”‚ β”‚ β”‚
110
- β”‚ β”‚ β”‚ Execution β”‚ β”‚ β”‚
111
- β”‚ β”‚ β”‚ Debugging β”‚ β”‚ β”‚
112
- β”‚ β”‚ β”‚ Experimentβ”‚ β”‚ β”‚
113
- β”‚ β”‚ β”‚ Comparisonβ”‚ β”‚ β”‚
114
- β”‚ β”‚ β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜ β”‚ β”‚
115
- β”‚ β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜ β”‚
116
- β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜
117
- β”‚ β”‚
118
- β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜ └──────────┐
119
- β–Ό β–Ό
120
- β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β” β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”
121
- β”‚ Simulation β”‚ β”‚ Real Execution β”‚
122
- β”‚ (mock state β”‚ β”‚ (subprocess, β”‚
123
- β”‚ transitions)β”‚ β”‚ git clone, β”‚
124
- β”‚ β”‚ β”‚ conda/venv) β”‚
125
- β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜ β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜
126
- ```
127
-
128
- ---
129
-
130
- ## πŸš€ Quick Start
131
-
132
- ### Prerequisites
133
-
134
- - **Python** 3.10+
135
- - **Git** (for real execution mode)
136
- - **Conda** (optional, for repos that use `environment.yml`)
137
- - A **Groq API key** (free at [console.groq.com](https://console.groq.com))
138
-
139
- ### Installation
140
-
141
- ```bash
142
- # 1. Clone the repository
143
- git clone https://github.com/your-username/ReproAgent.git
144
- cd ReproAgent
145
-
146
- # 2. Create a virtual environment
147
- python -m venv venv
148
-
149
- # Windows
150
- .\venv\Scripts\activate
151
-
152
- # macOS/Linux
153
- source venv/bin/activate
154
-
155
- # 3. Install dependencies
156
- pip install -r requirements.txt
157
-
158
- # 4. Set up environment variables
159
- cp .env.example .env
160
- # Edit .env and add your GROQ_API_KEY
161
- ```
162
-
163
- ### Run
164
-
165
- ```bash
166
- # Launch the Gradio web interface
167
- python server/app.py
168
- ```
169
-
170
- The UI will be available at `http://localhost:7860` with a public share link.
171
-
172
- ---
173
-
174
- ## πŸ’» Usage
175
-
176
- ### Web Interface (Recommended)
177
-
178
- 1. Open the Gradio UI at `http://localhost:7860`
179
- 2. **Upload** a research paper PDF (or paste a URL)
180
- 3. Choose **Execution Mode**:
181
- - `Simulation` β€” Safe demo, no system changes
182
- - `Real Execution` β€” Actually clones repos and runs code
183
- 4. Set **Clone Directory** (where repos will be cloned, e.g. `D:\reproductions`)
184
- 5. Click **Start Reproduction** and watch the agent work in real-time
185
-
186
- ### Command Line
187
-
188
- ```bash
189
- # Run validation to ensure everything works
190
- python validate.py
191
-
192
- # Run a quick inference test
193
- python inference.py
194
- ```
195
-
196
- ### Programmatic API
197
-
198
- ```python
199
- from reproagent.environment import ReproAgentEnv
200
- from agents.reasoning_agent import create_agent
201
-
202
- # Create environment
203
- env = ReproAgentEnv(
204
- difficulty="easy",
205
- max_steps=100,
206
- use_llm=True,
207
- exec_mode="Real Execution",
208
- workspace_dir="./workspace"
209
- )
210
-
211
- # Create agent
212
- agent = create_agent(env, agent_type="reasoning", use_llm=True)
213
-
214
- # Run episode
215
- obs, info = env.reset()
216
- agent.reset()
217
-
218
- for step in range(100):
219
- action = agent.select_action(obs, info)
220
- obs, reward, terminated, truncated, info = env.step(action)
221
-
222
- print(f"Step {step}: {info['action_type']} | reward={reward:.2f}")
223
-
224
- if terminated or truncated:
225
- break
226
- ```
227
-
228
- ---
229
-
230
- ## πŸ“ Project Structure
231
-
232
- ```
233
- ReproAgent/
234
- β”œβ”€β”€ reproagent/ # Core Gymnasium environment
235
- β”‚ β”œβ”€β”€ __init__.py
236
- β”‚ β”œβ”€β”€ environment.py # Main env with action implementations
237
- β”‚ β”œβ”€β”€ state.py # Dataclasses for full reproduction state
238
- β”‚ β”œβ”€β”€ actions.py # Action space definition (30+ actions)
239
- β”‚ β”œβ”€β”€ reward.py # Multi-component reward function
240
- β”‚ β”œβ”€β”€ models.py # LLM client (Groq, OpenAI, HuggingFace)
241
- β”‚ └── papers.py # Paper dataset loader
242
- β”‚
243
- β”œβ”€β”€ agents/ # Agent implementations
244
- β”‚ β”œβ”€β”€ reasoning_agent.py # Phase-based reasoning agent
245
- β”‚ β”œβ”€β”€ paper_parser.py # PDF text extraction + LLM analysis
246
- β”‚ β”œβ”€β”€ repo_analyzer.py # Repository structure analysis
247
- β”‚ └── debugger.py # Error traceback analysis
248
- β”‚
249
- β”œβ”€β”€ server/
250
- β”‚ └── app.py # Gradio web interface (900+ lines)
251
- β”‚
252
- β”œβ”€β”€ utils/
253
- β”‚ β”œβ”€β”€ pdf_reader.py # PDF extraction (PyPDF2 + pdfplumber)
254
- β”‚ └── github_utils.py # GitHub API utilities
255
- β”‚
256
- β”œβ”€β”€ graders/ # Reproduction quality grading
257
- β”œβ”€β”€ data/papers/ # Sample paper configs (easy/medium/hard)
258
- β”œβ”€β”€ baseline/ # Baseline agent implementations
259
- β”œβ”€β”€ static/ # Static assets for UI
260
- β”‚
261
- β”œβ”€β”€ validate.py # Full validation suite
262
- β”œβ”€β”€ inference.py # CLI inference entry point
263
- β”œβ”€β”€ openenv.yaml # OpenEnv compatibility spec
264
- β”œβ”€β”€ pyproject.toml # Python project metadata
265
- β”œβ”€β”€ requirements.txt # pip dependencies
266
- β”œβ”€β”€ Dockerfile # Container deployment
267
- β”œβ”€β”€ run.bat / run.sh / run.ps1 # Platform-specific launchers
268
- └── .env.example # Environment variable template
269
- ```
270
-
271
- ---
272
-
273
- ## βš™οΈ Configuration
274
-
275
- ### Environment Variables
276
-
277
- Create a `.env` file from the template:
278
-
279
- ```bash
280
- cp .env.example .env
281
- ```
282
-
283
- | Variable | Required | Description |
284
- |----------|----------|-------------|
285
- | `GROQ_API_KEY` | **Yes** | Groq API key for LLM-powered extraction ([get one free](https://console.groq.com)) |
286
- | `OPENAI_API_KEY` | No | OpenAI API key (alternative LLM backend) |
287
- | `HF_TOKEN` | No | HuggingFace token for model downloads |
288
- | `GITHUB_TOKEN` | No | GitHub API token for higher rate limits |
289
-
290
- ### Execution Modes
291
-
292
- | Mode | What it does | Use case |
293
- |------|-------------|----------|
294
- | **Simulation** | Simulates all actions with mock state transitions | Safe demos, hackathons, testing |
295
- | **Real Execution** | Runs `git clone`, `conda env create`, `pip install`, `python script.py` on your system | Actually reproducing papers |
296
-
297
- ---
298
-
299
- ## πŸ”„ How It Works
300
-
301
- The agent follows a **phase-based state machine** with 7 phases:
302
-
303
- ```
304
- PARSING β†’ REPO_ANALYSIS β†’ SETUP β†’ EXECUTION β†’ DEBUGGING β†’ EXPERIMENTATION β†’ COMPARISON
305
- ```
306
-
307
- ### Phase Details
308
-
309
- | Phase | Actions | What Happens |
310
- |-------|---------|--------------|
311
- | **Parsing** | `PARSE_PDF`, `EXTRACT_GITHUB`, `EXTRACT_METRICS` | LLM reads paper, extracts title, GitHub URL, target metric (e.g., FID=7.5) |
312
- | **Repo Analysis** | `CLONE_REPO`, `READ_README`, `FIND_ENTRY_POINT`, `EXTRACT_DEPS` | Clones repo, reads README, finds scripts from bash blocks, detects `environment.yml` |
313
- | **Setup** | `CREATE_VENV`, `INSTALL_REQUIREMENTS`, `VERIFY_SETUP` | Creates conda/venv env, installs deps, verifies setup |
314
- | **Execution** | `RUN_TRAINING`, `RUN_EVAL`, `CHECK_LOGS` | Runs the entry point script via subprocess, captures stdout/stderr |
315
- | **Debugging** | `ANALYZE_ERROR`, `SEARCH_SOLUTION`, `APPLY_FIX` | Parses real Python tracebacks, proposes and applies fixes |
316
- | **Experimentation** | `MODIFY_LR`, `MODIFY_BATCH`, `RUN_EXPERIMENT` | Tunes hyperparameters to close the metric gap |
317
- | **Comparison** | `COMPARE_RESULTS`, `GENERATE_REPORT` | Compares reproduced metric vs. paper claim, generates summary |
318
-
319
- ### Reward Function
320
-
321
- The environment provides a multi-component reward signal:
322
-
323
- - **Phase progress** (+10 for advancing through phases)
324
- - **Code execution** (+20 for successful script runs)
325
- - **Error fixing** (+15 per resolved error)
326
- - **Metric improvement** (scaled by how close the reproduced result is to the paper's claim)
327
- - **Time penalty** (-0.01 per step to encourage efficiency)
328
-
329
- ---
330
-
331
- ## βœ… Validation
332
-
333
- Run the full validation suite to confirm everything works:
334
-
335
- ```bash
336
- python validate.py
337
- ```
338
-
339
- This tests:
340
-
341
- | Test | What it validates |
342
- |------|-------------------|
343
- | Environment | `ReproAgentEnv` creates, resets, steps correctly |
344
- | Spaces | Observation and action spaces match the Gymnasium spec |
345
- | Episodes | Full multi-step episodes run without crashes |
346
- | Agents | `ReasoningAgent` and `RandomAgent` interact with the env |
347
- | Demo | Gradio app imports successfully |
348
- | Graders | Reproduction quality grader loads |
349
- | OpenEnv | `openenv.yaml` is present and well-formed |
350
-
351
- Expected output:
352
-
353
- ```
354
- ENVIRONMENT βœ… PASSED
355
- AGENTS βœ… PASSED
356
- DEMO βœ… PASSED
357
- GRADERS βœ… PASSED
358
- OPENENV_YAML βœ… PASSED
359
-
360
- πŸŽ‰ ALL VALIDATIONS PASSED!
361
- βœ… System is ready for deployment
362
- ```
363
-
364
- ---
365
-
366
- ## 🐳 Docker Deployment
367
-
368
- ```bash
369
- # Build the image
370
- docker build -t reproagent .
371
-
372
- # Run with your API key
373
- docker run -p 7860:7860 -e GROQ_API_KEY=your_key_here reproagent
374
- ```
375
-
376
- Or deploy to **HuggingFace Spaces**:
377
-
378
- ```bash
379
- pip install gradio
380
- gradio deploy
381
- ```
382
-
383
- ---
384
-
385
- ## πŸ›£οΈ Roadmap
386
-
387
- - [x] Gymnasium-compatible environment with 30+ actions
388
- - [x] Groq LLM integration with regex fallback
389
- - [x] Gradio web interface with live logs
390
- - [x] Real Execution mode (git clone, conda/venv, subprocess)
391
- - [x] Dynamic metric extraction (FID, BLEU, accuracy, PSNR, etc.)
392
- - [x] Bash block parsing from README for entry point discovery
393
- - [ ] Multi-script sequential execution (run 5 scripts in order per README)
394
- - [ ] Automatic checkpoint downloading from HuggingFace
395
- - [ ] GPU-aware execution scheduling
396
- - [ ] Result visualization and plot generation
397
- - [ ] Support for Jupyter notebook-based repos
398
-
399
- ---
400
-
401
- ## 🀝 Contributing
402
-
403
- Contributions are welcome! Please:
404
-
405
- 1. Fork the repository
406
- 2. Create a feature branch (`git checkout -b feature/amazing-feature`)
407
- 3. Commit your changes (`git commit -m 'Add amazing feature'`)
408
- 4. Push to the branch (`git push origin feature/amazing-feature`)
409
- 5. Open a Pull Request
410
-
411
- ---
412
-
413
- ## πŸ“ License
414
-
415
- This project is licensed under the **MIT License** β€” see the [LICENSE](LICENSE) file for details.
416
-
417
- ---
418
-
419
- <p align="center">
420
- Built with ❀️ for the ML research community
421
- </p>
 
 
 
 
 
 
 
 
 
 
 
 
1
+ ---
2
+ title: ReproAgent
3
+ emoji: πŸ”¬
4
+ colorFrom: blue
5
+ colorTo: indigo
6
+ sdk: gradio
7
+ sdk_version: 4.12.0
8
+ app_file: server/app.py
9
+ pinned: false
10
+ ---
11
+
12
+ <p align="center">
13
+ <img src="assets/banner.png" alt="ReproAgent Banner" width="100%"/>
14
+ </p>
15
+
16
+ <h1 align="center">πŸ”¬ ReproAgent</h1>
17
+
18
+ <p align="center">
19
+ <strong>An AI-powered agent that automatically reproduces machine learning research papers.</strong>
20
+ </p>
21
+
22
+ <p align="center">
23
+ <a href="#-features"><img src="https://img.shields.io/badge/Features-8-blue?style=for-the-badge" alt="Features"/></a>
24
+ <a href="#-quick-start"><img src="https://img.shields.io/badge/Python-3.10+-green?style=for-the-badge&logo=python&logoColor=white" alt="Python"/></a>
25
+ <a href="#-license"><img src="https://img.shields.io/badge/License-MIT-orange?style=for-the-badge" alt="License"/></a>
26
+ <a href="https://huggingface.co/spaces"><img src="https://img.shields.io/badge/πŸ€—-HuggingFace_Spaces-yellow?style=for-the-badge" alt="HF Spaces"/></a>
27
+ </p>
28
+
29
+ <p align="center">
30
+ Upload a research paper PDF β†’ ReproAgent reads it β†’ finds the repo β†’ clones the code β†’ sets up the environment β†’ runs it β†’ debugs errors β†’ tunes hyperparameters β†’ compares results.
31
+ </p>
32
+
33
+ ---
34
+
35
+ ## πŸ† OpenEnv Hackathon Submission
36
+
37
+ This project is submitted to the **OpenEnv Hackathon**. It is a fully compliant environment built on top of the framework.
38
+
39
+ ### Required Materials
40
+ - **Hugging Face Space**: [ReproAgent Live Demo](https://huggingface.co/spaces/username/reproagent)
41
+ - **Training Script (TRL/PPO)**: [Colab Notebook](training/train_reproagent.ipynb)
42
+ - **Evidence of Training**: We trained the agent using Proximal Policy Optimization (PPO) over 50 episodes.
43
+ <br><img src="assets/reward_plot.png" alt="Reward Plot" width="400"/> <img src="assets/loss_plot.png" alt="Loss Plot" width="400"/>
44
+ - **Presentation**: [Mini-Blog on HuggingFace](https://huggingface.co/blog/reproagent-openenv) / [YouTube Demo (< 2 minutes)](https://youtube.com/watch?v=demo_link)
45
+
46
+ ---
47
+
48
+ ## πŸ“– Table of Contents
49
+
50
+ - [Overview](#-overview)
51
+ - [Features](#-features)
52
+ - [Architecture](#-architecture)
53
+ - [Quick Start](#-quick-start)
54
+ - [Usage](#-usage)
55
+ - [Project Structure](#-project-structure)
56
+ - [Configuration](#-configuration)
57
+ - [How It Works](#-how-it-works)
58
+ - [Validation](#-validation)
59
+ - [Docker Deployment](#-docker-deployment)
60
+ - [Contributing](#-contributing)
61
+ - [License](#-license)
62
+
63
+ ---
64
+
65
+ ## 🌟 Overview
66
+
67
+ **ReproAgent** is an AI-driven framework built on [OpenAI Gymnasium](https://gymnasium.farama.org/) that automates the end-to-end reproduction of machine learning research papers. Given a PDF, it autonomously:
68
+
69
+ 1. **Parses** the paper to extract title, metrics, datasets, and GitHub links
70
+ 2. **Clones** the linked repository
71
+ 3. **Sets up** the environment (conda/venv) and installs dependencies
72
+ 4. **Runs** inference or training scripts
73
+ 5. **Debugs** errors using real traceback analysis
74
+ 6. **Tunes** hyperparameters to close the gap between reproduced and claimed results
75
+ 7. **Compares** final metrics against the paper's claims
76
+
77
+ It supports both a **Simulation** mode (safe, no system changes) and a **Real Execution** mode (actually clones repos, creates envs, runs code on your machine).
78
+
79
+ ---
80
+
81
+ ## ✨ Features
82
+
83
+ | Feature | Description |
84
+ |---------|-------------|
85
+ | πŸ“„ **PDF Parsing** | Extracts metadata using Groq LLM (llama-3.3-70b) with regex fallback |
86
+ | πŸ”— **Repo Discovery** | Finds GitHub links from paper text, cleans trailing punctuation |
87
+ | πŸ“¦ **Smart Environment Setup** | Auto-detects `requirements.txt`, `environment.yml`, or `pyproject.toml` and creates the correct env (pip venv or conda) |
88
+ | 🧠 **Intelligent Entry Point** | Scans for `inference.py`, `eval.py`, `main.py`, `train.py`, or extracts scripts from README bash blocks |
89
+ | πŸ› **Real Error Debugging** | Captures actual `stderr` tracebacks and feeds them into the debugging pipeline |
90
+ | πŸ§ͺ **Hyperparameter Tuning** | Modifies learning rate, batch size, optimizer, and epochs to reproduce paper metrics |
91
+ | πŸ“Š **Dynamic Metric Extraction** | Extracts the actual evaluation metric (FID, BLEU, accuracy, PSNR, etc.) from the paper β€” not hardcoded |
92
+ | πŸ–₯️ **Gradio Web UI** | Beautiful web interface with live logs, state tracking, and result visualization |
93
+
94
+ ---
95
+
96
+ ## πŸ—οΈ Architecture
97
+
98
+ ```
99
+ β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”
100
+ β”‚ Gradio Web UI β”‚
101
+ β”‚ (server/app.py) β”‚
102
+ β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”¬β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜
103
+ β”‚
104
+ β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β–Όβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”
105
+ β”‚ Reasoning Agent β”‚
106
+ β”‚ (agents/reasoning_ β”‚
107
+ β”‚ agent.py) β”‚
108
+ β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”¬β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜
109
+ β”‚ select_action()
110
+ β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β–Όβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”
111
+ β”‚ Gymnasium Environment β”‚
112
+ β”‚ (reproagent/ β”‚
113
+ β”‚ environment.py) β”‚
114
+ β”‚ β”‚
115
+ β”‚ β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β” β”‚
116
+ β”‚ β”‚ State Machine β”‚ β”‚
117
+ β”‚ β”‚ β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β” β”‚ β”‚
118
+ β”‚ β”‚ β”‚ Parsing β”‚ β”‚ β”‚
119
+ β”‚ β”‚ β”‚ RepoAnalysβ”‚ β”‚ β”‚
120
+ β”‚ β”‚ β”‚ Setup β”‚ β”‚ β”‚
121
+ β”‚ β”‚ β”‚ Execution β”‚ β”‚ β”‚
122
+ β”‚ β”‚ β”‚ Debugging β”‚ β”‚ β”‚
123
+ β”‚ β”‚ β”‚ Experimentβ”‚ β”‚ β”‚
124
+ β”‚ β”‚ β”‚ Comparisonβ”‚ β”‚ β”‚
125
+ β”‚ β”‚ β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜ β”‚ β”‚
126
+ β”‚ β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜ β”‚
127
+ β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜
128
+ β”‚ β”‚
129
+ β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜ └──────────┐
130
+ β–Ό β–Ό
131
+ β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β” β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”
132
+ β”‚ Simulation β”‚ β”‚ Real Execution β”‚
133
+ β”‚ (mock state β”‚ β”‚ (subprocess, β”‚
134
+ β”‚ transitions)β”‚ β”‚ git clone, β”‚
135
+ β”‚ β”‚ β”‚ conda/venv) β”‚
136
+ β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜ β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜
137
+ ```
138
+
139
+ ---
140
+
141
+ ## πŸš€ Quick Start
142
+
143
+ ### Prerequisites
144
+
145
+ - **Python** 3.10+
146
+ - **Git** (for real execution mode)
147
+ - **Conda** (optional, for repos that use `environment.yml`)
148
+ - A **Groq API key** (free at [console.groq.com](https://console.groq.com))
149
+
150
+ ### Installation
151
+
152
+ ```bash
153
+ # 1. Clone the repository
154
+ git clone https://github.com/your-username/ReproAgent.git
155
+ cd ReproAgent
156
+
157
+ # 2. Create a virtual environment
158
+ python -m venv venv
159
+
160
+ # Windows
161
+ .\venv\Scripts\activate
162
+
163
+ # macOS/Linux
164
+ source venv/bin/activate
165
+
166
+ # 3. Install dependencies
167
+ pip install -r requirements.txt
168
+
169
+ # 4. Set up environment variables
170
+ cp .env.example .env
171
+ # Edit .env and add your GROQ_API_KEY
172
+ ```
173
+
174
+ ### Run
175
+
176
+ ```bash
177
+ # Launch the Gradio web interface
178
+ python server/app.py
179
+ ```
180
+
181
+ The UI will be available at `http://localhost:7860` with a public share link.
182
+
183
+ ---
184
+
185
+ ## πŸ’» Usage
186
+
187
+ ### Web Interface (Recommended)
188
+
189
+ 1. Open the Gradio UI at `http://localhost:7860`
190
+ 2. **Upload** a research paper PDF (or paste a URL)
191
+ 3. Choose **Execution Mode**:
192
+ - `Simulation` β€” Safe demo, no system changes
193
+ - `Real Execution` β€” Actually clones repos and runs code
194
+ 4. Set **Clone Directory** (where repos will be cloned, e.g. `D:\reproductions`)
195
+ 5. Click **Start Reproduction** and watch the agent work in real-time
196
+
197
+ ### Command Line
198
+
199
+ ```bash
200
+ # Run validation to ensure everything works
201
+ python validate.py
202
+
203
+ # Run a quick inference test
204
+ python inference.py
205
+ ```
206
+
207
+ ### Programmatic API
208
+
209
+ ```python
210
+ from reproagent.environment import ReproAgentEnv
211
+ from agents.reasoning_agent import create_agent
212
+
213
+ # Create environment
214
+ env = ReproAgentEnv(
215
+ difficulty="easy",
216
+ max_steps=100,
217
+ use_llm=True,
218
+ exec_mode="Real Execution",
219
+ workspace_dir="./workspace"
220
+ )
221
+
222
+ # Create agent
223
+ agent = create_agent(env, agent_type="reasoning", use_llm=True)
224
+
225
+ # Run episode
226
+ obs, info = env.reset()
227
+ agent.reset()
228
+
229
+ for step in range(100):
230
+ action = agent.select_action(obs, info)
231
+ obs, reward, terminated, truncated, info = env.step(action)
232
+
233
+ print(f"Step {step}: {info['action_type']} | reward={reward:.2f}")
234
+
235
+ if terminated or truncated:
236
+ break
237
+ ```
238
+
239
+ ---
240
+
241
+ ## πŸ“ Project Structure
242
+
243
+ ```
244
+ ReproAgent/
245
+ β”œβ”€β”€ reproagent/ # Core Gymnasium environment
246
+ β”‚ β”œβ”€β”€ __init__.py
247
+ β”‚ β”œβ”€β”€ environment.py # Main env with action implementations
248
+ β”‚ β”œβ”€β”€ state.py # Dataclasses for full reproduction state
249
+ β”‚ β”œβ”€β”€ actions.py # Action space definition (30+ actions)
250
+ β”‚ β”œβ”€β”€ reward.py # Multi-component reward function
251
+ β”‚ β”œβ”€β”€ models.py # LLM client (Groq, OpenAI, HuggingFace)
252
+ β”‚ └── papers.py # Paper dataset loader
253
+ β”‚
254
+ β”œβ”€β”€ agents/ # Agent implementations
255
+ β”‚ β”œβ”€β”€ reasoning_agent.py # Phase-based reasoning agent
256
+ β”‚ β”œβ”€β”€ paper_parser.py # PDF text extraction + LLM analysis
257
+ β”‚ β”œβ”€β”€ repo_analyzer.py # Repository structure analysis
258
+ β”‚ └── debugger.py # Error traceback analysis
259
+ β”‚
260
+ β”œβ”€β”€ server/
261
+ β”‚ └── app.py # Gradio web interface (900+ lines)
262
+ β”‚
263
+ β”œβ”€β”€ utils/
264
+ β”‚ β”œβ”€β”€ pdf_reader.py # PDF extraction (PyPDF2 + pdfplumber)
265
+ β”‚ └── github_utils.py # GitHub API utilities
266
+ β”‚
267
+ β”œβ”€β”€ graders/ # Reproduction quality grading
268
+ β”œβ”€β”€ data/papers/ # Sample paper configs (easy/medium/hard)
269
+ β”œβ”€β”€ baseline/ # Baseline agent implementations
270
+ β”œβ”€β”€ static/ # Static assets for UI
271
+ β”‚
272
+ β”œβ”€β”€ validate.py # Full validation suite
273
+ β”œβ”€β”€ inference.py # CLI inference entry point
274
+ β”œβ”€β”€ openenv.yaml # OpenEnv compatibility spec
275
+ β”œβ”€β”€ pyproject.toml # Python project metadata
276
+ β”œβ”€β”€ requirements.txt # pip dependencies
277
+ β”œβ”€β”€ Dockerfile # Container deployment
278
+ β”œβ”€β”€ run.bat / run.sh / run.ps1 # Platform-specific launchers
279
+ └── .env.example # Environment variable template
280
+ ```
281
+
282
+ ---
283
+
284
+ ## βš™οΈ Configuration
285
+
286
+ ### Environment Variables
287
+
288
+ Create a `.env` file from the template:
289
+
290
+ ```bash
291
+ cp .env.example .env
292
+ ```
293
+
294
+ | Variable | Required | Description |
295
+ |----------|----------|-------------|
296
+ | `GROQ_API_KEY` | **Yes** | Groq API key for LLM-powered extraction ([get one free](https://console.groq.com)) |
297
+ | `OPENAI_API_KEY` | No | OpenAI API key (alternative LLM backend) |
298
+ | `HF_TOKEN` | No | HuggingFace token for model downloads |
299
+ | `GITHUB_TOKEN` | No | GitHub API token for higher rate limits |
300
+
301
+ ### Execution Modes
302
+
303
+ | Mode | What it does | Use case |
304
+ |------|-------------|----------|
305
+ | **Simulation** | Simulates all actions with mock state transitions | Safe demos, hackathons, testing |
306
+ | **Real Execution** | Runs `git clone`, `conda env create`, `pip install`, `python script.py` on your system | Actually reproducing papers |
307
+
308
+ ---
309
+
310
+ ## πŸ”„ How It Works
311
+
312
+ The agent follows a **phase-based state machine** with 7 phases:
313
+
314
+ ```
315
+ PARSING β†’ REPO_ANALYSIS β†’ SETUP β†’ EXECUTION β†’ DEBUGGING β†’ EXPERIMENTATION β†’ COMPARISON
316
+ ```
317
+
318
+ ### Phase Details
319
+
320
+ | Phase | Actions | What Happens |
321
+ |-------|---------|--------------|
322
+ | **Parsing** | `PARSE_PDF`, `EXTRACT_GITHUB`, `EXTRACT_METRICS` | LLM reads paper, extracts title, GitHub URL, target metric (e.g., FID=7.5) |
323
+ | **Repo Analysis** | `CLONE_REPO`, `READ_README`, `FIND_ENTRY_POINT`, `EXTRACT_DEPS` | Clones repo, reads README, finds scripts from bash blocks, detects `environment.yml` |
324
+ | **Setup** | `CREATE_VENV`, `INSTALL_REQUIREMENTS`, `VERIFY_SETUP` | Creates conda/venv env, installs deps, verifies setup |
325
+ | **Execution** | `RUN_TRAINING`, `RUN_EVAL`, `CHECK_LOGS` | Runs the entry point script via subprocess, captures stdout/stderr |
326
+ | **Debugging** | `ANALYZE_ERROR`, `SEARCH_SOLUTION`, `APPLY_FIX` | Parses real Python tracebacks, proposes and applies fixes |
327
+ | **Experimentation** | `MODIFY_LR`, `MODIFY_BATCH`, `RUN_EXPERIMENT` | Tunes hyperparameters to close the metric gap |
328
+ | **Comparison** | `COMPARE_RESULTS`, `GENERATE_REPORT` | Compares reproduced metric vs. paper claim, generates summary |
329
+
330
+ ### Reward Function
331
+
332
+ The environment provides a multi-component reward signal:
333
+
334
+ - **Phase progress** (+10 for advancing through phases)
335
+ - **Code execution** (+20 for successful script runs)
336
+ - **Error fixing** (+15 per resolved error)
337
+ - **Metric improvement** (scaled by how close the reproduced result is to the paper's claim)
338
+ - **Time penalty** (-0.01 per step to encourage efficiency)
339
+
340
+ ---
341
+
342
+ ## βœ… Validation
343
+
344
+ Run the full validation suite to confirm everything works:
345
+
346
+ ```bash
347
+ python validate.py
348
+ ```
349
+
350
+ This tests:
351
+
352
+ | Test | What it validates |
353
+ |------|-------------------|
354
+ | Environment | `ReproAgentEnv` creates, resets, steps correctly |
355
+ | Spaces | Observation and action spaces match the Gymnasium spec |
356
+ | Episodes | Full multi-step episodes run without crashes |
357
+ | Agents | `ReasoningAgent` and `RandomAgent` interact with the env |
358
+ | Demo | Gradio app imports successfully |
359
+ | Graders | Reproduction quality grader loads |
360
+ | OpenEnv | `openenv.yaml` is present and well-formed |
361
+
362
+ Expected output:
363
+
364
+ ```
365
+ ENVIRONMENT βœ… PASSED
366
+ AGENTS βœ… PASSED
367
+ DEMO βœ… PASSED
368
+ GRADERS βœ… PASSED
369
+ OPENENV_YAML βœ… PASSED
370
+
371
+ πŸŽ‰ ALL VALIDATIONS PASSED!
372
+ βœ… System is ready for deployment
373
+ ```
374
+
375
+ ---
376
+
377
+ ## 🐳 Docker Deployment
378
+
379
+ ```bash
380
+ # Build the image
381
+ docker build -t reproagent .
382
+
383
+ # Run with your API key
384
+ docker run -p 7860:7860 -e GROQ_API_KEY=your_key_here reproagent
385
+ ```
386
+
387
+ Or deploy to **HuggingFace Spaces**:
388
+
389
+ ```bash
390
+ pip install gradio
391
+ gradio deploy
392
+ ```
393
+
394
+ ---
395
+
396
+ ## πŸ›£οΈ Roadmap
397
+
398
+ - [x] Gymnasium-compatible environment with 30+ actions
399
+ - [x] Groq LLM integration with regex fallback
400
+ - [x] Gradio web interface with live logs
401
+ - [x] Real Execution mode (git clone, conda/venv, subprocess)
402
+ - [x] Dynamic metric extraction (FID, BLEU, accuracy, PSNR, etc.)
403
+ - [x] Bash block parsing from README for entry point discovery
404
+ - [ ] Multi-script sequential execution (run 5 scripts in order per README)
405
+ - [ ] Automatic checkpoint downloading from HuggingFace
406
+ - [ ] GPU-aware execution scheduling
407
+ - [ ] Result visualization and plot generation
408
+ - [ ] Support for Jupyter notebook-based repos
409
+
410
+ ---
411
+
412
+ ## 🀝 Contributing
413
+
414
+ Contributions are welcome! Please:
415
+
416
+ 1. Fork the repository
417
+ 2. Create a feature branch (`git checkout -b feature/amazing-feature`)
418
+ 3. Commit your changes (`git commit -m 'Add amazing feature'`)
419
+ 4. Push to the branch (`git push origin feature/amazing-feature`)
420
+ 5. Open a Pull Request
421
+
422
+ ---
423
+
424
+ ## πŸ“ License
425
+
426
+ This project is licensed under the **MIT License** β€” see the [LICENSE](LICENSE) file for details.
427
+
428
+ ---
429
+
430
+ <p align="center">
431
+ Built with ❀️ for the ML research community
432
+ </p>