123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687 |
- import time
- import requests
- import json
- import traceback
- from utils import download_video
- from audio_process import get_wav
- from xunfei_asr import call_asr
- from config import set_config
- from log import Log
- config_ = set_config()
- log_ = Log()
- def request_gpt(prompt):
- """
- headers = {
- 'Content-Type': 'application/json',
- 'Authorization': f'Bearer {config_.GPT_OPENAI_API_KEY}',
- }
- proxies = config_.PROXIES
- json_data = {
- 'model': 'gpt-3.5-turbo',
- 'messages': [
- {
- 'role': 'user',
- 'content': prompt,
- },
- ],
- }
- response = requests.post(url=config_.GPT_HOST, headers=headers, json=json_data, proxies=proxies)
- """
- response = requests.post(url=config_.GPT_URL, json={'content': prompt})
-
-
-
-
- log_.info(f"response: {response}")
- log_.info(f"response.text: {response.text}")
- res_data = json.loads(response.text)
- result_content = res_data['choices'][0]['message']['content']
- return result_content
- def title_generate(video_id, video_path):
- """
- 视频生成标题
- :param video_id: videoId
- :param video_path: videoPath
- :return:
- """
-
- log_.info(f"debug: title_generate 1")
- video_file_path = download_video(video_path=video_path, video_id=video_id, download_folder='videos')
- log_.info(f"video_file_path = {video_file_path}")
-
- log_.info(f"debug: title_generate 2")
- audio_path = get_wav(video_path=video_file_path)
- log_.info(f"audio_path = {audio_path}")
-
- log_.info(f"debug: title_generate 3")
- dialogue_path, asr_res = call_asr(audio_path=audio_path)
- log_.info({
- 'asrResult': {'videoId': video_id, 'asrRes': asr_res}
- })
-
- log_.info(f"debug: title_generate 4")
- prompt = f"{config_.GPT_PROMPT['title']['prompt2']}{asr_res.strip()}"
- gpt_res = request_gpt(prompt=prompt)
- return gpt_res
-
-
-
-
-
-
-
-
- if __name__ == '__main__':
- title_generate(video_id='001', video_path='')
|