Spaces:
Runtime error
Runtime error
Update confusedautoshortvideogen.py
Browse files- confusedautoshortvideogen.py +1 -316
confusedautoshortvideogen.py
CHANGED
@@ -20,55 +20,7 @@ mscript_music_input = "What is depression"
|
|
20 |
final_video_output = "final_video_output.mp4"
|
21 |
musicownpath = '/content/tmp1mbn3d3s.mp4'
|
22 |
|
23 |
-
|
24 |
-
|
25 |
-
**script_writing.py**
|
26 |
-
|
27 |
-
input_text (user_input)
|
28 |
-
script_output (scripttxt_output)
|
29 |
-
script_text (text)
|
30 |
-
audio_gen.py
|
31 |
-
|
32 |
-
script_audio_input (scripttxt_input)
|
33 |
-
audio_file (audio_output)
|
34 |
-
audio_format (mp3)
|
35 |
-
music_gen.py
|
36 |
-
|
37 |
-
script_music_input (scripttxt_input)
|
38 |
-
music_file (music_output)
|
39 |
-
music_format (mp3)
|
40 |
-
time_stamp_code.py
|
41 |
-
|
42 |
-
input_audio (audio_input)
|
43 |
-
timestamp_csv (tscsv_output)
|
44 |
-
csv_format (csv)
|
45 |
-
common_words_remover.py
|
46 |
-
|
47 |
-
raw_csv (csv_input)
|
48 |
-
filtered_csv (commoncsv_output)
|
49 |
-
csv_data (csv)
|
50 |
-
giphy_download.py
|
51 |
-
|
52 |
-
input_keywords (commoncsv_input)
|
53 |
-
downloaded_gif (gif_output)
|
54 |
-
gif_format (gif)
|
55 |
-
gif_crop_concat.py
|
56 |
-
|
57 |
-
raw_gif (gif_input)
|
58 |
-
gif_keywords (commoncsv_input)
|
59 |
-
final_video (concatenate_cropped_output)
|
60 |
-
video_format (mp4)
|
61 |
-
video_finalizer.py
|
62 |
-
|
63 |
-
video_input (concatenate_cropped_input)
|
64 |
-
audio_track (audio_input)
|
65 |
-
timestamps (tscsv_input)
|
66 |
-
background_music (music_input)
|
67 |
-
output_video (final_video_output)
|
68 |
-
output_format (mp4)
|
69 |
-
|
70 |
-
### script_writing.py
|
71 |
-
"""
|
72 |
|
73 |
import csv
|
74 |
import re
|
@@ -186,43 +138,6 @@ shutil.copy(audio_file_path, output_file_path)
|
|
186 |
|
187 |
"""###Music Gen"""
|
188 |
|
189 |
-
#from gradio_client import Client
|
190 |
-
#import requests
|
191 |
-
|
192 |
-
# Initialize the client with the correct Hugging Face Space URL
|
193 |
-
# Make sure the URL is correct and points to a valid Gradio app.
|
194 |
-
#client = Client("https://huggingface.co/spaces/facebook/MusicGen") # Updated URL
|
195 |
-
|
196 |
-
# Define the input for the API
|
197 |
-
#input_text = "youtube shorts background music, beatbox, loop"
|
198 |
-
|
199 |
-
# Query the API (fn_index=2 is used based on the provided information)
|
200 |
-
#result = client.predict(
|
201 |
-
# input_text, # str input in 'parameter_16' Dataset component
|
202 |
-
# fn_index=2
|
203 |
-
#)
|
204 |
-
|
205 |
-
# Check the result type
|
206 |
-
#print(result)
|
207 |
-
|
208 |
-
# Extract the URL from the result
|
209 |
-
# Assuming result is a tuple where the audio URL is the second element
|
210 |
-
#audio_url = result[1]
|
211 |
-
|
212 |
-
# Define the output file path
|
213 |
-
#output_file_path = "/content/tmp1mbn3d3s.mp4"
|
214 |
-
|
215 |
-
# Download the audio content from the URL
|
216 |
-
#response = requests.get(audio_url)
|
217 |
-
#audio_content = response.content
|
218 |
-
|
219 |
-
# Save the audio output to the specified path
|
220 |
-
#with open(output_file_path, 'wb') as f:
|
221 |
-
# f.write(audio_content)
|
222 |
-
|
223 |
-
# Provide download link for the generated audio file
|
224 |
-
#from google.colab import files
|
225 |
-
#files.download(output_file_path)
|
226 |
|
227 |
"""### Time Stamp"""
|
228 |
|
@@ -401,236 +316,6 @@ with open(CSV_FILE, 'r', encoding='utf-8') as file:
|
|
401 |
filename = f"{word}.gif"
|
402 |
download_giphy_gif(word, filename)
|
403 |
|
404 |
-
"""### Updated Download gif
|
405 |
-
|
406 |
-
import requests
|
407 |
-
import csv
|
408 |
-
import os
|
409 |
-
|
410 |
-
# Giphy API details
|
411 |
-
API_KEY = "KzPlVn6nz6czmjWpPEy6reL52r1H5gs7"
|
412 |
-
SEARCH_URL = "https://api.giphy.com/v1/gifs/search"
|
413 |
-
|
414 |
-
# CSV and download directory
|
415 |
-
CSV_FILE = "/content/updated_filtered_transcription.csv"
|
416 |
-
DOWNLOAD_DIR = '/content/memes2'
|
417 |
-
|
418 |
-
# Create download directory if it doesn't exist
|
419 |
-
os.makedirs(DOWNLOAD_DIR, exist_ok=True)
|
420 |
-
|
421 |
-
def download_giphy_gif(search_term, index, offset=0):
|
422 |
-
Downloads a GIF from Giphy based on the search term.
|
423 |
-
params = {
|
424 |
-
'api_key': API_KEY,
|
425 |
-
'q': search_term,
|
426 |
-
'limit': 1,
|
427 |
-
'offset': offset
|
428 |
-
}
|
429 |
-
response = requests.get(SEARCH_URL, params=params)
|
430 |
-
data = response.json()
|
431 |
-
|
432 |
-
if data['data']:
|
433 |
-
gif_url = data['data'][0]['images']['original']['url']
|
434 |
-
gif_response = requests.get(gif_url)
|
435 |
-
|
436 |
-
filename = f"{index}.gif"
|
437 |
-
filepath = os.path.join(DOWNLOAD_DIR, filename)
|
438 |
-
|
439 |
-
with open(filepath, 'wb') as f:
|
440 |
-
f.write(gif_response.content)
|
441 |
-
print(f"Downloaded GIF for '{search_term}' as '{filename}'")
|
442 |
-
return gif_url
|
443 |
-
else:
|
444 |
-
print(f"No GIF found for '{search_term}'")
|
445 |
-
return None
|
446 |
-
|
447 |
-
# Process the CSV file
|
448 |
-
with open(CSV_FILE, 'r', encoding='utf-8') as file:
|
449 |
-
reader = csv.DictReader(file)
|
450 |
-
word_counts = {}
|
451 |
-
for index, row in enumerate(reader):
|
452 |
-
word = row['word']
|
453 |
-
if word in word_counts:
|
454 |
-
word_counts[word] += 1
|
455 |
-
else:
|
456 |
-
word_counts[word] = 1
|
457 |
-
|
458 |
-
gif_url = download_giphy_gif(word, index, offset=word_counts[word] - 1)
|
459 |
-
if gif_url:
|
460 |
-
row['link'] = gif_url
|
461 |
-
|
462 |
-
# Write the updated CSV file
|
463 |
-
with open(CSV_FILE, 'w', newline='', encoding='utf-8') as file:
|
464 |
-
writer = csv.DictWriter(file, fieldnames=['word', 'link'])
|
465 |
-
writer.writeheader()
|
466 |
-
writer.writerows([{'word': word, 'link': gif_url} for word, gif_url in [(row['word'], row['link']) for row in reader]])
|
467 |
-
"""
|
468 |
-
|
469 |
-
# prompt: write a code to save /content/updated_filtered_transcription.csv with index
|
470 |
-
"""
|
471 |
-
import pandas as pd
|
472 |
-
df = pd.read_csv('/content/updated_filtered_transcription.csv')
|
473 |
-
df.to_csv('/content/updated_filtered_transcription.csv', index=True)
|
474 |
-
"""
|
475 |
-
|
476 |
-
"""import requests
|
477 |
-
import csv
|
478 |
-
import os
|
479 |
-
|
480 |
-
# Giphy API details
|
481 |
-
API_KEY = "KzPlVn6nz6czmjWpPEy6reL52r1H5gs7"
|
482 |
-
SEARCH_URL = "https://api.giphy.com/v1/gifs/search"
|
483 |
-
|
484 |
-
# CSV and download directory
|
485 |
-
CSV_FILE = "/content/updated_filtered_transcription.csv"
|
486 |
-
DOWNLOAD_DIR = '/content/memes3'
|
487 |
-
|
488 |
-
# Create download directory if it doesn't exist
|
489 |
-
os.makedirs(DOWNLOAD_DIR, exist_ok=True)
|
490 |
-
|
491 |
-
def download_giphy_gif(search_term, index):
|
492 |
-
Downloads a GIF from Giphy based on the search term.
|
493 |
-
params = {
|
494 |
-
'api_key': API_KEY,
|
495 |
-
'q': search_term,
|
496 |
-
'limit': 1
|
497 |
-
}
|
498 |
-
response = requests.get(SEARCH_URL, params=params)
|
499 |
-
data = response.json()
|
500 |
-
|
501 |
-
if data['data']:
|
502 |
-
gif_url = data['data'][0]['images']['original']['url']
|
503 |
-
gif_response = requests.get(gif_url)
|
504 |
-
|
505 |
-
filename = f"{index}.gif"
|
506 |
-
with open(os.path.join(DOWNLOAD_DIR, filename), 'wb') as f:
|
507 |
-
f.write(gif_response.content)
|
508 |
-
print(f"Downloaded GIF for '{search_term}' as '{filename}'")
|
509 |
-
else:
|
510 |
-
print(f"No GIF found for '{search_term}'")
|
511 |
-
|
512 |
-
# Process the CSV file
|
513 |
-
with open(CSV_FILE, 'r', encoding='utf-8') as file:
|
514 |
-
reader = csv.DictReader(file)
|
515 |
-
for index, row in enumerate(reader):
|
516 |
-
word = row['word']
|
517 |
-
download_giphy_gif(word, index)
|
518 |
-
|
519 |
-
import requests
|
520 |
-
import csv
|
521 |
-
import os
|
522 |
-
|
523 |
-
# Giphy API details
|
524 |
-
API_KEY = "KzPlVn6nz6czmjWpPEy6reL52r1H5gs7"
|
525 |
-
SEARCH_URL = "https://api.giphy.com/v1/gifs/search"
|
526 |
-
|
527 |
-
# CSV and download directory
|
528 |
-
CSV_FILE = "/content/updated_filtered_transcription.csv"
|
529 |
-
DOWNLOAD_DIR = '/content/memes3'
|
530 |
-
|
531 |
-
# Create download directory if it doesn't exist
|
532 |
-
os.makedirs(DOWNLOAD_DIR, exist_ok=True)
|
533 |
-
|
534 |
-
def download_giphy_gif(search_term, index):
|
535 |
-
Downloads a GIF from Giphy based on the search term.
|
536 |
-
params = {
|
537 |
-
'api_key': API_KEY,
|
538 |
-
'q': search_term,
|
539 |
-
'limit': 1
|
540 |
-
}
|
541 |
-
response = requests.get(SEARCH_URL, params=params)
|
542 |
-
data = response.json()
|
543 |
-
|
544 |
-
if data['data']:
|
545 |
-
gif_url = data['data'][0]['images']['original']['url']
|
546 |
-
gif_response = requests.get(gif_url)
|
547 |
-
|
548 |
-
filename = f"{index}.gif"
|
549 |
-
filepath = os.path.join(DOWNLOAD_DIR, filename)
|
550 |
-
|
551 |
-
# Check if the file already exists
|
552 |
-
if not os.path.exists(filepath):
|
553 |
-
with open(filepath, 'wb') as f:
|
554 |
-
f.write(gif_response.content)
|
555 |
-
print(f"Downloaded GIF for '{search_term}' as '{filename}'")
|
556 |
-
else:
|
557 |
-
print(f"GIF for '{search_term}' already exists")
|
558 |
-
|
559 |
-
return gif_url
|
560 |
-
else:
|
561 |
-
print(f"No GIF found for '{search_term}'")
|
562 |
-
return None
|
563 |
-
|
564 |
-
# Process the CSV file
|
565 |
-
with open(CSV_FILE, 'r', encoding='utf-8') as file:
|
566 |
-
reader = csv.DictReader(file)
|
567 |
-
rows = list(reader) # Convert reader to a list to ensure it's fully read
|
568 |
-
|
569 |
-
# Check if any rows were read
|
570 |
-
if rows:
|
571 |
-
# Add a "link" column if it doesn't exist
|
572 |
-
if 'link' not in rows[0].keys():
|
573 |
-
for row in rows:
|
574 |
-
row['link'] = ''
|
575 |
-
|
576 |
-
# Download GIFs and update the "link" column
|
577 |
-
for index, row in enumerate(rows):
|
578 |
-
word = row['word']
|
579 |
-
gif_url = download_giphy_gif(word, index)
|
580 |
-
if gif_url:
|
581 |
-
row['link'] = gif_url
|
582 |
-
|
583 |
-
# Write the updated CSV file
|
584 |
-
with open(CSV_FILE, 'w', newline='', encoding='utf-8') as file:
|
585 |
-
writer = csv.DictWriter(file, fieldnames=rows[0].keys())
|
586 |
-
writer.writeheader()
|
587 |
-
writer.writerows(rows)
|
588 |
-
else:
|
589 |
-
print("The CSV file is empty.")
|
590 |
-
|
591 |
-
import os
|
592 |
-
import pandas as pd
|
593 |
-
|
594 |
-
# Read the CSV file
|
595 |
-
df = pd.read_csv('/content/updated_filtered_transcription.csv')
|
596 |
-
|
597 |
-
# Get the list of words from the DataFrame
|
598 |
-
words = df['word'].tolist()
|
599 |
-
|
600 |
-
# Get the list of GIF files in the directory
|
601 |
-
gif_files = [f for f in os.listdir('/content/memes2') if f.endswith('.gif')]
|
602 |
-
|
603 |
-
# Ensure we have enough words for the GIF files
|
604 |
-
if len(words) < len(gif_files):
|
605 |
-
raise ValueError("Not enough words in the CSV file to rename all GIFs.")
|
606 |
-
|
607 |
-
# Iterate through the GIF files and rename them
|
608 |
-
for i, gif_file in enumerate(gif_files):
|
609 |
-
try:
|
610 |
-
# Generate new filename based on index from the CSV
|
611 |
-
new_filename = f"{i+1}.gif" # Index starts from 1
|
612 |
-
|
613 |
-
# Construct the full paths for the old and new filenames
|
614 |
-
old_path = os.path.join('/content/memes2', gif_file)
|
615 |
-
new_path = os.path.join('/content/memes2', new_filename)
|
616 |
-
|
617 |
-
# Rename the file
|
618 |
-
os.rename(old_path, new_path)
|
619 |
-
print(f"Renamed '{gif_file}' to '{new_filename}'")
|
620 |
-
except Exception as e:
|
621 |
-
print(f"Error processing file '{gif_file}': {e}")
|
622 |
-
|
623 |
-
### Concate Gif (incomplete)
|
624 |
-
"""
|
625 |
-
|
626 |
-
# prompt: drop Unnamed: 0 and save the file
|
627 |
-
|
628 |
-
#import pandas as pd
|
629 |
-
#df = pd.read_csv('/content/updated_filtered_transcription.csv')
|
630 |
-
#df = df.drop(columns=['Unnamed: 0'])
|
631 |
-
#df.to_csv('/content/updated_filtered_transcription.csv', index=False)
|
632 |
-
df.head()
|
633 |
-
|
634 |
import moviepy.editor as mpe
|
635 |
import os
|
636 |
import csv
|
|
|
20 |
final_video_output = "final_video_output.mp4"
|
21 |
musicownpath = '/content/tmp1mbn3d3s.mp4'
|
22 |
|
23 |
+
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
24 |
|
25 |
import csv
|
26 |
import re
|
|
|
138 |
|
139 |
"""###Music Gen"""
|
140 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
141 |
|
142 |
"""### Time Stamp"""
|
143 |
|
|
|
316 |
filename = f"{word}.gif"
|
317 |
download_giphy_gif(word, filename)
|
318 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|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