import gradio as gr import requests import time import os API_HOME = os.environ['url'] END_GENERATE = '/generate' END_STATUS = '/generate/status' API_KEY = os.environ['api'] def set_header(): header = { "Content-Type": "application/json", "Authorization": "Bearer " + API_KEY, } return header # 비디오 또는 오디오 컨텐츠 생성하는 함수 def generate_contents(user_content, brand_name, aspect_ratio='landscape'): url = API_HOME + END_GENERATE VOICE_ID = '64ea1fbc310bccff6a4191ed' # Korean, Korea, Wolf Sea # 멀티 라인 텍스트를 분리하여 각 줄을 별도의 씬으로 처리 scenes = [{"content": line.strip(), "voiceId": VOICE_ID} for line in user_content.split('\n') if line.strip()] payload = { "format": "video", # video | audio "scenes": scenes, "settings": { 'aspectRatio': aspect_ratio, 'subtitle': { 'fontColor': 'yellow', 'backgroundColor': 'black', 'placement': 'bottom', 'display': 'phrase', }, }, "backgroundMusicKeywords": "happy, lofi, beats" } headers = set_header() response = requests.request("POST", url, json=payload, headers=headers).json() if response['success']: return response['data']['id'] else: return 'FAILED' # 컨텐츠 생성 상태를 확인하는 함수 def generate_status(content_id): url = API_HOME + END_STATUS payload = {"id": content_id} headers = set_header() while True: response = requests.request("POST", url, json=payload, headers=headers).json() if response['success']: status = response['data']['status'] if status == 'queued' or status == 'processing': time.sleep(10) # 10초 대기 elif status == 'success': return response['data']['file'] else: break return 'FAILED' # Gradio 인터페이스 함수 def gradio_generate_contents(user_content, brand_name, aspect_ratio): content_id = generate_contents(user_content, brand_name, aspect_ratio) markdown_text = "비디오 스크립트 자동 생성 클릭: [여기를 클릭하세요](https://seawolf2357-hyejascript.hf.space)" return content_id, markdown_text def gradio_generate_status(content_id): download_url = generate_status(content_id) markdown_text = "자동 생성된 영상에 대한 수정 및 편집 요청 클릭: [여기를 클릭하세요](https://forms.gle/u9hPDFbntLEp8xH6A)" if download_url != 'FAILED': display_text = download_url[:10] + '...' if len(download_url) > 10 else download_url html_link = f'{display_text}' html_video = f'' return html_link + '
' + html_video, markdown_text else: return "컨텐츠 생성 실패 또는 ID가 잘못되었습니다.", markdown_text iface_create = gr.Interface( fn=gradio_generate_contents, inputs=[ gr.TextArea(label="컨텐츠 텍스트"), gr.Textbox(label="키워드"), gr.Dropdown(label="화면 비율", choices=['portrait', 'square', 'landscape'], value='landscape'), ], outputs=[ gr.Textbox(label="컨텐츠 ID"), gr.Markdown() # 마크다운 출력 추가 ], examples=[ [ "Nature Republic Super Aqua Max 지성 피부용 프레시 워터 크림\n아름다운 여성에게 진정 필요한것은 무엇일까요? 진정한 아름다움은 건강하고 맑은 피부에 있습니다.", "네이처리퍼블릭", "landscape" ], [ "인생에 있어 행복이 무엇일까요?\n야외에서 뛰어놀고 있는 멋진 개들을 보면 기분이 좋아집니다.\n내곁에서 졸고 있는 고양이들이 사랑스럽죠?", "행복", "landscape" ] ] ) iface_status = gr.Interface( fn=gradio_generate_status, inputs=gr.Textbox(label="컨텐츠 ID"), outputs=[ gr.HTML(label="다운로드 링크 및 비디오"), gr.Markdown("자동 생성된 영상에 대한 수정 및 편집 요청 클릭: [여기를 클릭하세요](https://forms.gle/u9hPDFbntLEp8xH6A)") ] ) iface_combined = gr.TabbedInterface([iface_create, iface_status], ["컨텐츠 생성", "상태 확인 및 다운로드"]) iface_combined.launch(auth=("arxiv", "gpt"))