Spaces:
Sleeping
Sleeping
Update annotated_casl_app.py
Browse files- annotated_casl_app.py +13 -3
annotated_casl_app.py
CHANGED
|
@@ -28,8 +28,15 @@ def clean_output_formatting(text):
|
|
| 28 |
text = text.replace('**', '') # Remove any remaining **
|
| 29 |
text = text.replace('*', '') # Remove any remaining *
|
| 30 |
|
| 31 |
-
# Remove hashtags from headers
|
| 32 |
-
text = re.sub(r'^#{1,6}\s
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 33 |
|
| 34 |
# Convert tables to lists - more comprehensive approach
|
| 35 |
lines = text.split('\n')
|
|
@@ -168,7 +175,10 @@ def call_claude_api_quick_analysis(prompt):
|
|
| 168 |
|
| 169 |
if response.status_code == 200:
|
| 170 |
response_json = response.json()
|
| 171 |
-
|
|
|
|
|
|
|
|
|
|
| 172 |
else:
|
| 173 |
logger.error(f"Claude API error: {response.status_code} - {response.text}")
|
| 174 |
return f"Error: Claude API Error: {response.status_code}"
|
|
|
|
| 28 |
text = text.replace('**', '') # Remove any remaining **
|
| 29 |
text = text.replace('*', '') # Remove any remaining *
|
| 30 |
|
| 31 |
+
# Remove hashtags from headers (at start of line)
|
| 32 |
+
text = re.sub(r'^#{1,6}\s+', '', text, flags=re.MULTILINE) # Remove ### headers
|
| 33 |
+
|
| 34 |
+
# Also remove hashtags that appear mid-sentence or in other positions
|
| 35 |
+
text = re.sub(r'\s#{1,6}\s+', ' ', text) # Remove hashtags with spaces around them
|
| 36 |
+
text = re.sub(r'#{1,6}([A-Z])', r'\1', text) # Remove # before capitalized words like #SECTION
|
| 37 |
+
text = re.sub(r'^#{1,6}$', '', text, flags=re.MULTILINE) # Remove standalone hashtags on a line
|
| 38 |
+
text = re.sub(r'#([a-zA-Z])', r'\1', text) # Remove # before any word
|
| 39 |
+
text = text.replace('#', '') # Remove any remaining bare # symbols
|
| 40 |
|
| 41 |
# Convert tables to lists - more comprehensive approach
|
| 42 |
lines = text.split('\n')
|
|
|
|
| 175 |
|
| 176 |
if response.status_code == 200:
|
| 177 |
response_json = response.json()
|
| 178 |
+
raw_response = response_json['content'][0]['text']
|
| 179 |
+
# Clean formatting from response (removes **, #, tables)
|
| 180 |
+
cleaned_response = clean_output_formatting(raw_response)
|
| 181 |
+
return cleaned_response
|
| 182 |
else:
|
| 183 |
logger.error(f"Claude API error: {response.status_code} - {response.text}")
|
| 184 |
return f"Error: Claude API Error: {response.status_code}"
|