Update app.py
Browse files
app.py
CHANGED
@@ -12,10 +12,10 @@ load_dotenv()
|
|
12 |
|
13 |
# API Keys
|
14 |
OPENAI_API_KEY = os.getenv("OPENAI_API_KEY")
|
15 |
-
|
16 |
|
17 |
# URLs
|
18 |
-
|
19 |
UPLOAD_URL = os.getenv("UPLOAD_URL")
|
20 |
|
21 |
def get_voices():
|
@@ -65,34 +65,33 @@ def upload_file(file_path):
|
|
65 |
|
66 |
def lipsync_api_call(video_url, audio_url):
|
67 |
headers = {
|
|
|
68 |
"Content-Type": "application/json",
|
69 |
-
"
|
70 |
}
|
71 |
|
72 |
data = {
|
73 |
-
"
|
74 |
-
"
|
75 |
-
|
76 |
-
|
77 |
-
|
78 |
-
"pads": [0, 5, 0, 0],
|
79 |
-
"synergizerStrength": 1
|
80 |
}
|
81 |
|
82 |
-
response = requests.post(
|
83 |
return response.json()
|
84 |
|
85 |
-
def check_job_status(
|
86 |
-
headers = {"
|
87 |
max_attempts = 30 # Limit the number of attempts
|
88 |
|
89 |
for _ in range(max_attempts):
|
90 |
-
response = requests.get(f"{
|
91 |
data = response.json()
|
92 |
|
93 |
-
if data["status"] == "
|
94 |
-
return data["
|
95 |
-
elif data["status"] == "
|
96 |
return None
|
97 |
|
98 |
time.sleep(10)
|
@@ -183,13 +182,13 @@ def process_video(voice, url, text, progress=gr.Progress()):
|
|
183 |
progress(0.5, desc="Initiating lipsync...")
|
184 |
job_data = lipsync_api_call(video_url, audio_url)
|
185 |
|
186 |
-
if "error" in job_data
|
187 |
-
raise Exception(job_data.get("error",
|
188 |
|
189 |
-
|
190 |
|
191 |
progress(0.6, desc="Processing lipsync...")
|
192 |
-
result_url = check_job_status(
|
193 |
|
194 |
if result_url:
|
195 |
progress(0.9, desc="Downloading result...")
|
@@ -227,11 +226,8 @@ def process_video(voice, url, text, progress=gr.Progress()):
|
|
227 |
|
228 |
def create_interface():
|
229 |
voices = get_voices()
|
230 |
-
|
231 |
-
|
232 |
-
footer {display: none !important;}
|
233 |
-
"""
|
234 |
-
with gr.Blocks(css=css) as app:
|
235 |
gr.Markdown("# Generator")
|
236 |
with gr.Row():
|
237 |
with gr.Column():
|
|
|
12 |
|
13 |
# API Keys
|
14 |
OPENAI_API_KEY = os.getenv("OPENAI_API_KEY")
|
15 |
+
REPLICATE_API_TOKEN = os.getenv("REPLICATE_API_TOKEN")
|
16 |
|
17 |
# URLs
|
18 |
+
REPLICATE_API_URL = "https://api.replicate.com/v1/predictions"
|
19 |
UPLOAD_URL = os.getenv("UPLOAD_URL")
|
20 |
|
21 |
def get_voices():
|
|
|
65 |
|
66 |
def lipsync_api_call(video_url, audio_url):
|
67 |
headers = {
|
68 |
+
"Authorization": f"Bearer {REPLICATE_API_TOKEN}",
|
69 |
"Content-Type": "application/json",
|
70 |
+
"Prefer": "wait"
|
71 |
}
|
72 |
|
73 |
data = {
|
74 |
+
"version": "db5a650c807b007dc5f9e5abe27c53e1b62880d1f94d218d27ce7fa802711d67",
|
75 |
+
"input": {
|
76 |
+
"face": video_url,
|
77 |
+
"input_audio": audio_url
|
78 |
+
}
|
|
|
|
|
79 |
}
|
80 |
|
81 |
+
response = requests.post(REPLICATE_API_URL, headers=headers, json=data)
|
82 |
return response.json()
|
83 |
|
84 |
+
def check_job_status(prediction_id):
|
85 |
+
headers = {"Authorization": f"Bearer {REPLICATE_API_TOKEN}"}
|
86 |
max_attempts = 30 # Limit the number of attempts
|
87 |
|
88 |
for _ in range(max_attempts):
|
89 |
+
response = requests.get(f"{REPLICATE_API_URL}/{prediction_id}", headers=headers)
|
90 |
data = response.json()
|
91 |
|
92 |
+
if data["status"] == "succeeded":
|
93 |
+
return data["output"]
|
94 |
+
elif data["status"] == "failed":
|
95 |
return None
|
96 |
|
97 |
time.sleep(10)
|
|
|
182 |
progress(0.5, desc="Initiating lipsync...")
|
183 |
job_data = lipsync_api_call(video_url, audio_url)
|
184 |
|
185 |
+
if "error" in job_data:
|
186 |
+
raise Exception(job_data.get("error", "Unknown error"))
|
187 |
|
188 |
+
prediction_id = job_data["id"]
|
189 |
|
190 |
progress(0.6, desc="Processing lipsync...")
|
191 |
+
result_url = check_job_status(prediction_id)
|
192 |
|
193 |
if result_url:
|
194 |
progress(0.9, desc="Downloading result...")
|
|
|
226 |
|
227 |
def create_interface():
|
228 |
voices = get_voices()
|
229 |
+
|
230 |
+
with gr.Blocks() as app:
|
|
|
|
|
|
|
231 |
gr.Markdown("# Generator")
|
232 |
with gr.Row():
|
233 |
with gr.Column():
|