Spaces:
Runtime error
Runtime error
File size: 4,838 Bytes
47ab4d9 5a686c9 47ab4d9 f2f2b35 47ab4d9 5a686c9 df881b8 47ab4d9 df881b8 47ab4d9 5a686c9 47ab4d9 433ca1f 47ab4d9 5a686c9 47ab4d9 284a6d8 433ca1f 284a6d8 433ca1f 284a6d8 433ca1f 5a686c9 284a6d8 1c97435 e2c5877 73ef68b 25e5468 47ab4d9 d49d212 284a6d8 5a686c9 0f9b008 5a686c9 244d581 284a6d8 0f9b008 dfc751b 0f9b008 284a6d8 5a686c9 |
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 123 124 125 126 127 128 |
import gradio as gr
import requests
import time
API_HOME = 'https://api.fliki.ai/v1'
END_GENERATE = '/generate'
END_STATUS = '/generate/status'
API_KEY = 'ZZUIQ4OZASNRQ8B8WYHNW'
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):
return generate_contents(user_content, brand_name, aspect_ratio)
def gradio_generate_status(content_id):
download_url = generate_status(content_id)
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
else:
return "컨ν
μΈ μμ± μ€ν¨ λλ IDκ° μλͺ»λμμ΅λλ€."
# 컨ν
μΈ μμ± μΈν°νμ΄μ€
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"),
examples=[
[
"""Nature Republic Super Aqua Max μ§μ± νΌλΆμ© νλ μ μν° ν¬λ¦Ό
μλ¦λ€μ΄ μ¬μ±μκ² μ§μ νμνκ²μ 무μμΌκΉμ? μ§μ ν μλ¦λ€μμ 건κ°νκ³ λ§μ νΌλΆμ μμ΅λλ€.
μλ¦λ€μμ μ¬λ¬κ°μ§ κΈ°μ€μ΄ μκ² μ§λ§, κΉ¨λν νΌλΆκ° κ·Έμ€ μΌλΈμ΄μ λ°νμ
λλ€.
μμ€ν λΉμ μ νΌλΆ 건κ°μ μν΄ λ³΄μ΅κ³Ό λ―Έλ°±μ κΈ°λ₯μ±μ κ°νν νμ μ μΈ νμ₯νμ μΆμ²ν©λλ€.
μ§κΈ λ°λ‘ μ°λ½μ£Όμλ©΄ μμΈ μλ΄λ₯Ό μ κ³΅ν΄ λ립λλ€.""",
"λ€μ΄μ²λ¦¬νΌλΈλ¦",
"landscape"
],
[
"""μΈμμ μμ΄ νλ³΅μ΄ λ¬΄μμΌκΉμ?
μΌμΈμμ λ°μ΄λκ³ μλ λ©μ§ κ°λ€μ 보면 κΈ°λΆμ΄ μ’μμ§λλ€.
λ΄κ³μμ μ‘Έκ³ μλ κ³ μμ΄λ€μ΄ μ¬λμ€λ½μ£ ?
ν볡μ κ²°μ½ λ©λ¦¬ μμ§ μμ΅λλ€. μ€λμ μμ€ν¨μ κ°μ¬ν©μλ€.""",
"ν볡",
"landscape"
]
]
)
# μν νμΈ λ° λΉλμ€ λ€μ΄λ‘λ μΈν°νμ΄μ€
iface_status = gr.Interface(
fn=gradio_generate_status,
inputs=gr.Textbox(label="컨ν
μΈ ID"),
outputs=gr.HTML(label="λ€μ΄λ‘λ λ§ν¬ λ° λΉλμ€"),
examples=[
["659f5a3f096a487442e72dee"],
["659f6651d4c72225a9895ebb"],
["659cb397cb76ef0bf866bea1"],
["659d36c2566250b231cffab1"],
["659b99911395c3bd1cc1165b"]
] # μμ μΆκ°
)
# λ μΈν°νμ΄μ€λ₯Ό νμΌλ‘ ꡬμ±
iface_combined = gr.TabbedInterface([iface_create, iface_status], ["컨ν
μΈ μμ±", "μν νμΈ λ° λ€μ΄λ‘λ"])
iface_combined.launch()
|