Spaces:
Paused
Paused
fix prompt for short answer
Browse files- inference_lfm.py +10 -5
inference_lfm.py
CHANGED
|
@@ -199,7 +199,7 @@ def answer_question_audio(
|
|
| 199 |
question_audio_path: str | None = None,
|
| 200 |
question_text: str | None = None,
|
| 201 |
story_context: str = "",
|
| 202 |
-
max_new_tokens: int =
|
| 203 |
) -> tuple[str, np.ndarray | None, int]:
|
| 204 |
"""
|
| 205 |
Answer a question about the story using LFM2.5-Audio end-to-end.
|
|
@@ -216,17 +216,20 @@ def answer_question_audio(
|
|
| 216 |
with GPU_INFERENCE_LOCK, torch.no_grad():
|
| 217 |
chat = ChatState(processor, dtype=dtype)
|
| 218 |
|
| 219 |
-
#
|
| 220 |
chat.new_turn("system")
|
| 221 |
-
chat.add_text(
|
|
|
|
|
|
|
|
|
|
| 222 |
chat.end_turn()
|
| 223 |
|
| 224 |
# User turn — story context as text prefix, then audio or text question
|
| 225 |
chat.new_turn("user")
|
| 226 |
if story_context:
|
| 227 |
chat.add_text(
|
| 228 |
-
f"Story context:\n{story_context[:
|
| 229 |
-
"
|
| 230 |
)
|
| 231 |
if question_audio_path:
|
| 232 |
import librosa
|
|
@@ -237,6 +240,8 @@ def answer_question_audio(
|
|
| 237 |
chat.add_text(question_text)
|
| 238 |
else:
|
| 239 |
return "Please ask a question!", None, SAMPLE_RATE
|
|
|
|
|
|
|
| 240 |
chat.end_turn()
|
| 241 |
|
| 242 |
chat.new_turn("assistant")
|
|
|
|
| 199 |
question_audio_path: str | None = None,
|
| 200 |
question_text: str | None = None,
|
| 201 |
story_context: str = "",
|
| 202 |
+
max_new_tokens: int = 150,
|
| 203 |
) -> tuple[str, np.ndarray | None, int]:
|
| 204 |
"""
|
| 205 |
Answer a question about the story using LFM2.5-Audio end-to-end.
|
|
|
|
| 216 |
with GPU_INFERENCE_LOCK, torch.no_grad():
|
| 217 |
chat = ChatState(processor, dtype=dtype)
|
| 218 |
|
| 219 |
+
# System prompt: format requirement + brevity constraint
|
| 220 |
chat.new_turn("system")
|
| 221 |
+
chat.add_text(
|
| 222 |
+
"Respond with interleaved text and audio. "
|
| 223 |
+
"Give a short, direct answer in 1-2 sentences. Do not repeat the question."
|
| 224 |
+
)
|
| 225 |
chat.end_turn()
|
| 226 |
|
| 227 |
# User turn — story context as text prefix, then audio or text question
|
| 228 |
chat.new_turn("user")
|
| 229 |
if story_context:
|
| 230 |
chat.add_text(
|
| 231 |
+
f"Story context:\n{story_context[:2000]}\n\n"
|
| 232 |
+
"Based only on the story above, answer briefly."
|
| 233 |
)
|
| 234 |
if question_audio_path:
|
| 235 |
import librosa
|
|
|
|
| 240 |
chat.add_text(question_text)
|
| 241 |
else:
|
| 242 |
return "Please ask a question!", None, SAMPLE_RATE
|
| 243 |
+
# Closing constraint so the model sees it immediately before generating
|
| 244 |
+
chat.add_text("Answer in 1-2 sentences only.")
|
| 245 |
chat.end_turn()
|
| 246 |
|
| 247 |
chat.new_turn("assistant")
|