-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathquick_start.py
More file actions
218 lines (167 loc) Β· 6.68 KB
/
quick_start.py
File metadata and controls
218 lines (167 loc) Β· 6.68 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
"""
EditScribe Quick Start Script
Simplifies running the complete editorial workflow
"""
import requests
import json
import sys
import time
from pathlib import Path
class EditScribeClient:
"""Simple client for EditScribe API"""
def __init__(self, base_url="http://localhost:8000"):
self.base_url = base_url
def upload_manuscript(self, file_path):
"""Upload a manuscript file"""
print(f"\nπ€ Uploading manuscript: {file_path}")
with open(file_path, 'rb') as f:
files = {'file': f}
response = requests.post(f"{self.base_url}/upload", files=files)
if response.status_code == 200:
data = response.json()
print(f"β
Upload successful!")
print(f" Manuscript ID: {data['manuscript_id']}")
print(f" Word count: {data['word_count']:,}")
return data['manuscript_id']
else:
print(f"β Upload failed: {response.text}")
return None
def run_stage(self, manuscript_id, stage_name):
"""Run a specific editorial stage"""
print(f"\nπ Running {stage_name.upper()} stage...")
endpoint_map = {
'acquisitions': 'acquisitions',
'developmental': 'developmental',
'line': 'line',
'copy': 'copy',
'proof': 'proof',
'cold-read': 'cold-read'
}
endpoint = endpoint_map.get(stage_name)
if not endpoint:
print(f"β Unknown stage: {stage_name}")
return False
response = requests.post(f"{self.base_url}/workflow/{manuscript_id}/{endpoint}")
if response.status_code == 200:
data = response.json()
print(f"β
{stage_name.upper()} complete!")
if 'total_issues' in data:
print(f" Issues found: {data['total_issues']}")
return True
else:
print(f"β {stage_name.upper()} failed: {response.text}")
return False
def get_workflow_status(self, manuscript_id):
"""Get current workflow status"""
response = requests.get(f"{self.base_url}/workflow/{manuscript_id}/status")
if response.status_code == 200:
return response.json()
return None
def get_stage_result(self, manuscript_id, stage_name):
"""Get results from a completed stage"""
response = requests.get(f"{self.base_url}/workflow/{manuscript_id}/{stage_name}/result")
if response.status_code == 200:
return response.json()
return None
def get_complete_report(self, manuscript_id):
"""Get complete editorial report"""
response = requests.get(f"{self.base_url}/projects/{manuscript_id}/complete-report")
if response.status_code == 200:
return response.json()
return None
def print_banner():
"""Print welcome banner"""
print("="*60)
print("EditScribe - Professional Manuscript Editing System")
print("="*60)
def run_complete_workflow(client, manuscript_id, include_cold_read=True):
"""Run the complete editorial workflow"""
stages = [
'acquisitions',
'developmental',
'line',
'copy',
'proof'
]
if include_cold_read:
stages.append('cold-read')
print(f"\nπ Running {len(stages)} editorial stages...")
for stage in stages:
success = client.run_stage(manuscript_id, stage)
if not success:
print(f"\nβ οΈ Workflow stopped at {stage}")
return False
time.sleep(1) # Brief pause between stages
return True
def save_results(client, manuscript_id, output_dir):
"""Save all results to files"""
output_path = Path(output_dir)
output_path.mkdir(exist_ok=True)
print(f"\nπΎ Saving results to: {output_path}")
# Save complete report
report = client.get_complete_report(manuscript_id)
if report:
with open(output_path / "complete_report.json", 'w') as f:
json.dump(report, f, indent=2)
print(f" β
Saved complete_report.json")
# Save individual stage results
stages = ['acquisitions', 'developmental', 'line', 'copy', 'proof', 'cold-read']
for stage in stages:
result = client.get_stage_result(manuscript_id, stage)
if result:
with open(output_path / f"{stage}_report.json", 'w') as f:
json.dump(result, f, indent=2)
print(f" β
Saved {stage}_report.json")
def main():
"""Main entry point"""
print_banner()
# Check if manuscript file provided
if len(sys.argv) < 2:
print("\nβ Usage: python quick_start.py <manuscript_file.docx>")
print("\nExample:")
print(" python quick_start.py my_novel.docx")
print("\nOptions:")
print(" --no-cold-read Skip the optional Cold Reader stage")
print(" --output-dir DIR Save results to specific directory (default: ./results)")
sys.exit(1)
manuscript_file = sys.argv[1]
include_cold_read = '--no-cold-read' not in sys.argv
# Get output directory
output_dir = "./results"
if '--output-dir' in sys.argv:
idx = sys.argv.index('--output-dir')
if idx + 1 < len(sys.argv):
output_dir = sys.argv[idx + 1]
# Check file exists
if not Path(manuscript_file).exists():
print(f"\nβ File not found: {manuscript_file}")
sys.exit(1)
# Initialize client
client = EditScribeClient()
# Upload manuscript
manuscript_id = client.upload_manuscript(manuscript_file)
if not manuscript_id:
sys.exit(1)
# Run workflow
print(f"\n{'='*60}")
print("Starting Editorial Workflow")
print(f"{'='*60}")
success = run_complete_workflow(client, manuscript_id, include_cold_read)
if success:
print(f"\n{'='*60}")
print("β
WORKFLOW COMPLETE!")
print(f"{'='*60}")
# Save results
save_results(client, manuscript_id, output_dir)
print(f"\nπ Summary:")
print(f" Manuscript ID: {manuscript_id}")
print(f" Results saved to: {output_dir}")
print(f"\nπ‘ Next steps:")
print(f" 1. Review the complete_report.json")
print(f" 2. Check individual stage reports for detailed feedback")
print(f" 3. Review your manuscript in: backend/projects/{manuscript_id}/")
else:
print(f"\nβ Workflow failed. Check the error messages above.")
sys.exit(1)
if __name__ == "__main__":
main()