alexorlov commited on
Commit
de5fcc2
·
verified ·
1 Parent(s): db68bd8

Upload app/services/file_generator.py with huggingface_hub

Browse files
Files changed (1) hide show
  1. app/services/file_generator.py +13 -58
app/services/file_generator.py CHANGED
@@ -1,64 +1,19 @@
1
- from typing import List
2
- from datetime import datetime
3
- from app.models.checklist import ChecklistItem
4
 
5
 
6
- class FileGenerator:
7
- @staticmethod
8
- def generate_markdown(
9
- session_id: str,
10
- checklist: List[ChecklistItem],
11
- round_summaries: List[str]
12
- ) -> str:
13
- """Генерирует Markdown файл с результатами чеклиста"""
14
-
15
- date = datetime.now().strftime("%Y-%m-%d %H:%M")
16
-
17
- md_content = f"""# Чеклист созвона с клиентом
18
 
19
- **Дата:** {date}
20
- **Сессия:** {session_id}
 
21
 
22
- ---
23
 
24
- """
25
- # Группируем по категориям
26
- categories = {}
27
- for item in checklist:
28
- if item.category not in categories:
29
- categories[item.category] = []
30
- categories[item.category].append(item)
31
 
32
- # Маппинг статусов на чекбоксы
33
- status_map = {
34
- "confirmed": "[x]",
35
- "needs_clarification": "[ ] ⚠️",
36
- "not_discussed": "[ ]"
37
- }
38
-
39
- for category, items in categories.items():
40
- md_content += f"## {category}\n\n"
41
- for item in items:
42
- checkbox = status_map.get(item.status, "[ ]")
43
- line = f"- {checkbox} {item.item}"
44
- if item.notes:
45
- line += f" *({item.notes})*"
46
- md_content += line + "\n"
47
- md_content += "\n"
48
-
49
- # Добавляем саммари раундов
50
- if round_summaries:
51
- md_content += "---\n\n## Саммари интервью\n\n"
52
- for i, summary in enumerate(round_summaries, 1):
53
- md_content += f"**Раунд {i}:** {summary}\n\n"
54
-
55
- md_content += """---
56
-
57
- *Сгенерировано автоматически с помощью AI Checklist Agent*
58
- """
59
-
60
- return md_content
61
-
62
-
63
- def get_file_generator() -> FileGenerator:
64
- return FileGenerator()
 
1
+ from datetime import date
 
 
2
 
3
 
4
+ def post_process_markdown(markdown: str, session_id: str) -> str:
5
+ """Clean up and ensure consistent markdown formatting."""
6
+ lines = markdown.strip().split("\n")
 
 
 
 
 
 
 
 
 
7
 
8
+ # Ensure it starts with the expected header
9
+ if not lines[0].startswith("# "):
10
+ lines.insert(0, "# Чеклист созвона с клиентом")
11
 
12
+ content = "\n".join(lines)
13
 
14
+ # Ensure footer exists
15
+ footer = "\n---\n\n*Сгенерировано автоматически с помощью AI Checklist Agent*\n"
16
+ if "Сгенерировано автоматически" not in content:
17
+ content += footer
 
 
 
18
 
19
+ return content