seawolf2357 commited on
Commit
433ca1f
ยท
1 Parent(s): 73ef68b

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +7 -129
app.py CHANGED
@@ -3,13 +3,9 @@ import requests
3
  import time
4
 
5
  API_HOME = 'https://api.fliki.ai/v1'
6
- END_LANGUAGES = '/languages'
7
- END_DIALECTS = '/dialects'
8
- END_VOICES = '/voices'
9
  END_GENERATE = '/generate'
10
  END_STATUS = '/generate/status'
11
  API_KEY = 'ZZUIQ4OZASNRQ8B8WYHNW'
12
- brand = 'ํŒŒ์ธ์• ํ”Œ ๋…ธํŠธ๋ถ'
13
 
14
  def set_header():
15
  header = {
@@ -18,54 +14,8 @@ def set_header():
18
  }
19
  return header
20
 
21
- # ๊ธฐ์กด์˜ ํ•จ์ˆ˜๋“ค...
22
-
23
-
24
- def set_header():
25
- header = {
26
- "Content-Type": "application/json",
27
- "Authorization": "Bearer " + API_KEY,
28
- }
29
- return header
30
-
31
- # ์–ธ์–ด ๋ฆฌ์ŠคํŠธ๋ฅผ ๊ฐ€์ ธ์˜ค๋Š” ํ•จ์ˆ˜.
32
- def get_language_id():
33
- url = API_HOME + END_LANGUAGES
34
- headers = set_header()
35
- response = requests.request("GET", url, headers=headers).json()
36
- print(f"์–ธ์–ด ๋ฆฌ์ŠคํŠธ: {response}")
37
- # Korean: 61b8b2fa4268666c126babf1
38
- return response
39
-
40
-
41
- # ์–ธ์–ด์ง€์—ญ ๋ฆฌ์ŠคํŠธ๋ฅผ ๊ฐ€์ ธ์˜ค๋Š” ํ•จ์ˆ˜.
42
- def get_dialects():
43
- url = API_HOME + END_DIALECTS
44
- headers = set_header()
45
- response = requests.request("GET", url, headers=headers).json()
46
- print(f"์–ธ์–ด์ง€์—ญ ๋ฆฌ์ŠคํŠธ: {response}")
47
- # Korea: 61b8b30f4268666c126bac8d
48
- return response
49
-
50
-
51
- # ์ง€์—ญ์–ธ์–ด ๋ฆฌ์ŠคํŠธ๋ฅผ ๊ฐ€์ ธ์˜ค๋Š” ํ•จ์ˆ˜.
52
- def get_voices(language_id, dialect_id):
53
- url = API_HOME + END_VOICES
54
- headers = set_header()
55
- payload = {
56
- 'languageId': language_id,
57
- 'dialectId': dialect_id
58
- }
59
- response = requests.request("POST", url, json=payload, headers=headers).json()
60
- print(f"voice: {response}")
61
- return response
62
-
63
-
64
  # ๋น„๋””์˜ค ๋˜๋Š” ์˜ค๋””์˜ค ์ปจํ…์ธ  ์ƒ์„ฑํ•˜๋Š” ํ•จ์ˆ˜.
65
-
66
  def generate_contents(user_content, brand_name):
67
- global brand
68
- brand = brand_name # ๋ธŒ๋žœ๋“œ๋ช… ์„ค์ •
69
  url = API_HOME + END_GENERATE
70
  VOICE_ID = '65934ac2bc02ab1c006755fa' # Korean, Korea, Wolf Sea
71
 
@@ -76,27 +26,20 @@ def generate_contents(user_content, brand_name):
76
  "format": "video", # video | audio
77
  "scenes": scenes,
78
  "settings": {
79
- # ... ์„ค์ •๋“ค ...
80
  },
81
  "backgroundMusicKeywords": "happy, lofi, beats"
82
  }
83
 
84
- # ... ๋‚˜๋จธ์ง€ ์ฝ”๋“œ ...
85
-
86
  headers = set_header()
87
  response = requests.request("POST", url, json=payload, headers=headers).json()
88
 
89
- # HTTP ์ƒํƒœ์ฝ”๋“œ ํ™•์ธ
90
- if response['success'] == True:
91
- # ์‘๋‹ต๊ฐ’ ์˜ˆ์‹œ: {'success': True, 'data': {'id': '6593aa11d153762d8aa022e9'}}
92
- print(f"์ •์ƒ: {response['data']['id']}")
93
  return response['data']['id']
94
  else:
95
- print(f"request ์‹คํŒจ: {response}")
96
  return 'FAILED'
97
 
