Shreyash Indurkar commited on
Commit
4b45566
·
1 Parent(s): c0d569c

Final out changes

Browse files
Files changed (1) hide show
  1. app.py +13 -11
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
- "summary": summary,
138
- "top_important_words": [], # No attention data available
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
- # If word importance calculation fails, still return the summary
147
  return {
148
- "summary": summary,
149
- "top_important_words": [],
150
- "error_message": f"Failed to compute word importance: {str(e)}"
151
  }
152
 
153
- # Final JSON response
154
- return {
155
- "summary": summary,
156
- "top_important_words": word_importance
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),