Spaces:
Sleeping
Sleeping
app_2
Browse files
app.py
CHANGED
|
@@ -159,6 +159,12 @@ def analyze_segment_with_gemini(cluster_text, is_full_text=False):
|
|
| 159 |
timeout=None,
|
| 160 |
max_retries=3
|
| 161 |
)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 162 |
|
| 163 |
if is_full_text:
|
| 164 |
prompt = f"""
|
|
@@ -167,8 +173,19 @@ def analyze_segment_with_gemini(cluster_text, is_full_text=False):
|
|
| 167 |
- Check if it's too short or lacks meaningful content (less than 100 words of substance)
|
| 168 |
- If either case is true, respond with a simple JSON: {{"status": "insufficient", "reason": "Brief explanation"}}
|
| 169 |
|
| 170 |
-
Analyze the following text
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 171 |
|
|
|
|
| 172 |
1. First, do text segmentation and identify DISTINCT key topics within the text
|
| 173 |
2. For each segment/topic you identify:
|
| 174 |
- Provide a SPECIFIC and UNIQUE topic name (3-5 words) that clearly differentiates it from other segments
|
|
@@ -216,25 +233,22 @@ def analyze_segment_with_gemini(cluster_text, is_full_text=False):
|
|
| 216 |
// More segments...
|
| 217 |
]
|
| 218 |
}}
|
| 219 |
-
|
| 220 |
-
|
| 221 |
-
OR if the text is just introductory, concluding, or insufficient:
|
| 222 |
-
{{
|
| 223 |
-
"status": "insufficient",
|
| 224 |
-
"reason": "Brief explanation of why (e.g., 'Text is primarily self-introduction', 'Text is too short', etc.)"
|
| 225 |
-
}}
|
| 226 |
-
|
| 227 |
-
|
| 228 |
-
|
| 229 |
"""
|
| 230 |
else:
|
| 231 |
prompt = f"""
|
| 232 |
-
FIRST ASSESS THE TEXT:
|
| 233 |
-
- Check if it's primarily self-introduction, biographical information, or conclusion
|
| 234 |
-
- Check if it's too short or lacks meaningful content (less than 100 words of substance)
|
| 235 |
-
- If either case is true, respond with a simple JSON: {{"status": "insufficient", "reason": "Brief explanation"}}
|
| 236 |
-
|
| 237 |
Analyze the following text segment and provide:
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 238 |
1. A SPECIFIC and DESCRIPTIVE topic name (3-5 words) that precisely captures the main focus
|
| 239 |
2. 3-5 key concepts discussed
|
| 240 |
3. A brief summary (6-7 sentences)
|
|
@@ -275,14 +289,6 @@ def analyze_segment_with_gemini(cluster_text, is_full_text=False):
|
|
| 275 |
// More questions...
|
| 276 |
]
|
| 277 |
}}
|
| 278 |
-
|
| 279 |
-
OR if the text is just introductory, concluding, or insufficient:
|
| 280 |
-
{{
|
| 281 |
-
"status": "insufficient",
|
| 282 |
-
"reason": "Brief explanation of why (e.g., 'Text is primarily self-introduction', 'Text is too short', etc.)"
|
| 283 |
-
}}
|
| 284 |
-
|
| 285 |
-
|
| 286 |
"""
|
| 287 |
|
| 288 |
response = llm.invoke(prompt)
|
|
|
|
| 159 |
timeout=None,
|
| 160 |
max_retries=3
|
| 161 |
)
|
| 162 |
+
|
| 163 |
+
if len(cluster_text.split()) < 50:
|
| 164 |
+
return {
|
| 165 |
+
"status": "insufficient",
|
| 166 |
+
"reason": f"Text is too short ({len(cluster_text.split())} words). Minimum 50 words required for analysis."
|
| 167 |
+
}
|
| 168 |
|
| 169 |
if is_full_text:
|
| 170 |
prompt = f"""
|
|
|
|
| 173 |
- Check if it's too short or lacks meaningful content (less than 100 words of substance)
|
| 174 |
- If either case is true, respond with a simple JSON: {{"status": "insufficient", "reason": "Brief explanation"}}
|
| 175 |
|
| 176 |
+
Analyze the following text:
|
| 177 |
+
FIRST ASSESS THE TEXT:
|
| 178 |
+
- Is it primarily self-introduction, biographical information, or conclusion?
|
| 179 |
+
- Does it lack meaningful content for analysis?
|
| 180 |
+
|
| 181 |
+
IF THE TEXT IS INSUFFICIENT (introductory, concluding, or lacking substance):
|
| 182 |
+
Return ONLY this JSON structure:
|
| 183 |
+
{{
|
| 184 |
+
"status": "insufficient",
|
| 185 |
+
"reason": "Brief explanation (e.g., 'Text is primarily self-introduction', 'Text lacks substantive content')"
|
| 186 |
+
}}
|
| 187 |
|
| 188 |
+
IF THE TEXT HAS SUFFICIENT MEANINGFUL CONTENT:
|
| 189 |
1. First, do text segmentation and identify DISTINCT key topics within the text
|
| 190 |
2. For each segment/topic you identify:
|
| 191 |
- Provide a SPECIFIC and UNIQUE topic name (3-5 words) that clearly differentiates it from other segments
|
|
|
|
| 233 |
// More segments...
|
| 234 |
]
|
| 235 |
}}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 236 |
"""
|
| 237 |
else:
|
| 238 |
prompt = f"""
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 239 |
Analyze the following text segment and provide:
|
| 240 |
+
FIRST ASSESS THE TEXT:
|
| 241 |
+
- Is it primarily self-introduction, biographical information, or conclusion?
|
| 242 |
+
- Does it lack meaningful content for analysis?
|
| 243 |
+
|
| 244 |
+
IF THE TEXT IS INSUFFICIENT (introductory, concluding, or lacking substance):
|
| 245 |
+
Return ONLY this JSON structure:
|
| 246 |
+
{{
|
| 247 |
+
"status": "insufficient",
|
| 248 |
+
"reason": "Brief explanation (e.g., 'Text is primarily self-introduction', 'Text lacks substantive content')"
|
| 249 |
+
}}
|
| 250 |
+
|
| 251 |
+
IF THE TEXT HAS SUFFICIENT MEANINGFUL CONTENT:
|
| 252 |
1. A SPECIFIC and DESCRIPTIVE topic name (3-5 words) that precisely captures the main focus
|
| 253 |
2. 3-5 key concepts discussed
|
| 254 |
3. A brief summary (6-7 sentences)
|
|
|
|
| 289 |
// More questions...
|
| 290 |
]
|
| 291 |
}}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 292 |
"""
|
| 293 |
|
| 294 |
response = llm.invoke(prompt)
|