testdeep123 commited on
Commit
06b8655
·
verified ·
1 Parent(s): e86aa56

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +68 -40
app.py CHANGED
@@ -48,6 +48,21 @@ OPENROUTER_MODEL = "mistralai/mistral-small-3.1-24b-instruct:free"
48
  OUTPUT_VIDEO_FILENAME = "final_video.mp4"
49
  USER_AGENT = "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/91.0.4472.124 Safari/537.36"
50
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
51
  # ---------------- Helper Functions ---------------- #
52
  # (Your existing helper functions remain unchanged: generate_script, parse_script,
53
  # search_pexels_videos, search_pexels_images, search_google_images, download_image,
@@ -434,7 +449,7 @@ def generate_media(prompt, user_image=None, current_index=0, total_segments=1):
434
  else:
435
  print(f"Google Images search failed for prompt: {prompt}")
436
 
437
- if random.random() < 0.50:
438
  video_file = os.path.join(TEMP_FOLDER, f"{safe_prompt}_video.mp4")
439
  video_url = search_pexels_videos(prompt, PEXELS_API_KEY)
440
  if video_url:
@@ -758,12 +773,37 @@ def fix_imagemagick_policy():
758
  print(f"Error fixing policies: {e}")
759
  return False
760
 
761
- # ---------------- Main Function with Gradio Integration ---------------- #
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
762
  def generate_video(user_input, resolution, caption_option):
763
  """Generate a video based on user input via Gradio."""
764
  global TARGET_RESOLUTION, CAPTION_COLOR, TEMP_FOLDER
765
- import shutil
766
-
767
  # Set resolution
768
  if resolution == "Full":
769
  TARGET_RESOLUTION = (1920, 1080)
@@ -852,21 +892,7 @@ def generate_video(user_input, resolution, caption_option):
852
 
853
  return OUTPUT_VIDEO_FILENAME
854
 
