hysts HF Staff commited on
Commit
b7e7514
·
1 Parent(s): 63bc571

Place audio after text in chat messages

Browse files
Files changed (1) hide show
  1. app.py +12 -6
app.py CHANGED
@@ -93,14 +93,20 @@ def _resolve_media_source(path: str) -> str:
93
 
94
 
95
  def _user_content(text: str, files: list[str]) -> list[dict]:
96
- """Build a user message content list from text and uploaded file paths."""
97
- content: list[dict] = []
 
 
 
 
 
98
  for path in files:
99
  kind = _classify_file(path)
100
- if kind:
101
- content.append({"type": kind, "url": _resolve_media_source(path)})
102
- content.append({"type": "text", "text": text})
103
- return content
 
104
 
105
 
106
  def process_history(history: list[dict]) -> list[dict]:
 
93
 
94
 
95
  def _user_content(text: str, files: list[str]) -> list[dict]:
96
+ """Build a user message content list from text and uploaded file paths.
97
+
98
+ Media placement follows the model card's guidance: image and video go before
99
+ the text, audio goes after it.
100
+ """
101
+ before: list[dict] = []
102
+ after: list[dict] = []
103
  for path in files:
104
  kind = _classify_file(path)
105
+ if kind == "audio":
106
+ after.append({"type": kind, "url": _resolve_media_source(path)})
107
+ elif kind:
108
+ before.append({"type": kind, "url": _resolve_media_source(path)})
109
+ return [*before, {"type": "text", "text": text}, *after]
110
 
111
 
112
  def process_history(history: list[dict]) -> list[dict]: