Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
@@ -3,6 +3,10 @@ import os
|
|
3 |
from lumaai import AsyncLumaAI
|
4 |
import asyncio
|
5 |
import aiohttp
|
|
|
|
|
|
|
|
|
6 |
|
7 |
async def get_camera_motions():
|
8 |
api_key = os.getenv("LMGEN_KEY")
|
@@ -53,10 +57,10 @@ async def generate_video(client, prompt, loop=False, aspect_ratio="16:9", camera
|
|
53 |
}
|
54 |
}
|
55 |
|
56 |
-
progress(0, desc="
|
57 |
generation = await client.generations.create(**generation_params)
|
58 |
|
59 |
-
progress(0.1, desc="
|
60 |
|
61 |
# Poll for completion
|
62 |
start_time = asyncio.get_event_loop().time()
|
@@ -65,16 +69,16 @@ async def generate_video(client, prompt, loop=False, aspect_ratio="16:9", camera
|
|
65 |
if status.state == "completed":
|
66 |
break
|
67 |
elif status.state == "failed":
|
68 |
-
raise Exception("
|
69 |
|
70 |
# Update progress based on time elapsed (assuming 60 seconds total)
|
71 |
elapsed_time = asyncio.get_event_loop().time() - start_time
|
72 |
progress_value = min(0.1 + (elapsed_time / 60) * 0.8, 0.9)
|
73 |
-
progress(progress_value, desc="
|
74 |
|
75 |
await asyncio.sleep(5)
|
76 |
|
77 |
-
progress(0.9, desc="
|
78 |
|
79 |
# Download the video
|
80 |
video_url = status.assets.video
|
@@ -89,39 +93,57 @@ async def generate_video(client, prompt, loop=False, aspect_ratio="16:9", camera
|
|
89 |
break
|
90 |
fd.write(chunk)
|
91 |
|
92 |
-
progress(1.0, desc="
|
93 |
return file_name
|
94 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
95 |
async def text_to_video(prompt, loop, aspect_ratio, camera_motion, extend_id, reverse_extend_id, interpolate_id1, interpolate_id2, progress=gr.Progress()):
|
96 |
api_key = os.getenv("LMGEN_KEY")
|
97 |
if not api_key:
|
98 |
-
raise gr.Error("LMGEN_KEY
|
99 |
|
100 |
client = AsyncLumaAI(auth_token=api_key)
|
101 |
|
102 |
try:
|
|
|
|
|
|
|
|
|
|
|
103 |
interpolate_ids = None
|
104 |
if interpolate_id1 and interpolate_id2:
|
105 |
interpolate_ids = [interpolate_id1, interpolate_id2]
|
106 |
|
107 |
video_path = await generate_video(
|
108 |
-
client,
|
109 |
extend_id, reverse_extend_id, interpolate_ids, progress
|
110 |
)
|
111 |
return video_path, ""
|
112 |
except Exception as e:
|
113 |
-
return None, f"
|
114 |
|
115 |
async def image_to_video(prompt, image_url, loop, aspect_ratio, camera_motion, progress=gr.Progress()):
|
116 |
api_key = os.getenv("LMGEN_KEY")
|
117 |
if not api_key:
|
118 |
-
raise gr.Error("LMGEN_KEY
|
119 |
|
120 |
client = AsyncLumaAI(auth_token=api_key)
|
121 |
|
122 |
try:
|
|
|
|
|
|
|
|
|
|
|
123 |
generation_params = {
|
124 |
-
"prompt":
|
125 |
"loop": loop,
|
126 |
"aspect_ratio": aspect_ratio,
|
127 |
"keyframes": {
|
@@ -132,10 +154,10 @@ async def image_to_video(prompt, image_url, loop, aspect_ratio, camera_motion, p
|
|
132 |
}
|
133 |
}
|
134 |
|
135 |
-
progress(0, desc="
|
136 |
generation = await client.generations.create(**generation_params)
|
137 |
|
138 |
-
progress(0.1, desc="
|
139 |
|
140 |
# Poll for completion
|
141 |
start_time = asyncio.get_event_loop().time()
|
@@ -144,16 +166,16 @@ async def image_to_video(prompt, image_url, loop, aspect_ratio, camera_motion, p
|
|
144 |
if status.state == "completed":
|
145 |
break
|
146 |
elif status.state == "failed":
|
147 |
-
raise Exception("
|
148 |
|
149 |
# Update progress based on time elapsed (assuming 60 seconds total)
|
150 |
elapsed_time = asyncio.get_event_loop().time() - start_time
|
151 |
progress_value = min(0.1 + (elapsed_time / 60) * 0.8, 0.9)
|
152 |
-
progress(progress_value, desc="
|
153 |
|
154 |
await asyncio.sleep(5)
|
155 |
|
156 |
-
progress(0.9, desc="
|
157 |
|
158 |
# Download the video
|
159 |
video_url = status.assets.video
|
@@ -168,10 +190,10 @@ async def image_to_video(prompt, image_url, loop, aspect_ratio, camera_motion, p
|
|
168 |
break
|
169 |
fd.write(chunk)
|
170 |
|
171 |
-
progress(1.0, desc="
|
172 |
return file_name, ""
|
173 |
except Exception as e:
|
174 |
-
return None, f"
|
175 |
|
176 |
with gr.Blocks() as demo:
|
177 |
gr.Markdown("# Luma AI ν
μ€νΈ-λΉλμ€ μμ± λ°λͺ¨")
|
|
|
3 |
from lumaai import AsyncLumaAI
|
4 |
import asyncio
|
5 |
import aiohttp
|
6 |
+
from transformers import pipeline
|
7 |
+
|
8 |
+
# λ²μ νμ΄νλΌμΈ μ΄κΈ°ν
|
9 |
+
translator = pipeline("translation", model="Helsinki-NLP/opus-mt-ko-en")
|
10 |
|
11 |
async def get_camera_motions():
|
12 |
api_key = os.getenv("LMGEN_KEY")
|
|
|
57 |
}
|
58 |
}
|
59 |
|
60 |
+
progress(0, desc="λΉλμ€ μμ± μμ μ€...")
|
61 |
generation = await client.generations.create(**generation_params)
|
62 |
|
63 |
+
progress(0.1, desc="λΉλμ€ μμ± μμλ¨. μλ£ λκΈ° μ€...")
|
64 |
|
65 |
# Poll for completion
|
66 |
start_time = asyncio.get_event_loop().time()
|
|
|
69 |
if status.state == "completed":
|
70 |
break
|
71 |
elif status.state == "failed":
|
72 |
+
raise Exception("λΉλμ€ μμ± μ€ν¨")
|
73 |
|
74 |
# Update progress based on time elapsed (assuming 60 seconds total)
|
75 |
elapsed_time = asyncio.get_event_loop().time() - start_time
|
76 |
progress_value = min(0.1 + (elapsed_time / 60) * 0.8, 0.9)
|
77 |
+
progress(progress_value, desc="λΉλμ€ μμ± μ€...")
|
78 |
|
79 |
await asyncio.sleep(5)
|
80 |
|
81 |
+
progress(0.9, desc="μμ±λ λΉλμ€ λ€μ΄λ‘λ μ€...")
|
82 |
|
83 |
# Download the video
|
84 |
video_url = status.assets.video
|
|
|
93 |
break
|
94 |
fd.write(chunk)
|
95 |
|
96 |
+
progress(1.0, desc="λΉλμ€ μμ± μλ£!")
|
97 |
return file_name
|
98 |
|
99 |
+
async def translate_prompt(prompt):
|
100 |
+
try:
|
101 |
+
translated = translator(prompt, max_length=512)[0]['translation_text']
|
102 |
+
return translated
|
103 |
+
except Exception as e:
|
104 |
+
print(f"λ²μ μ€ μ€λ₯ λ°μ: {str(e)}")
|
105 |
+
return prompt # λ²μ μ€ν¨ μ μλ³Έ ν둬ννΈ λ°ν
|
106 |
+
|
107 |
async def text_to_video(prompt, loop, aspect_ratio, camera_motion, extend_id, reverse_extend_id, interpolate_id1, interpolate_id2, progress=gr.Progress()):
|
108 |
api_key = os.getenv("LMGEN_KEY")
|
109 |
if not api_key:
|
110 |
+
raise gr.Error("LMGEN_KEY νκ²½ λ³μκ° μ€μ λμ§ μμμ΅λλ€.")
|
111 |
|
112 |
client = AsyncLumaAI(auth_token=api_key)
|
113 |
|
114 |
try:
|
115 |
+
# ν둬ννΈ λ²μ
|
116 |
+
translated_prompt = await translate_prompt(prompt)
|
117 |
+
print(f"μλ³Έ ν둬ννΈ: {prompt}")
|
118 |
+
print(f"λ²μλ ν둬ννΈ: {translated_prompt}")
|
119 |
+
|
120 |
interpolate_ids = None
|
121 |
if interpolate_id1 and interpolate_id2:
|
122 |
interpolate_ids = [interpolate_id1, interpolate_id2]
|
123 |
|
124 |
video_path = await generate_video(
|
125 |
+
client, translated_prompt, loop, aspect_ratio, camera_motion,
|
126 |
extend_id, reverse_extend_id, interpolate_ids, progress
|
127 |
)
|
128 |
return video_path, ""
|
129 |
except Exception as e:
|
130 |
+
return None, f"μ€λ₯ λ°μ: {str(e)}"
|
131 |
|
132 |
async def image_to_video(prompt, image_url, loop, aspect_ratio, camera_motion, progress=gr.Progress()):
|
133 |
api_key = os.getenv("LMGEN_KEY")
|
134 |
if not api_key:
|
135 |
+
raise gr.Error("LMGEN_KEY νκ²½ λ³μκ° μ€μ λμ§ μμμ΅λλ€.")
|
136 |
|
137 |
client = AsyncLumaAI(auth_token=api_key)
|
138 |
|
139 |
try:
|
140 |
+
# ν둬ννΈ λ²μ
|
141 |
+
translated_prompt = await translate_prompt(prompt)
|
142 |
+
print(f"μλ³Έ ν둬ννΈ: {prompt}")
|
143 |
+
print(f"λ²μλ ν둬ννΈ: {translated_prompt}")
|
144 |
+
|
145 |
generation_params = {
|
146 |
+
"prompt": translated_prompt + (f" {camera_motion}" if camera_motion else ""),
|
147 |
"loop": loop,
|
148 |
"aspect_ratio": aspect_ratio,
|
149 |
"keyframes": {
|
|
|
154 |
}
|
155 |
}
|
156 |
|
157 |
+
progress(0, desc="μ΄λ―Έμ§λ‘λΆν° λΉλμ€ μμ± μμ μ€...")
|
158 |
generation = await client.generations.create(**generation_params)
|
159 |
|
160 |
+
progress(0.1, desc="λΉλμ€ μμ± μμλ¨. μλ£ λκΈ° μ€...")
|
161 |
|
162 |
# Poll for completion
|
163 |
start_time = asyncio.get_event_loop().time()
|
|
|
166 |
if status.state == "completed":
|
167 |
break
|
168 |
elif status.state == "failed":
|
169 |
+
raise Exception("λΉλμ€ μμ± μ€ν¨")
|
170 |
|
171 |
# Update progress based on time elapsed (assuming 60 seconds total)
|
172 |
elapsed_time = asyncio.get_event_loop().time() - start_time
|
173 |
progress_value = min(0.1 + (elapsed_time / 60) * 0.8, 0.9)
|
174 |
+
progress(progress_value, desc="λΉλμ€ μμ± μ€...")
|
175 |
|
176 |
await asyncio.sleep(5)
|
177 |
|
178 |
+
progress(0.9, desc="μμ±λ λΉλμ€ λ€μ΄λ‘λ μ€...")
|
179 |
|
180 |
# Download the video
|
181 |
video_url = status.assets.video
|
|
|
190 |
break
|
191 |
fd.write(chunk)
|
192 |
|
193 |
+
progress(1.0, desc="λΉλμ€ μμ± μλ£!")
|
194 |
return file_name, ""
|
195 |
except Exception as e:
|
196 |
+
return None, f"μ€λ₯ λ°μ: {str(e)}"
|
197 |
|
198 |
with gr.Blocks() as demo:
|
199 |
gr.Markdown("# Luma AI ν
μ€νΈ-λΉλμ€ μμ± λ°λͺ¨")
|