Spaces:
Running
Running
format
Browse files
app.py
CHANGED
|
@@ -11,12 +11,10 @@ import uuid
|
|
| 11 |
import tempfile
|
| 12 |
import shlex
|
| 13 |
import shutil
|
|
|
|
| 14 |
HF_API_KEY = os.environ["HF_TOKEN"]
|
| 15 |
|
| 16 |
-
client = OpenAI(
|
| 17 |
-
base_url="https://api-inference.huggingface.co/v1/",
|
| 18 |
-
api_key=HF_API_KEY
|
| 19 |
-
)
|
| 20 |
|
| 21 |
allowed_medias = [
|
| 22 |
".png",
|
|
@@ -142,7 +140,7 @@ YOUR FFMPEG COMMAND:
|
|
| 142 |
print("\n=== COMPLETE PROMPT ===")
|
| 143 |
for msg in messages:
|
| 144 |
print(f"\n[{msg['role'].upper()}]:")
|
| 145 |
-
print(msg[
|
| 146 |
print("=====================\n")
|
| 147 |
|
| 148 |
completion = client.chat.completions.create(
|
|
@@ -150,14 +148,15 @@ YOUR FFMPEG COMMAND:
|
|
| 150 |
messages=messages,
|
| 151 |
temperature=temperature,
|
| 152 |
top_p=top_p,
|
| 153 |
-
max_tokens=2048
|
| 154 |
)
|
| 155 |
content = completion.choices[0].message.content
|
| 156 |
# Extract command from code block if present
|
| 157 |
if "```" in content:
|
| 158 |
# Find content between ```sh or ```bash and the next ```
|
| 159 |
import re
|
| 160 |
-
|
|
|
|
| 161 |
if command:
|
| 162 |
command = command.group(1).strip()
|
| 163 |
else:
|
|
@@ -227,7 +226,9 @@ def update(files, prompt, top_p=1, temperature=1):
|
|
| 227 |
output_file_name = f"output_{uuid.uuid4()}.mp4"
|
| 228 |
output_file_path = str((Path(temp_dir) / output_file_name).resolve())
|
| 229 |
final_command = args + ["-y", output_file_path]
|
| 230 |
-
print(
|
|
|
|
|
|
|
| 231 |
subprocess.run(final_command, cwd=temp_dir)
|
| 232 |
generated_command = f"### Generated Command\n```bash\nffmpeg {' '.join(args[1:])} -y output.mp4\n```"
|
| 233 |
return output_file_path, gr.update(value=generated_command)
|
|
|
|
| 11 |
import tempfile
|
| 12 |
import shlex
|
| 13 |
import shutil
|
| 14 |
+
|
| 15 |
HF_API_KEY = os.environ["HF_TOKEN"]
|
| 16 |
|
| 17 |
+
client = OpenAI(base_url="https://api-inference.huggingface.co/v1/", api_key=HF_API_KEY)
|
|
|
|
|
|
|
|
|
|
| 18 |
|
| 19 |
allowed_medias = [
|
| 20 |
".png",
|
|
|
|
| 140 |
print("\n=== COMPLETE PROMPT ===")
|
| 141 |
for msg in messages:
|
| 142 |
print(f"\n[{msg['role'].upper()}]:")
|
| 143 |
+
print(msg["content"])
|
| 144 |
print("=====================\n")
|
| 145 |
|
| 146 |
completion = client.chat.completions.create(
|
|
|
|
| 148 |
messages=messages,
|
| 149 |
temperature=temperature,
|
| 150 |
top_p=top_p,
|
| 151 |
+
max_tokens=2048,
|
| 152 |
)
|
| 153 |
content = completion.choices[0].message.content
|
| 154 |
# Extract command from code block if present
|
| 155 |
if "```" in content:
|
| 156 |
# Find content between ```sh or ```bash and the next ```
|
| 157 |
import re
|
| 158 |
+
|
| 159 |
+
command = re.search(r"```(?:sh|bash)?\n(.*?)\n```", content, re.DOTALL)
|
| 160 |
if command:
|
| 161 |
command = command.group(1).strip()
|
| 162 |
else:
|
|
|
|
| 226 |
output_file_name = f"output_{uuid.uuid4()}.mp4"
|
| 227 |
output_file_path = str((Path(temp_dir) / output_file_name).resolve())
|
| 228 |
final_command = args + ["-y", output_file_path]
|
| 229 |
+
print(
|
| 230 |
+
f"\n=== EXECUTING FFMPEG COMMAND ===\nffmpeg {' '.join(final_command[1:])}\n"
|
| 231 |
+
)
|
| 232 |
subprocess.run(final_command, cwd=temp_dir)
|
| 233 |
generated_command = f"### Generated Command\n```bash\nffmpeg {' '.join(args[1:])} -y output.mp4\n```"
|
| 234 |
return output_file_path, gr.update(value=generated_command)
|