Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
@@ -68,15 +68,12 @@ def answer_question(text, question, max_length=512):
|
|
68 |
start_logits = tf.convert_to_tensor(start_logits)
|
69 |
end_logits = tf.convert_to_tensor(end_logits)
|
70 |
|
71 |
-
#
|
72 |
-
|
73 |
-
|
74 |
-
axis = tf.constant(1, dtype=tf.int32) # Replace with correct axis if needed
|
75 |
|
76 |
-
|
77 |
-
|
78 |
-
|
79 |
-
answer = tf.gather(text, answer_start, axis=1).numpy()[0][answer_start[0]:answer_end[0]]
|
80 |
|
81 |
return answer if answer else "No answer found."
|
82 |
|
|
|
68 |
start_logits = tf.convert_to_tensor(start_logits)
|
69 |
end_logits = tf.convert_to_tensor(end_logits)
|
70 |
|
71 |
+
# Find the indices of the start and end positions
|
72 |
+
answer_start = tf.argmax(start_logits, axis=1).numpy()[0]
|
73 |
+
answer_end = (tf.argmax(end_logits, axis=1) + 1).numpy()[0] # Increment by 1 for exclusive end index
|
|
|
74 |
|
75 |
+
# Extract the answer text from the original text
|
76 |
+
answer = text[answer_start:answer_end].strip()
|
|
|
|
|
77 |
|
78 |
return answer if answer else "No answer found."
|
79 |
|