98
-
99
- # /generate API ํ˜ธ์ถœ ์„ฑ๊ณต ํ›„ ๋ฐ›์€ id๋กœ ์ปจํ…์ธ  ์ƒ์„ฑ ์ƒํƒœ๋ฅผ ํ™•์ธํ•˜๋Š” ํ•จ์ˆ˜.
100
  def generate_status(content_id):
101
  url = API_HOME + END_STATUS
102
  payload = {"id": content_id}
@@ -106,29 +49,22 @@ def generate_status(content_id):
106
  response = requests.request("POST", url, json=payload, headers=headers).json()
107
 
108
  if response['success']:
109
- if response['data']['status'] == 'queued' or response['data']['status'] == 'processing':
110
- print('์ปจํ…์ธ  ์ƒ์„ฑ ์ค‘... ์ž ์‹œ ํ›„ ๋‹ค์‹œ ์‹œ๋„ํ•˜์„ธ์š”.')
111
  time.sleep(10) # 10์ดˆ ๋Œ€๊ธฐ
112
- elif response['data']['status'] == 'success':
113
- print('์ปจํ…์ธ  ์ƒ์„ฑ ์™„๋ฃŒ!')
114
  return response['data']['file']
115
  else:
116
- print(f"request ์‹คํŒจ: {response}")
117
  break
118
  return 'FAILED'
119
 
120
-
121
  def gradio_generate_status(content_id):
122
  download_url = generate_status(content_id)
123
  if download_url != 'FAILED':
124
- # URL์˜ ํ…์ŠคํŠธ๋ฅผ 10๊ธ€์ž๋กœ ์ œํ•œํ•˜๊ณ  ๋งํฌ ์ƒ์„ฑ
125
  display_text = download_url[:10] + '...' if len(download_url) > 10 else download_url
126
  html_link = f'<a href="{download_url}" target="_blank">{display_text}</a>'
127
-
128
- # iframe์„ ์‚ฌ์šฉํ•˜์—ฌ ๋น„๋””์˜ค ์ž„๋ฒ ๋“œ
129
  html_video = f'<iframe src="{download_url}" width="640" height="360" frameborder="0" allowfullscreen></iframe>'
130
-
131
- # ๋งํฌ์™€ ๋น„๋””์˜ค ๋‘˜ ๋‹ค ๋ฐ˜ํ™˜
132
  return html_link + '<br>' + html_video
133
  else:
134
  return "์ปจํ…์ธ  ์ƒ์„ฑ ์‹คํŒจ ๋˜๋Š” ID๊ฐ€ ์ž˜๋ชป๋˜์—ˆ์Šต๋‹ˆ๋‹ค."
@@ -140,61 +76,3 @@ status_iface = gr.Interface(
140
  )
141
 
142
  status_iface.launch()
143
-
144
- def download_content(url):
145
- data = requests.get(url, timeout=30)
146
- save_path = "downloaded_example.mp4"
147
- with open(save_path, 'wb') as file:
148
- for chunk in data.iter_content(chunk_size=128):
149
- file.write(chunk)
150
- print(f"MP4 ํŒŒ์ผ์ด ์„ฑ๊ณต์ ์œผ๋กœ ์ €์žฅ๋˜์—ˆ์Šต๋‹ˆ๋‹ค. ๊ฒฝ๋กœ: {save_path}")
151
- return 'success'
152
-
153
-
154
- # # ์‹คํ–‰.
155
-
156
- # get_language_id() # Korean: 61b8b2fa4268666c126babf1
157
- # get_dialects() # Korea: 61b8b30f4268666c126bac8d
158
- # get_voices('61b8b2fa4268666c126babf1', '61b8b30f4268666c126bac8d')
159
-
160
- try:
161
- id = generate_contents()
162
- if id != 'FAILED':
163
- status = 'PENDING'
164
- while status == 'PENDING':
165
- time.sleep(9) # 9์ดˆ ๊ธฐ๋‹ค๋ฆผ
166
- print('9์ดˆ ๋Œ€๊ธฐ ํ›„ ์ƒํƒœํ™•์ธ ํ•จ์ˆ˜๋ฅผ ํ˜ธ์ถœํ•ฉ๋‹ˆ๋‹ค.')
167
- status = generate_status(id)
168
- if status != 'PENDING': break
169
-
170
- print(f"์ปจํ…์ธ  ์ƒ์„ฑ ์„ฑ๊ณต: {status}")
171
- else:
172
- print('์ƒ์„ฑ ์‹คํŒจ..')
173
- except Exception as e:
174
- print(f"์˜ค๋ฅ˜ ๋ฐœ์ƒ: {e}")
175
-
176
- def gradio_generate_contents(user_content, brand_name):
177
- return generate_contents(user_content, brand_name)
178
-
179
- def gradio_generate_status(content_id):
180
- return generate_status(content_id)
181
-
182
- # ... ์ด์ „ ์ฝ”๋“œ ...
183
-
184
- # Gradio ์ธํ„ฐํŽ˜์ด์Šค ์ˆ˜์ •
185
- iface = gr.Interface(
186
- fn=gradio_generate_contents, # ์ปจํ…์ธ  ์ƒ์„ฑ ํ•จ์ˆ˜
187
- inputs=[gr.TextArea(label="์ปจํ…์ธ  ํ…์ŠคํŠธ"), gr.Textbox(label="๋ธŒ๋žœ๋“œ๋ช…")], # ๋ฉ€ํ‹ฐ๋ผ์ธ ํ…์ŠคํŠธ ์ž…๋ ฅ ๋ฐ ๋ธŒ๋žœ๋“œ๋ช… ์ž…๋ ฅ
188
- outputs=gr.Textbox(label="์ปจํ…์ธ  ID")
189
- )
190
-
191
- status_iface = gr.Interface(
192
- fn=gradio_generate_status, # ์ปจํ…์ธ  ์ƒํƒœ ํ™•์ธ ํ•จ์ˆ˜
193
- inputs=gr.Textbox(label="์ปจํ…์ธ  ID"),
194
- outputs=gr.Textbox(label="์ปจํ…์ธ  ์ƒํƒœ ๋˜๋Š” URL")
195
- )
196
-
197
- # ์ธํ„ฐํŽ˜์ด์Šค ์‹คํ–‰
198
- iface.launch()
199
- status_iface.launch()
200
-
 
