Spaces:
Runtime error
Runtime error
refactor: Improve ffmpeg command extraction from LLM response
Browse files
app.py
CHANGED
@@ -138,7 +138,18 @@ YOUR FFMPEG COMMAND:
|
|
138 |
top_p=top_p,
|
139 |
max_tokens=2048
|
140 |
)
|
141 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
142 |
|
143 |
# remove output.mp4 with the actual output file path
|
144 |
command = command.replace("output.mp4", "")
|
|
|
138 |
top_p=top_p,
|
139 |
max_tokens=2048
|
140 |
)
|
141 |
+
content = completion.choices[0].message.content
|
142 |
+
# Extract command from code block if present
|
143 |
+
if "```" in content:
|
144 |
+
# Find content between ```sh or ```bash and the next ```
|
145 |
+
import re
|
146 |
+
command = re.search(r'```(?:sh|bash)?\n(.*?)\n```', content, re.DOTALL)
|
147 |
+
if command:
|
148 |
+
command = command.group(1).strip()
|
149 |
+
else:
|
150 |
+
command = content.replace("\n", "")
|
151 |
+
else:
|
152 |
+
command = content.replace("\n", "")
|
153 |
|
154 |
# remove output.mp4 with the actual output file path
|
155 |
command = command.replace("output.mp4", "")
|