Spaces:
Runtime error
Runtime error
Commit
·
c21b473
1
Parent(s):
7bb8a21
Add list of vid links to prevent a same video being loaded
Browse files- components/pexels.py +9 -5
components/pexels.py
CHANGED
|
@@ -30,26 +30,29 @@ def search_pexels(keyword, api_key, orientation='potrait', size='medium', endpoi
|
|
| 30 |
|
| 31 |
|
| 32 |
# Video download function
|
| 33 |
-
def download_video(data, parent_path,
|
| 34 |
for x in data['videos'][0]['video_files'] :
|
| 35 |
|
| 36 |
#if width != None and x['width'] < width:
|
| 37 |
# continue
|
| 38 |
#if height != None and x['height'] < height :
|
| 39 |
#continue
|
| 40 |
-
|
|
|
|
|
|
|
| 41 |
vid = x
|
| 42 |
print(vid['link'])
|
| 43 |
with open(f"{os.path.join(parent_path,str(i) + '_' + str(vid['id']))}.mp4", 'bw') as f:
|
| 44 |
f.write(requests.get(vid['link']).content)
|
| 45 |
print("Sucessfully saved video in", os.path.join(parent_path,str(i) + '_' + str(vid['id'])) + '.mp4')
|
| 46 |
-
|
|
|
|
| 47 |
|
| 48 |
|
| 49 |
# Utilizing the LLMs to find the relevant videos
|
| 50 |
def generate_videos(product, api_key, orientation, llm_chain=None, sum_llm_chain=None):
|
| 51 |
prod = product.strip().replace(" ", "_")
|
| 52 |
-
|
| 53 |
try :
|
| 54 |
# Split the paragraph by sentences
|
| 55 |
|
|
@@ -71,7 +74,8 @@ def generate_videos(product, api_key, orientation, llm_chain=None, sum_llm_chain
|
|
| 71 |
keyword = sum_llm_chain.run(s)
|
| 72 |
print(i+1, ":", keyword)
|
| 73 |
data = search_pexels(keyword, api_key, orientation.lower())
|
| 74 |
-
download_video(data, prod, i)
|
|
|
|
| 75 |
|
| 76 |
print("Success! videos has been generated")
|
| 77 |
except Exception as e :
|
|
|
|
| 30 |
|
| 31 |
|
| 32 |
# Video download function
|
| 33 |
+
def download_video(data, parent_path, link, i):
|
| 34 |
for x in data['videos'][0]['video_files'] :
|
| 35 |
|
| 36 |
#if width != None and x['width'] < width:
|
| 37 |
# continue
|
| 38 |
#if height != None and x['height'] < height :
|
| 39 |
#continue
|
| 40 |
+
if x['link'] in links:
|
| 41 |
+
continue
|
| 42 |
+
|
| 43 |
vid = x
|
| 44 |
print(vid['link'])
|
| 45 |
with open(f"{os.path.join(parent_path,str(i) + '_' + str(vid['id']))}.mp4", 'bw') as f:
|
| 46 |
f.write(requests.get(vid['link']).content)
|
| 47 |
print("Sucessfully saved video in", os.path.join(parent_path,str(i) + '_' + str(vid['id'])) + '.mp4')
|
| 48 |
+
return vid['link']
|
| 49 |
+
|
| 50 |
|
| 51 |
|
| 52 |
# Utilizing the LLMs to find the relevant videos
|
| 53 |
def generate_videos(product, api_key, orientation, llm_chain=None, sum_llm_chain=None):
|
| 54 |
prod = product.strip().replace(" ", "_")
|
| 55 |
+
links = []
|
| 56 |
try :
|
| 57 |
# Split the paragraph by sentences
|
| 58 |
|
|
|
|
| 74 |
keyword = sum_llm_chain.run(s)
|
| 75 |
print(i+1, ":", keyword)
|
| 76 |
data = search_pexels(keyword, api_key, orientation.lower())
|
| 77 |
+
link= download_video(data, prod, links,i)
|
| 78 |
+
links.append(link)
|
| 79 |
|
| 80 |
print("Success! videos has been generated")
|
| 81 |
except Exception as e :
|