3
  import time
4
 
5
  API_HOME = 'https://api.fliki.ai/v1'
 
 
 
6
  END_GENERATE = '/generate'
7
  END_STATUS = '/generate/status'
8
  API_KEY = 'ZZUIQ4OZASNRQ8B8WYHNW'
 
9
 
10
  def set_header():
11
  header = {
 
14
  }
15
  return header
16
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
17
  # ๋น„๋””์˜ค ๋˜๋Š” ์˜ค๋””์˜ค ์ปจํ…์ธ  ์ƒ์„ฑํ•˜๋Š” ํ•จ์ˆ˜.
 
18
  def generate_contents(user_content, brand_name):
 
 
19
  url = API_HOME + END_GENERATE
20
  VOICE_ID = '65934ac2bc02ab1c006755fa' # Korean, Korea, Wolf Sea
21
 
 
26
  "format": "video", # video | audio
27
  "scenes": scenes,
28
  "settings": {
29
+ # ์„ค์ •๋“ค...
30
  },
31
  "backgroundMusicKeywords": "happy, lofi, beats"
32
  }
33
 
 
 
34
  headers = set_header()
35
  response = requests.request("POST", url, json=payload, headers=headers).json()
36
 
37
+ if response['success']:
 
 
 
38
  return response['data']['id']
39
  else:
 
40
  return 'FAILED'
41
 
42
+ # ์ปจํ…์ธ  ์ƒ์„ฑ ์ƒํƒœ๋ฅผ ํ™•์ธํ•˜๋Š” ํ•จ์ˆ˜.
 
43
  def generate_status(content_id):
44
  url = API_HOME + END_STATUS
45
  payload = {"id": content_id}
 
49
  response = requests.request("POST", url, json=payload, headers=headers).json()
50
 
51
  if response['success']:
52
+ status = response['data']['status']
53
+ if status == 'queued' or status == 'processing':
54
  time.sleep(10) # 10์ดˆ ๋Œ€๊ธฐ
55
+ elif status == 'success':
 
56
  return response['data']['file']
57
  else:
 
58
  break
59
  return 'FAILED'
60
 
61
+ # Gradio ์ธํ„ฐํŽ˜์ด์Šค ํ•จ์ˆ˜
62
  def gradio_generate_status(content_id):
63
  download_url = generate_status(content_id)
64
  if download_url != 'FAILED':
 
65
  display_text = download_url[:10] + '...' if len(download_url) > 10 else download_url
66
  html_link = f'<a href="{download_url}" target="_blank">{display_text}</a>'
 
 
67
  html_video = f'<iframe src="{download_url}" width="640" height="360" frameborder="0" allowfullscreen></iframe>'
 
 
68
  return html_link + '<br>' + html_video
69
  else:
70
  return "์ปจํ…์ธ  ์ƒ์„ฑ ์‹คํŒจ ๋˜๋Š” ID๊ฐ€ ์ž˜๋ชป๋˜์—ˆ์Šต๋‹ˆ๋‹ค."
 
76
  )
77
 
78
  status_iface.launch()