File size: 4,613 Bytes
47ab4d9
 
 
1e03b23
47ab4d9
6d19b72
47ab4d9
 
6d19b72
47ab4d9
 
 
 
 
 
 
 
5a686c9
 
47ab4d9
f2f2b35
47ab4d9
5a686c9
 
df881b8
47ab4d9
 
df881b8
47ab4d9
5a686c9
 
 
 
 
 
 
d505472
47ab4d9
 
d505472
47ab4d9
 
 
433ca1f
47ab4d9
 
 
 
5a686c9
47ab4d9
 
 
 
 
284a6d8
 
 
 
433ca1f
 
284a6d8
433ca1f
284a6d8
 
 
 
a403b1d
433ca1f
5a686c9
a403b1d
 
 
5a686c9
284a6d8
 
37b5458
0936be5
284a6d8
1c97435
e2c5877
73ef68b
37b5458
47ab4d9
37b5458
fbc4ac6
5a686c9
 
 
 
6f5d1ae
51c1540
5a686c9
fbc4ac6
 
 
0936be5
0f9b008
 
04b5cc5
51c1540
 
0f9b008
 
04b5cc5
51c1540
 
0f9b008
51c1540
5a686c9
 
 
244d581
284a6d8
37b5458
 
 
51c1540
284a6d8
 
5a686c9
6f5d1ae
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
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'<a href="{download_url}" target="_blank">{display_text}</a>'
        html_video = f'<iframe src="{download_url}" width="640" height="360" frameborder="0" allowfullscreen></iframe>'
        return html_link + '<br>' + 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"))