File size: 5,880 Bytes
63bcd5a
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
cff9d3b
 
 
63bcd5a
 
 
 
 
 
 
 
 
 
 
 
 
b09149c
63bcd5a
 
 
 
4552666
 
 
63bcd5a
 
 
 
 
 
cff9d3b
63bcd5a
 
cff9d3b
63bcd5a
4552666
 
 
63bcd5a
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
4552666
 
 
63bcd5a
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
4552666
 
 
63bcd5a
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
4552666
b09149c
 
 
 
 
 
 
 
 
 
c2a8167
 
 
 
b09149c
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
from src.recommendation_engine.llm_client import generate_text
from src.recommendation_engine.prompt_builder import (
    build_full_project_prompt
)

import re

def extract_section(text, section_name):

    text = text.strip()

    marker = section_name + ":"

    if marker not in text:
        return ""

    start = text.find(marker) + len(marker)

    sections = [
        "CATEGORY:",
        "ABSTRACT:",
        "DESCRIPTION:",
        "TECHNOLOGIES:",
        "KEYWORDS:",
        "PROBLEM_STATEMENT:",
        "PROPOSED_SOLUTION:",
        "OBJECTIVES:",
        "AI_SUMMARY:",
        "FUTURE_WORK:",
        "METHODOLOGY:"
    ]

    end = len(text)

    for s in sections:

        if s == marker:
            continue

        pos = text.find(s, start)

        if pos != -1 and pos < end:
            end = pos

    return text[start:end].strip()

def parse_bullets(text):

    lines = text.splitlines()

    final = []

    for line in lines:

        line = line.strip()

        if not line:
            continue

        line = re.sub(
            r"^[-•*0-9.\)\s]+",
            "",
            line
        )

        if line:
            final.append(line)

    return final

def generate_full_project(
    title,
    features,
    description="",
    abstract="",
    custom_description=False,
    custom_abstract=False
):

    context = {
        "project_title": title,
        "features": features,
        "description": description,
        "abstract": abstract
    }

    prompt = build_full_project_prompt(context)

    raw = generate_text(
        prompt,
        task="full_project"
    )

    result = {

        
        
        
        "project_title": title,

        "category":
            extract_section(raw, "CATEGORY"),

        "abstract":
            abstract if custom_abstract else extract_section(raw, "ABSTRACT"),

        "description":
            description if custom_description else extract_section(raw, "DESCRIPTION"),

        
        
        
        "technologies":
            parse_bullets(
                extract_section(raw, "TECHNOLOGIES")
            ),

        "keywords":
            parse_bullets(
                extract_section(raw, "KEYWORDS")
            ),

        "objectives":
            parse_bullets(
                extract_section(raw, "OBJECTIVES")
            ),

        "future_work":
            parse_bullets(
                extract_section(raw, "FUTURE_WORK")
            ),

        
        
        
        "problem_statement":
            extract_section(
                raw,
                "PROBLEM_STATEMENT"
            ),

        "proposed_solution":
            extract_section(
                raw,
                "PROPOSED_SOLUTION"
            ),

        "methodology":
            extract_section(
                raw,
                "METHODOLOGY"
            ),

        "ai_summary":
            extract_section(
                raw,
                "AI_SUMMARY"
            )
    }

    
    
    

    if not result.get("category"):
        result["category"] = "General AI System"

    if not result.get("keywords"):
        result["keywords"] = [
            "Artificial Intelligence",
            "Automation",
            "Smart System"
        ]

    if not result.get("problem_statement"):
        result["problem_statement"] = (
            "Current traditional systems suffer from "
            "limited automation, inefficiency, and "
            "lack of intelligent decision-making."
        )

    if not result.get("proposed_solution"):
        result["proposed_solution"] = (
            "The proposed system uses AI-driven "
            "automation and intelligent analytics "
            "to improve operational efficiency."
        )

    if not result.get("objectives"):
        result["objectives"] = [
            "Improve automation efficiency",
            "Enhance system accuracy",
            "Reduce operational costs"
        ]

    if not result.get("methodology"):
        result["methodology"] = (
            "The system will be developed using "
            "data collection, preprocessing, "
            "AI model training, testing, and deployment."
        )

    if not result.get("future_work"):
        result["future_work"] = [
            "Cloud integration",
            "Mobile application support",
            "Advanced AI optimization"
        ]

    if not result.get("ai_summary"):
        result["ai_summary"] = (
            f"{title} is an intelligent AI-powered "
            f"graduation project designed to provide "
            f"automation, monitoring, and predictive analysis."
        )

    return result

def rewrite_custom_sections(features, abstract="", description=""):
    features_text = "\n".join(f"- {f}" for f in features)
    
    prompt = f"""
The user provided custom text for their project's abstract and/or description.
Your task is to update their custom text to incorporate the following NEW FEATURES.

CRITICAL RULES:
1. You MUST preserve the exact tone, style, and core phrasing of the user's original text!
2. Just weave the new features in naturally.
3. EXPAND the content significantly to ensure it is highly detailed.
4. The rewritten ABSTRACT MUST contain a minimum of 130 words.
5. The rewritten DESCRIPTION MUST contain a minimum of 160 words.

NEW FEATURES:
{features_text}

CUSTOM ABSTRACT:
{abstract if abstract else "N/A"}

CUSTOM DESCRIPTION:
{description if description else "N/A"}

OUTPUT FORMAT:

ABSTRACT:
(your rewritten abstract here, or leave empty if N/A)

DESCRIPTION:
(your rewritten description here, or leave empty if N/A)
""".strip()

    raw = generate_text(prompt, task="chat")
    
    return {
        "abstract": extract_section(raw, "ABSTRACT") if abstract else "",
        "description": extract_section(raw, "DESCRIPTION") if description else ""
    }