concurnecy
Browse files
app.py
CHANGED
|
@@ -1,9 +1,10 @@
|
|
|
|
|
| 1 |
import gradio as gr
|
| 2 |
import os
|
| 3 |
from pathlib import Path
|
| 4 |
import tempfile
|
| 5 |
|
| 6 |
-
from sympy import true
|
| 7 |
from extract_metadata import get_metadata
|
| 8 |
from find_steps import find_all_steps
|
| 9 |
from video_editing import crop_video, get_final_video
|
|
@@ -11,6 +12,16 @@ import json
|
|
| 11 |
from video_editing_ffmpeg import concatenate_videos
|
| 12 |
|
| 13 |
from grok_analyze import get_story_with_grok
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 14 |
# Placeholder function for video generation
|
| 15 |
def generate_video(metadata, filenames,current_context):
|
| 16 |
"""
|
|
@@ -58,15 +69,28 @@ def upload_files(uploaded_files):
|
|
| 58 |
metadata_file=file.name
|
| 59 |
|
| 60 |
if metadata_file=="":
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 61 |
metadata, filename = get_metadata(uploaded_files)
|
| 62 |
-
else:
|
| 63 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 64 |
with open(metadata_file, 'r') as file:
|
| 65 |
metadata = json.load(file)
|
| 66 |
return metadata, metadata_file, "Files uploaded successfully."
|
| 67 |
|
|
|
|
|
|
|
| 68 |
print("Uploaded files:", filename)
|
| 69 |
print("Metadata:", metadata)
|
|
|
|
| 70 |
|
| 71 |
return metadata, filename, "Files uploaded successfully."
|
| 72 |
|
|
@@ -78,6 +102,7 @@ with gr.Blocks() as demo:
|
|
| 78 |
with gr.Column():
|
| 79 |
file_input = gr.File(label="Upload Images, Videos or metadata", file_count="multiple", file_types=["image", "video",'.json'])
|
| 80 |
upload_button = gr.Button("Upload Files (video, image, metadata)")
|
|
|
|
| 81 |
generate_button = gr.Button("Generate Story!")
|
| 82 |
context = gr.Textbox(label="Context")
|
| 83 |
generated_story = gr.Textbox(label="Generated Story")
|
|
@@ -106,4 +131,6 @@ with gr.Blocks() as demo:
|
|
| 106 |
)
|
| 107 |
|
| 108 |
# Launch the app (Pyodide-compatible launch)
|
| 109 |
-
demo.launch(share=true)
|
|
|
|
|
|
|
|
|
| 1 |
+
from dotenv import load_dotenv
|
| 2 |
import gradio as gr
|
| 3 |
import os
|
| 4 |
from pathlib import Path
|
| 5 |
import tempfile
|
| 6 |
|
| 7 |
+
from sympy import true
|
| 8 |
from extract_metadata import get_metadata
|
| 9 |
from find_steps import find_all_steps
|
| 10 |
from video_editing import crop_video, get_final_video
|
|
|
|
| 12 |
from video_editing_ffmpeg import concatenate_videos
|
| 13 |
|
| 14 |
from grok_analyze import get_story_with_grok
|
| 15 |
+
|
| 16 |
+
from concurrent.futures import ThreadPoolExecutor
|
| 17 |
+
import random
|
| 18 |
+
import string
|
| 19 |
+
|
| 20 |
+
from experiments.upload_to_s3 import upload_multiple_files
|
| 21 |
+
load_dotenv()
|
| 22 |
+
|
| 23 |
+
# Access the variables
|
| 24 |
+
bucket = os.getenv("BUCKET")
|
| 25 |
# Placeholder function for video generation
|
| 26 |
def generate_video(metadata, filenames,current_context):
|
| 27 |
"""
|
|
|
|
| 69 |
metadata_file=file.name
|
| 70 |
|
| 71 |
if metadata_file=="":
|
| 72 |
+
random_string = 'a'.join(random.choices(string.ascii_lowercase + string.digits, k=8))
|
| 73 |
+
|
| 74 |
+
tuple_list = [(path,random_string+"/"+os.path.splitext(os.path.basename(path))[0]) for path in uploaded_files]
|
| 75 |
+
|
| 76 |
+
print(tuple_list)
|
| 77 |
metadata, filename = get_metadata(uploaded_files)
|
|
|
|
| 78 |
|
| 79 |
+
# with ThreadPoolExecutor() as executor:
|
| 80 |
+
# future = executor.submit(upload_multiple_files,tuple_list,bucket)
|
| 81 |
+
|
| 82 |
+
executor = ThreadPoolExecutor(max_workers=1) # Adjust max_workers as needed
|
| 83 |
+
future = executor.submit(upload_multiple_files, tuple_list, bucket)
|
| 84 |
+
else:
|
| 85 |
with open(metadata_file, 'r') as file:
|
| 86 |
metadata = json.load(file)
|
| 87 |
return metadata, metadata_file, "Files uploaded successfully."
|
| 88 |
|
| 89 |
+
|
| 90 |
+
|
| 91 |
print("Uploaded files:", filename)
|
| 92 |
print("Metadata:", metadata)
|
| 93 |
+
|
| 94 |
|
| 95 |
return metadata, filename, "Files uploaded successfully."
|
| 96 |
|
|
|
|
| 102 |
with gr.Column():
|
| 103 |
file_input = gr.File(label="Upload Images, Videos or metadata", file_count="multiple", file_types=["image", "video",'.json'])
|
| 104 |
upload_button = gr.Button("Upload Files (video, image, metadata)")
|
| 105 |
+
# get_metadata = gr.Button("Generate Metadata")
|
| 106 |
generate_button = gr.Button("Generate Story!")
|
| 107 |
context = gr.Textbox(label="Context")
|
| 108 |
generated_story = gr.Textbox(label="Generated Story")
|
|
|
|
| 131 |
)
|
| 132 |
|
| 133 |
# Launch the app (Pyodide-compatible launch)
|
| 134 |
+
# demo.launch(share=true)
|
| 135 |
+
|
| 136 |
+
demo.launch()
|