Update app.py
Browse files
app.py
CHANGED
@@ -46,10 +46,7 @@ def search_google_images(query, num_images=1):
|
|
46 |
cse_id = os.getenv('GOOGLE_CSE_ID')
|
47 |
proxies = load_proxies()
|
48 |
|
49 |
-
print(f"Buscando imágenes para: {query}")
|
50 |
-
|
51 |
if not proxies:
|
52 |
-
print("No proxies available, trying without proxy")
|
53 |
with requests.Session() as session:
|
54 |
result = session.get(
|
55 |
f"https://www.googleapis.com/customsearch/v1",
|
@@ -81,22 +78,6 @@ def search_google_images(query, num_images=1):
|
|
81 |
"key": api_key
|
82 |
}
|
83 |
).json()
|
84 |
-
else:
|
85 |
-
with requests_proxy.ProxyManager(proxies) as proxy_manager:
|
86 |
-
result = proxy_manager.get(
|
87 |
-
f"https://www.googleapis.com/customsearch/v1",
|
88 |
-
params={
|
89 |
-
"q": query,
|
90 |
-
"cx": cse_id,
|
91 |
-
"searchType": "image",
|
92 |
-
"num": num_images * 3,
|
93 |
-
"safe": 'off',
|
94 |
-
"imgSize": 'HUGE',
|
95 |
-
"imgType": 'photo',
|
96 |
-
"rights": 'cc_publicdomain|cc_attribute|cc_sharealike',
|
97 |
-
"key": api_key
|
98 |
-
}
|
99 |
-
).json()
|
100 |
|
101 |
if 'items' in result:
|
102 |
image_urls = []
|
@@ -108,18 +89,14 @@ def search_google_images(query, num_images=1):
|
|
108 |
image_urls.append(item['link'])
|
109 |
if len(image_urls) >= num_images:
|
110 |
break
|
111 |
-
|
112 |
-
print(f"Encontradas {len(image_urls)} imágenes de tamaño adecuado")
|
113 |
return image_urls
|
114 |
|
115 |
print("No se encontraron imágenes después de probar todos los proxies")
|
116 |
return []
|
117 |
-
|
118 |
except Exception as e:
|
119 |
print(f"Error general en la búsqueda de imágenes: {str(e)}")
|
120 |
return []
|
121 |
|
122 |
-
|
123 |
def process_image(image):
|
124 |
try:
|
125 |
width, height = image.size
|
@@ -135,8 +112,7 @@ def process_image(image):
|
|
135 |
image = image.resize((new_width, new_height), Image.Resampling.LANCZOS)
|
136 |
background = Image.new('RGB', (max(new_width, MIN_WIDTH), max(new_height, MIN_HEIGHT)), 'black')
|
137 |
|
138 |
-
offset = ((background.width - image.width) // 2,
|
139 |
-
(background.height - image.height) // 2)
|
140 |
background.paste(image, offset)
|
141 |
|
142 |
return background
|
@@ -160,9 +136,8 @@ def download_image(url):
|
|
160 |
image = background
|
161 |
|
162 |
processed_image = process_image(image)
|
163 |
-
if processed_image:
|
164 |
return processed_image
|
165 |
-
|
166 |
except Exception as e:
|
167 |
print(f"Error downloading image with proxy {proxy}: {e}")
|
168 |
continue
|
@@ -185,7 +160,6 @@ def concatenate_google_images(keywords, clip_duration=5, num_images_per_keyword=
|
|
185 |
video_clips = []
|
186 |
for keyword in keyword_list:
|
187 |
try:
|
188 |
-
print(f"Searching images for keyword '{keyword}'...")
|
189 |
image_urls = search_google_images(keyword, num_images=num_images_per_keyword)
|
190 |
for url in image_urls:
|
191 |
image = download_image(url)
|
@@ -239,7 +213,7 @@ def combine_audio_video(audio_file, video_clip, music_clip=None):
|
|
239 |
audio_clip.close()
|
240 |
if music_clip:
|
241 |
music_clip.close()
|
242 |
-
|
243 |
return output_path
|
244 |
except Exception as e:
|
245 |
print(f"Error combining audio and video: {e}")
|
@@ -302,7 +276,6 @@ def process_input(text, txt_file, mp3_file, selected_voice, rate, pitch, keyword
|
|
302 |
|
303 |
download_link = upload_to_google_drive(final_video_path, folder_id=FOLDER_ID)
|
304 |
if download_link:
|
305 |
-
print(f"Video uploaded to Google Drive. Download link: {download_link}")
|
306 |
return f"[Download video]({download_link})"
|
307 |
else:
|
308 |
raise ValueError("Error uploading video to Google Drive")
|
@@ -319,10 +292,7 @@ with gr.Blocks() as demo:
|
|
319 |
text_input = gr.Textbox(label="Write your text here", lines=5)
|
320 |
txt_file_input = gr.File(label="Or upload a .txt file", file_types=[".txt"])
|
321 |
mp3_file_input = gr.File(label="Upload background music (.mp3)", file_types=[".mp3"])
|
322 |
-
keyword_input = gr.Textbox(
|
323 |
-
label="Enter keywords separated by commas",
|
324 |
-
value="fear, religion, god, demons, aliens, possession, galaxy, mysterious, dystopian, astral, warfare, space, space, galaxy, moon, fear, astral, god, evil, mystery, cosmos, stars, paranormal, inexplicable, hidden, enigma, unknown, unusual, intriguing, curious, strange, supernatural, esoteric, arcane, occultism, supernatural, mystery, phenomenon, rare, unusual, enigmatic, sinister, gloomy, dark, shadowy, macabre, eerie, chilling, cursed, fantastic, unreal, unknown, mysterious, enigmatic, inexplicable, unusual, strange, unusual, arcane, esoteric, hidden, shadowy, dark, gloomy, sinister, macabre, eerie, chilling, cursed, fantastic, unreal, paranormal, supernatural, occultism, phenomenon, rare, intriguing, curious"
|
325 |
-
)
|
326 |
voices = asyncio.run(get_voices())
|
327 |
voice_dropdown = gr.Dropdown(choices=list(voices.keys()), label="Select Voice")
|
328 |
rate_slider = gr.Slider(minimum=-50, maximum=50, value=0, label="Speech Rate Adjustment (%)", step=1)
|
|
|
46 |
cse_id = os.getenv('GOOGLE_CSE_ID')
|
47 |
proxies = load_proxies()
|
48 |
|
|
|
|
|
49 |
if not proxies:
|
|
|
50 |
with requests.Session() as session:
|
51 |
result = session.get(
|
52 |
f"https://www.googleapis.com/customsearch/v1",
|
|
|
78 |
"key": api_key
|
79 |
}
|
80 |
).json()
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
81 |
|
82 |
if 'items' in result:
|
83 |
image_urls = []
|
|
|
89 |
image_urls.append(item['link'])
|
90 |
if len(image_urls) >= num_images:
|
91 |
break
|
|
|
|
|
92 |
return image_urls
|
93 |
|
94 |
print("No se encontraron imágenes después de probar todos los proxies")
|
95 |
return []
|
|
|
96 |
except Exception as e:
|
97 |
print(f"Error general en la búsqueda de imágenes: {str(e)}")
|
98 |
return []
|
99 |
|
|
|
100 |
def process_image(image):
|
101 |
try:
|
102 |
width, height = image.size
|
|
|
112 |
image = image.resize((new_width, new_height), Image.Resampling.LANCZOS)
|
113 |
background = Image.new('RGB', (max(new_width, MIN_WIDTH), max(new_height, MIN_HEIGHT)), 'black')
|
114 |
|
115 |
+
offset = ((background.width - image.width) // 2, (background.height - image.height) // 2)
|
|
|
116 |
background.paste(image, offset)
|
117 |
|
118 |
return background
|
|
|
136 |
image = background
|
137 |
|
138 |
processed_image = process_image(image)
|
139 |
+
if processed_image:
|
140 |
return processed_image
|
|
|
141 |
except Exception as e:
|
142 |
print(f"Error downloading image with proxy {proxy}: {e}")
|
143 |
continue
|
|
|
160 |
video_clips = []
|
161 |
for keyword in keyword_list:
|
162 |
try:
|
|
|
163 |
image_urls = search_google_images(keyword, num_images=num_images_per_keyword)
|
164 |
for url in image_urls:
|
165 |
image = download_image(url)
|
|
|
213 |
audio_clip.close()
|
214 |
if music_clip:
|
215 |
music_clip.close()
|
216 |
+
|
217 |
return output_path
|
218 |
except Exception as e:
|
219 |
print(f"Error combining audio and video: {e}")
|
|
|
276 |
|
277 |
download_link = upload_to_google_drive(final_video_path, folder_id=FOLDER_ID)
|
278 |
if download_link:
|
|
|
279 |
return f"[Download video]({download_link})"
|
280 |
else:
|
281 |
raise ValueError("Error uploading video to Google Drive")
|
|
|
292 |
text_input = gr.Textbox(label="Write your text here", lines=5)
|
293 |
txt_file_input = gr.File(label="Or upload a .txt file", file_types=[".txt"])
|
294 |
mp3_file_input = gr.File(label="Upload background music (.mp3)", file_types=[".mp3"])
|
295 |
+
keyword_input = gr.Textbox(label="Enter keywords separated by commas", value="fear, religion, god, demons, aliens, possession, galaxy, mysterious, dystopian, astral, warfare, space, space, galaxy, moon, fear, astral, god, evil, mystery, cosmos, stars, paranormal, inexplicable, hidden, enigma, unknown, unusual, intriguing, curious, strange, supernatural, esoteric, arcane, occultism, supernatural, mystery, phenomenon, rare, unusual, enigmatic, sinister, gloomy, dark, shadowy, macabre, eerie, chilling, cursed, fantastic, unreal, unknown, mysterious, enigmatic, inexplicable, unusual, strange, unusual, arcane, esoteric, hidden, shadowy, dark, gloomy, sinister, macabre, eerie, chilling, cursed, fantastic, unreal, paranormal, supernatural, occultism, phenomenon, rare, intriguing, curious")
|
|
|
|
|
|
|
296 |
voices = asyncio.run(get_voices())
|
297 |
voice_dropdown = gr.Dropdown(choices=list(voices.keys()), label="Select Voice")
|
298 |
rate_slider = gr.Slider(minimum=-50, maximum=50, value=0, label="Speech Rate Adjustment (%)", step=1)
|