855
-
856
-
857
-
858
-
859
-
860
-
861
-
862
-
863
-
864
-
865
-
866
- import gradio as gr
867
- import shutil
868
- import os
869
-
870
  VOICE_CHOICES = {
871
  'Emma (Female)': 'af_heart',
872
  'Bella (Female)': 'af_bella',
@@ -898,28 +924,28 @@ VOICE_CHOICES = {
898
  'Daniel 🇬🇧 (Male)': 'bm_daniel'
899
  }
900
 
901
-
902
- def handle_music_upload(music_file):
 
 
 
 
 
 
 
 
 
 
 
903
  if music_file is not None:
904
  target_path = "music.mp3"
905
- shutil.copy(music_file, target_path)
906
  print(f"Uploaded music saved as: {target_path}")
907
-
908
- def generate_video_with_options(user_input, resolution, caption_option, music_file, voice, video_clip_probability, bg_music_volume, fps, preset, voice_speed, font_size):
909
- handle_music_upload(music_file)
910
-
911
- selected_voice = VOICE_CHOICES[voice]
912
- print(f"Selected Voice: {selected_voice}")
913
- print(f"Video Clip Probability: {video_clip_probability}%")
914
- print(f"Music Volume: {bg_music_volume}")
915
- print(f"FPS: {fps}")
916
- print(f"Preset: {preset}")
917
- print(f"Voice Speed: {voice_speed}")
918
- print(f"Caption Font Size: {font_size}")
919
-
920
- # Pass these to your video generator as needed
921
  return generate_video(user_input, resolution, caption_option)
922
 
 
923
  iface = gr.Interface(
924
  fn=generate_video_with_options,
925
  inputs=[
@@ -931,14 +957,16 @@ iface = gr.Interface(
931
  gr.Slider(0, 100, value=25, step=1, label="Video Clip Usage Probability (%)"),
932
  gr.Slider(0.0, 1.0, value=0.08, step=0.01, label="Background Music Volume"),
933
  gr.Slider(10, 60, value=30, step=1, label="Video FPS"),
934
- gr.Dropdown(choices=["ultrafast", "superfast", "veryfast", "faster", "fast", "medium", "slow"], value="veryfast", label="Export Preset"),
 
935
  gr.Slider(0.5, 1.5, value=0.9, step=0.05, label="Voice Speed"),
936
  gr.Slider(20, 100, value=45, step=1, label="Caption Font Size")
937
  ],
938
  outputs=gr.Video(label="Generated Video"),
939
  title="AI Documentary Video Generator",
940
- description="Upload music, choose voice, control video clips, volume, FPS, speed, captions."
941
  )
942
 
943
- iface.launch(share=True)
944
-
 
 
48
  OUTPUT_VIDEO_FILENAME = "final_video.mp4"
49
  USER_AGENT = "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/91.0.4472.124 Safari/537.36"
50
 
51
+
52
+
53
+ # Additional global variables needed for the Gradio interface
54
+ selected_voice = 'af_heart' # Default voice
55
+ voice_speed = 0.9 # Default voice speed
56
+ font_size = 45 # Default font size
57
+ video_clip_probability = 0.25 # Default probability for video clips
58
+ bg_music_volume = 0.08 # Default background music volume
59
+ fps = 30 # Default FPS
60
+ preset = "veryfast" # Default preset
61
+ TARGET_RESOLUTION = None
62
+ CAPTION_COLOR = None
63
+ TEMP_FOLDER = None
64
+
65
+
66
  # ---------------- Helper Functions ---------------- #
67
  # (Your existing helper functions remain unchanged: generate_script, parse_script,
68
  # search_pexels_videos, search_pexels_images, search_google_images, download_image,
 
449
  else:
450
  print(f"Google Images search failed for prompt: {prompt}")
451
 
452
+ if random.random() < video_clip_probability:
453
  video_file = os.path.join(TEMP_FOLDER, f"{safe_prompt}_video.mp4")
454
  video_url = search_pexels_videos(prompt, PEXELS_API_KEY)
455
  if video_url:
 
773
  print(f"Error fixing policies: {e}")
774
  return False
775
 
776
+
777
+
778
+
779
+
780
+
781
+
782
+
783
+
784
+
785
+
786
+
787
+
788
+
789
+
790
+
791
+
792
+
793
+
794
+
795
+
796
+
797
+
798
+
799
+
800
+
801
+
802
+ # ---------------- Main Video Generation Function ---------------- #
803
  def generate_video(user_input, resolution, caption_option):
804
  """Generate a video based on user input via Gradio."""
805
  global TARGET_RESOLUTION, CAPTION_COLOR, TEMP_FOLDER
806
+
 
807
  # Set resolution
808
  if resolution == "Full":
809
  TARGET_RESOLUTION = (1920, 1080)
 
892
 
893
  return OUTPUT_VIDEO_FILENAME
894
 
895
+ # ---------------- Gradio Interface ---------------- #
 
 
 
 
 
 
 
 
 
 
 
 
 
 
896
  VOICE_CHOICES = {
897
  'Emma (Female)': 'af_heart',
898
  'Bella (Female)': 'af_bella',
 
924
  'Daniel 🇬🇧 (Male)': 'bm_daniel'
925
  }
926
 
927
+ def generate_video_with_options(user_input, resolution, caption_option, music_file, voice, vclip_prob, bg_vol, video_fps, video_preset, v_speed, caption_size):
928
+ global selected_voice, voice_speed, font_size, video_clip_probability, bg_music_volume, fps, preset
929
+
930
+ # Update global variables with user selections
931
+ selected_voice = VOICE_CHOICES[voice]
932
+ voice_speed = v_speed
933
+ font_size = caption_size
934
+ video_clip_probability = vclip_prob / 100 # Convert from percentage to decimal
935
+ bg_music_volume = bg_vol
936
+ fps = video_fps
937
+ preset = video_preset
938
+
939
+ # Handle music upload
940
  if music_file is not None:
941
  target_path = "music.mp3"
942
+ shutil.copy(music_file.name, target_path)
943
  print(f"Uploaded music saved as: {target_path}")
944
+
945
+ # Generate the video
 
 
 
 
 
 
 
 
 
 
 
 
946
  return generate_video(user_input, resolution, caption_option)
947
 
948
+ # Create the Gradio interface
949
  iface = gr.Interface(
950
  fn=generate_video_with_options,
951
  inputs=[
 
957
  gr.Slider(0, 100, value=25, step=1, label="Video Clip Usage Probability (%)"),
958
  gr.Slider(0.0, 1.0, value=0.08, step=0.01, label="Background Music Volume"),
959
  gr.Slider(10, 60, value=30, step=1, label="Video FPS"),
960
+ gr.Dropdown(choices=["ultrafast", "superfast", "veryfast", "faster", "fast", "medium", "slow"],
961
+ value="veryfast", label="Export Preset"),
962
  gr.Slider(0.5, 1.5, value=0.9, step=0.05, label="Voice Speed"),
963
  gr.Slider(20, 100, value=45, step=1, label="Caption Font Size")
964
  ],
965
  outputs=gr.Video(label="Generated Video"),
966
  title="AI Documentary Video Generator",
967
+ description="Create short documentary videos with AI. Upload music, choose voice, and customize settings."
968
  )
969
 
970
+ # Launch the interface
971
+ if __name__ == "__main__":
972
+ iface.launch(share=True)