Spaces:
Build error
Build error
File size: 5,584 Bytes
aa95dd5 bc18a34 0af8481 993c6c8 0af8481 5206fbf 0af8481 5206fbf 0af8481 baf199d 0af8481 aab1d42 0af8481 aab1d42 0af8481 baf199d 0af8481 baf199d 0af8481 bd532eb 0af8481 baf199d 0af8481 baf199d 3c02b31 0af8481 baf199d 0af8481 baf199d 0af8481 3c02b31 bc18a34 3c02b31 0af8481 |
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 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 |
import gradio as gr
import requests
import time
API_HOME = 'https://api.fliki.ai/v1'
END_LANGUAGES = '/languages'
END_DIALECTS = '/dialects'
END_VOICES = '/voices'
END_GENERATE = '/generate'
END_STATUS = '/generate/status'
API_KEY = 'ZZUIQ4OZASNRQ8B8WYHNW'
brand = 'ํ์ธ์ ํ ๋
ธํธ๋ถ'
def set_header():
header = {
"Content-Type": "application/json",
"Authorization": "Bearer " + API_KEY,
}
return header
# ๊ธฐ์กด์ ํจ์๋ค...
def set_header():
header = {
"Content-Type": "application/json",
"Authorization": "Bearer " + API_KEY,
}
return header
# ์ธ์ด ๋ฆฌ์คํธ๋ฅผ ๊ฐ์ ธ์ค๋ ํจ์.
def get_language_id():
url = API_HOME + END_LANGUAGES
headers = set_header()
response = requests.request("GET", url, headers=headers).json()
print(f"์ธ์ด ๋ฆฌ์คํธ: {response}")
# Korean: 61b8b2fa4268666c126babf1
return response
# ์ธ์ด์ง์ญ ๋ฆฌ์คํธ๋ฅผ ๊ฐ์ ธ์ค๋ ํจ์.
def get_dialects():
url = API_HOME + END_DIALECTS
headers = set_header()
response = requests.request("GET", url, headers=headers).json()
print(f"์ธ์ด์ง์ญ ๋ฆฌ์คํธ: {response}")
# Korea: 61b8b30f4268666c126bac8d
return response
# ์ง์ญ์ธ์ด ๋ฆฌ์คํธ๋ฅผ ๊ฐ์ ธ์ค๋ ํจ์.
def get_voices(language_id, dialect_id):
url = API_HOME + END_VOICES
headers = set_header()
payload = {
'languageId': language_id,
'dialectId': dialect_id
}
response = requests.request("POST", url, json=payload, headers=headers).json()
print(f"voice: {response}")
return response
# ๋น๋์ค ๋๋ ์ค๋์ค ์ปจํ
์ธ ์์ฑํ๋ ํจ์.
def generate_contents(user_content, brand_name):
global brand
brand = brand_name # ๋ธ๋๋๋ช
์ค์
url = API_HOME + END_GENERATE
VOICE_ID = '65934ac2bc02ab1c006755fa' # Korean, Korea, Wolf Sea
payload = {
"format": "video", # video | audio
"scenes": [
{
"content": user_content, # ์ฌ์ฉ์๊ฐ ์
๋ ฅํ ํ
์คํธ
"voiceId": VOICE_ID
},
# ... ๋ค๋ฅธ ์ฌ๋ค์ด ํ์ํ๋ค๋ฉด ์ฌ๊ธฐ์ ์ถ๊ฐ ...
],
"settings": {
'aspectRatio': 'portrait', # 'portrait', 'square', 'horizontal'
'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()
# HTTP ์ํ์ฝ๋ ํ์ธ
if response['success'] == True:
# ์๋ต๊ฐ ์์: {'success': True, 'data': {'id': '6593aa11d153762d8aa022e9'}}
print(f"์ ์: {response['data']['id']}")
return response['data']['id']
else:
print(f"request ์คํจ: {response}")
return 'FAILED'
# /generate API ํธ์ถ ์ฑ๊ณต ํ ๋ฐ์ id๋ก ์ปจํ
์ธ ์์ฑ ์ํ๋ฅผ ํ์ธํ๋ ํจ์.
def generate_status(content_id):
url = API_HOME + END_STATUS
payload = {"id": content_id}
headers = set_header()
response = requests.request("POST", url, json=payload, headers=headers).json()
# HTTP ์ํ์ฝ๋ ํ์ธ
if response['success'] == True:
print(f"์ ์: {response}")
if response['data']['status'] == 'queued':
print('์์ง ์ปจํ
์ธ URL์ด ์์ฑ๋์ง ์์์ต๋๋ค.')
return 'PENDING'
if response['data']['status'] == 'processing':
print('์ปจํ
์ธ URL์ด ์์ง ์์ฑ ์ค ์
๋๋ค.')
return 'PENDING'
elif response['data']['status'] == 'success':
return response['data']['file']
else:
print(f"request ์คํจ")
def download_content(url):
data = requests.get(url, timeout=30)
save_path = "downloaded_example.mp4"
with open(save_path, 'wb') as file:
for chunk in data.iter_content(chunk_size=128):
file.write(chunk)
print(f"MP4 ํ์ผ์ด ์ฑ๊ณต์ ์ผ๋ก ์ ์ฅ๋์์ต๋๋ค. ๊ฒฝ๋ก: {save_path}")
return 'success'
# # ์คํ.
# get_language_id() # Korean: 61b8b2fa4268666c126babf1
# get_dialects() # Korea: 61b8b30f4268666c126bac8d
# get_voices('61b8b2fa4268666c126babf1', '61b8b30f4268666c126bac8d')
try:
id = generate_contents()
if id != 'FAILED':
status = 'PENDING'
while status == 'PENDING':
time.sleep(9) # 9์ด ๊ธฐ๋ค๋ฆผ
print('9์ด ๋๊ธฐ ํ ์ํํ์ธ ํจ์๋ฅผ ํธ์ถํฉ๋๋ค.')
status = generate_status(id)
if status != 'PENDING': break
print(f"์ปจํ
์ธ ์์ฑ ์ฑ๊ณต: {status}")
else:
print('์์ฑ ์คํจ..')
except Exception as e:
print(f"์ค๋ฅ ๋ฐ์: {e}")
# Gradio ์ธํฐํ์ด์ค๋ฅผ ์ํ ํจ์
def gradio_generate_contents(user_content, brand_name):
return generate_contents(user_content, brand_name) # ๋ ์
๋ ฅ ๋ชจ๋ ์ ๋ฌ
# Gradio ์ธํฐํ์ด์ค ์์
iface = gr.Interface(
fn=gradio_generate_contents, # ์ปจํ
์ธ ์์ฑ ํจ์
inputs=[gr.inputs.Textbox(label="์ปจํ
์ธ ํ
์คํธ"), gr.inputs.Textbox(label="๋ธ๋๋๋ช
")],
outputs=gr.outputs.Textbox(label="์ปจํ
์ธ ID")
)
status_iface = gr.Interface(
fn=gradio_generate_status, # ์ปจํ
์ธ ์ํ ํ์ธ ํจ์
inputs=gr.inputs.Textbox(label="์ปจํ
์ธ ID"),
outputs=gr.outputs.Textbox(label="์ปจํ
์ธ ์ํ ๋๋ URL")
)
iface.launch()
status_iface.launch()
|