Spaces:
Sleeping
Sleeping
Commit
·
2ee7e44
1
Parent(s):
3e8379a
made changes in inference.py file
Browse files- app/inference_api.py +36 -15
- constraints.txt +0 -0
- requirements-base.txt +0 -0
app/inference_api.py
CHANGED
@@ -54,26 +54,47 @@ RECOMMENDATIONS:
|
|
54 |
"processing_time": processing_time
|
55 |
}
|
56 |
|
57 |
-
#
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
58 |
import re
|
59 |
-
|
|
|
|
|
|
|
|
|
|
|
60 |
if match:
|
61 |
-
cleaned_response =
|
62 |
-
# Verify the output has the required structure
|
63 |
-
if not re.search(r"(?i)safety\s*assessment\s*:", cleaned_response) and not re.search(r"(?i)recommendations\s*:", cleaned_response):
|
64 |
-
# Missing required sections, return default message
|
65 |
-
return {
|
66 |
-
"response": "Model failed to generate proper analysis. Please try again.",
|
67 |
-
"status": "success",
|
68 |
-
"model_used": "huggingface-qwen-fallback",
|
69 |
-
"prompt": prompt,
|
70 |
-
"processing_time": processing_time
|
71 |
-
}
|
72 |
else:
|
73 |
-
#
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
74 |
return {
|
75 |
"response": "Model failed to generate proper analysis. Please try again.",
|
76 |
-
"status": "success",
|
77 |
"model_used": "huggingface-qwen-fallback",
|
78 |
"prompt": prompt,
|
79 |
"processing_time": processing_time
|
|
|
54 |
"processing_time": processing_time
|
55 |
}
|
56 |
|
57 |
+
# Clean up the response - remove unwanted instructional text
|
58 |
+
cleaned_response = raw_response
|
59 |
+
|
60 |
+
# Remove the specific problematic text and similar variations
|
61 |
+
unwanted_texts = [
|
62 |
+
"If there is no need for recommendations, don't provide them.",
|
63 |
+
"If there is no need for recommendations, don't provide them",
|
64 |
+
"If there is no need for recommendations, do not provide them.",
|
65 |
+
"If there is no need for recommendations, do not provide them",
|
66 |
+
"If no recommendations are needed, don't provide them.",
|
67 |
+
"If no recommendations are needed, don't provide them",
|
68 |
+
"Don't provide recommendations if not needed.",
|
69 |
+
"Don't provide recommendations if not needed"
|
70 |
+
]
|
71 |
+
|
72 |
+
for unwanted_text in unwanted_texts:
|
73 |
+
cleaned_response = cleaned_response.replace(unwanted_text, "").strip()
|
74 |
+
|
75 |
+
# Remove any text that appears before the actual analysis
|
76 |
+
# Look for patterns like "OVERVIEW", "ANALYSIS", etc. followed by the unwanted text
|
77 |
import re
|
78 |
+
|
79 |
+
# Remove any instructional text that might appear at the beginning
|
80 |
+
cleaned_response = re.sub(r'^.*?(?=SAFETY\s*STATUS\s*:|SAFETY\s*ASSESSMENT\s*:)', '', cleaned_response, flags=re.IGNORECASE | re.DOTALL).strip()
|
81 |
+
|
82 |
+
# Try to find SAFETY STATUS first
|
83 |
+
match = re.search(r"(?i)safety\s*status\s*:", cleaned_response)
|
84 |
if match:
|
85 |
+
cleaned_response = cleaned_response[match.start():].strip()
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
86 |
else:
|
87 |
+
# If no SAFETY STATUS, try to find SAFETY ASSESSMENT
|
88 |
+
match = re.search(r"(?i)safety\s*assessment\s*:", cleaned_response)
|
89 |
+
if match:
|
90 |
+
cleaned_response = "SAFETY STATUS: SAFE\n\n" + cleaned_response[match.start():].strip()
|
91 |
+
|
92 |
+
# Verify the output has the required structure
|
93 |
+
if not re.search(r"(?i)safety\s*assessment\s*:", cleaned_response):
|
94 |
+
# Missing required sections, return default message
|
95 |
return {
|
96 |
"response": "Model failed to generate proper analysis. Please try again.",
|
97 |
+
"status": "success",
|
98 |
"model_used": "huggingface-qwen-fallback",
|
99 |
"prompt": prompt,
|
100 |
"processing_time": processing_time
|
constraints.txt
ADDED
File without changes
|
requirements-base.txt
ADDED
File without changes
|