victor HF staff commited on
Commit
d348068
1 Parent(s): 4cda010

refactor: Migrate from OpenAI GPT-4 to Qwen inference with Hugging Face API

Browse files
Files changed (1) hide show
  1. app.py +12 -5
app.py CHANGED
@@ -4,7 +4,7 @@ from PIL import Image
4
  from moviepy.editor import VideoFileClip, AudioFileClip
5
 
6
  import os
7
- import openai
8
  import subprocess
9
  from pathlib import Path
10
  import uuid
@@ -13,8 +13,11 @@ import shlex
13
  import shutil
14
  from utils import format_bash_command
15
 
16
- OPENAI_API_KEY = os.environ["OPENAI_API_KEY"]
17
- openai.api_key = OPENAI_API_KEY
 
 
 
18
 
19
  allowed_medias = [
20
  ".png",
@@ -127,8 +130,12 @@ YOUR FFMPEG COMMAND:
127
  },
128
  ]
129
  try:
130
- completion = openai.ChatCompletion.create(
131
- model="gpt-4", messages=messages, top_p=top_p, temperature=temperature
 
 
 
 
132
  )
133
  command = completion.choices[0].message.content.replace("\n", "")
134
 
 
4
  from moviepy.editor import VideoFileClip, AudioFileClip
5
 
6
  import os
7
+ from openai import OpenAI
8
  import subprocess
9
  from pathlib import Path
10
  import uuid
 
13
  import shutil
14
  from utils import format_bash_command
15
 
16
+ HF_API_KEY = os.environ["HF_API_KEY"]
17
+ client = OpenAI(
18
+ base_url="https://api-inference.huggingface.co/v1/",
19
+ api_key=HF_API_KEY
20
+ )
21
 
22
  allowed_medias = [
23
  ".png",
 
130
  },
131
  ]
132
  try:
133
+ completion = client.chat.completions.create(
134
+ model="Qwen/Qwen2.5-Coder-32B-Instruct",
135
+ messages=messages,
136
+ temperature=temperature,
137
+ top_p=top_p,
138
+ max_tokens=2048
139
  )
140
  command = completion.choices[0].message.content.replace("\n", "")
141