-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathfile_summarizer.py
More file actions
62 lines (47 loc) · 1.4 KB
/
file_summarizer.py
File metadata and controls
62 lines (47 loc) · 1.4 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
#!/usr/bin/env python3
"""
File summarizer - AI-powered text file summarization.
"""
import asyncio
import sys
from pathlib import Path
from copilot import CopilotClient
async def main():
"""Summarize a text file using Copilot."""
if len(sys.argv) < 2:
print("Usage: python file_summarizer.py <file-path>")
print("\nExample:")
print(" python file_summarizer.py README.md")
sys.exit(1)
file_path = Path(sys.argv[1])
if not file_path.exists():
print(f"❌ Error: File not found: {file_path}")
sys.exit(1)
# Read the file
content = file_path.read_text(encoding='utf-8')
print(f"📄 Summarizing: {file_path.name}")
print(f"📊 Size: {len(content)} characters\n")
client = CopilotClient()
await client.start()
try:
session = await client.create_session({"model": "gpt-5-mini"})
prompt = f"""Summarize this file in a clear, concise way:
File: {file_path.name}
Content:
```
{content}
```
Provide:
1. Main purpose/topic
2. Key points (3-5 bullets)
3. Target audience (if identifiable)
"""
print("🤖 Summary:\n")
response = await session.send_and_wait({"prompt": prompt})
print(response.data.content)
print("\n✅ Summary complete!")
await session.destroy()
finally:
await client.stop()
if __name__ == "__main__":
asyncio.run(main())