-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.py
221 lines (170 loc) · 6.52 KB
/
main.py
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
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
# -----------------------------SETTING ENVIRONMENT-----------------------------
import os
import uvicorn
import requests
import elevenlabs
from fastapi import FastAPI
from publitio import PublitioAPI
from dotenv import load_dotenv, find_dotenv
dotenv_path = find_dotenv()
load_dotenv(dotenv_path)
def MainFunction(names):
ELEVENLABS_API = os.getenv("ELEVENLABS_API")
PUBLITIO_API = os.getenv("PUBLITIO_API")
PUBLITIO_SECRET = os.getenv("PUBLITIO_SECRET")
GOOEY_API = os.getenv("GOOEY_API")
elevenlabs.set_api_key(ELEVENLABS_API)
publitio_api = PublitioAPI(PUBLITIO_API, PUBLITIO_SECRET)
# -----------------------------ELEVENLABS-----------------------------
if not os.path.exists("Audios/"):
os.mkdir("Audios")
Names = names
for name in Names:
text = f"Hi {name}, my name is Max, welcome to ADAPTA."
# voice = "tcm9oOOhlpLxWHalMXbM" #max
voice = "Adam" # me
audio = elevenlabs.generate(text=text, voice=voice)
audio_filename = f"Audios/{name}.mp3"
elevenlabs.save(audio, audio_filename)
print(f"Saved {name}.mp3")
# -----------------------------PUBLITIO UPLAODER-----------------------------
folder_path = "Audios/"
def Audio_Uploader(folder_path):
uploaded_urls = {}
for filename in os.listdir(folder_path):
file_path = os.path.join(folder_path, filename)
with open(file_path, "rb") as f:
r = publitio_api.create_file(
file=f,
title=filename,
description=filename,
)
print(f"Uploaded {filename} to Publitio.")
url_download = r.get("url_preview")
if url_download:
uploaded_urls[filename] = url_download
else:
print(f"Failed to get URL for {filename}")
return uploaded_urls
uploaded_urls = Audio_Uploader(folder_path)
# -----------------------------CLEARING THE DIRECTORY-----------------------------
directory = "Audios/"
files = os.listdir(directory)
for file in files:
file_path = os.path.join(directory, file)
if os.path.isfile(file_path):
os.remove(file_path)
print(f"Deleted: {file_path}")
# -----------------------------GOOEY AI LIPSYNC------------------------------
url_list = list(uploaded_urls.values())
print(url_list)
names_list = list(uploaded_urls.keys())
print(names_list)
generated_urls = []
results = []
for name, url in zip(names_list, url_list):
payload = {
"input_face": "https://raw.githubusercontent.com/SOBANEJAZ/api-testing/main/video.mp4",
"input_audio": url,
}
response = requests.post(
"https://api.gooey.ai/v2/Lipsync/",
headers={"Authorization": "Bearer " + GOOEY_API},
json=payload,
)
assert response.ok, response.content
result_info = {
"name": name,
"output_video": response.json()["output"]["output_video"],
}
results.append(result_info)
# for item in result:
# print(f"Lipsync result for {item['name']}: {item['output_video']}")
app = FastAPI()
# -----------------------------SETTING ENVIRONMENT-----------------------------
import os
import uvicorn
import requests
import elevenlabs
from fastapi import FastAPI
from publitio import PublitioAPI
def MainFunction(names):
ELEVENLABS_API = os.getenv("ELEVENLABS_API") # chan
PUBLITIO_API = os.getenv("PUBLITIO_API")
PUBLITIO_SECRET = os.getenv("PUBLITIO_SECRET")
GOOEY_API = os.getenv("GOOEY_API")
elevenlabs.set_api_key(ELEVENLABS_API)
publitio_api = PublitioAPI(PUBLITIO_API, PUBLITIO_SECRET)
# -----------------------------ELEVENLABS-----------------------------
if not os.path.exists("Audios/"):
os.mkdir("Audios")
Names = names
for name in Names:
text = f"Hi {name}, my name is Max, welcome to ADAPTA."
# voice = "tcm9oOOhlpLxWHalMXbM" #max
voice = "Adam" # me
audio = elevenlabs.generate(text=text, voice=voice)
audio_filename = f"Audios/{name}.mp3"
elevenlabs.save(audio, audio_filename)
print(f"Saved {name}.mp3")
# -----------------------------PUBLITIO UPLAODER-----------------------------
folder_path = "Audios/"
def Audio_Uploader(folder_path):
uploaded_urls = {}
for filename in os.listdir(folder_path):
file_path = os.path.join(folder_path, filename)
with open(file_path, "rb") as f:
r = publitio_api.create_file(
file=f,
title=filename,
description=filename,
)
print(f"Uploaded {filename} to Publitio.")
url_download = r.get("url_preview")
if url_download:
uploaded_urls[filename] = url_download
else:
print(f"Failed to get URL for {filename}")
return uploaded_urls
uploaded_urls = Audio_Uploader(folder_path)
# -----------------------------CLEARING THE DIRECTORY-----------------------------
directory = "Audios/"
files = os.listdir(directory)
for file in files:
file_path = os.path.join(directory, file)
if os.path.isfile(file_path):
os.remove(file_path)
print(f"Deleted: {file_path}")
# -----------------------------GOOEY AI LIPSYNC------------------------------
url_list = list(uploaded_urls.values())
print(url_list)
names_list = list(uploaded_urls.keys())
print(names_list)
generated_urls = []
results = []
for name, url in zip(names_list, url_list):
payload = {
"input_face": "https://raw.githubusercontent.com/SOBANEJAZ/api-testing/main/video.mp4",
"input_audio": url,
}
response = requests.post(
"https://api.gooey.ai/v2/Lipsync/",
headers={"Authorization": "Bearer " + GOOEY_API},
json=payload,
)
assert response.ok, response.content
result_info = {
"name": name,
"output_video": response.json()["output"]["output_video"],
}
results.append(result_info)
return results
# Define your FastAPI endpoint
@app.post("/generate_videos")
async def generate_videos(names: list[str]):
results = MainFunction(names)
return {"results": results}
@app.get("/")
def root():
a = "Hello I made an API"
return a