Spaces:
Sleeping
Sleeping
Shreyash Indurkar
commited on
Commit
·
4b45566
1
Parent(s):
c0d569c
Final out changes
Browse files
app.py
CHANGED
|
@@ -133,28 +133,30 @@ def predict_code_summary(request: CodeRequest):
|
|
| 133 |
|
| 134 |
# Ensure we have the attentions
|
| 135 |
if not hasattr(forward_outputs, 'attentions') or not forward_outputs.attentions:
|
|
|
|
| 136 |
return {
|
| 137 |
-
|
| 138 |
-
|
| 139 |
-
"message": "Attention data not available from this model"
|
| 140 |
}
|
| 141 |
|
| 142 |
# Step 3: Compute word importance
|
| 143 |
try:
|
| 144 |
word_importance = compute_word_importance(forward_outputs.attentions, inputs)
|
| 145 |
except Exception as e:
|
| 146 |
-
#
|
| 147 |
return {
|
| 148 |
-
|
| 149 |
-
|
| 150 |
-
"error_message": f"Failed to compute word importance: {str(e)}"
|
| 151 |
}
|
| 152 |
|
| 153 |
-
#
|
| 154 |
-
|
| 155 |
-
|
| 156 |
-
|
| 157 |
}
|
|
|
|
|
|
|
|
|
|
| 158 |
except Exception as e:
|
| 159 |
error_details = {
|
| 160 |
"error": str(e),
|
|
|
|
| 133 |
|
| 134 |
# Ensure we have the attentions
|
| 135 |
if not hasattr(forward_outputs, 'attentions') or not forward_outputs.attentions:
|
| 136 |
+
# Format response to maintain consistency
|
| 137 |
return {
|
| 138 |
+
'summary': summary,
|
| 139 |
+
'topWords': []
|
|
|
|
| 140 |
}
|
| 141 |
|
| 142 |
# Step 3: Compute word importance
|
| 143 |
try:
|
| 144 |
word_importance = compute_word_importance(forward_outputs.attentions, inputs)
|
| 145 |
except Exception as e:
|
| 146 |
+
# Format response to maintain consistency even when word importance fails
|
| 147 |
return {
|
| 148 |
+
'summary': summary,
|
| 149 |
+
'topWords': []
|
|
|
|
| 150 |
}
|
| 151 |
|
| 152 |
+
# Format the result according to the specified structure
|
| 153 |
+
result = {
|
| 154 |
+
'summary': summary,
|
| 155 |
+
'topWords': [{'word': word, 'score': float(score)} for word, score in word_importance]
|
| 156 |
}
|
| 157 |
+
|
| 158 |
+
# Return formatted JSON response
|
| 159 |
+
return result
|
| 160 |
except Exception as e:
|
| 161 |
error_details = {
|
| 162 |
"error": str(e),
|