Spaces:
Running
Running
import gradio as gr | |
import requests | |
import time | |
import uuid | |
import os | |
from huggingface_hub import HfApi, hf_hub_download | |
import pandas as pd | |
import shutil | |
import json | |
from pathlib import Path | |
# Hugging Face Dataset Configuration | |
REPO_ID = "your-huggingface-username/sora-video-dataset" # REPLACE WITH YOUR ACTUAL HUGGING FACE DATASET REPO | |
PAGE_SIZE = 10 | |
FILE_DIR_PATH = "." | |
def append_videos_to_dataset( | |
video_urls, | |
video_paths, | |
prompts=None, | |
split="train", | |
commit_message="Added new videos" | |
): | |
api = HfApi() | |
temp_dir = Path("temp_dataset_folder") | |
split_dir = temp_dir / split | |
split_dir.mkdir(parents=True, exist_ok=True) | |
try: | |
# Download existing metadata if it exists | |
try: | |
metadata_path = hf_hub_download( | |
repo_id=REPO_ID, | |
filename=f"{split}/metadata.csv", | |
repo_type="dataset" | |
) | |
existing_metadata = pd.read_csv(metadata_path) | |
if 'prompt' not in existing_metadata.columns: | |
existing_metadata['prompt'] = '' | |
except: | |
existing_metadata = pd.DataFrame(columns=['file_name', 'prompt', 'original_url']) | |
# Prepare new metadata entries | |
new_entries = [] | |
for i, video_path in enumerate(video_paths): | |
video_name = Path(video_path).name | |
# Copy video to temporary directory | |
shutil.copy2(video_path, split_dir / video_name) | |
# Add metadata entry with prompt | |
new_entries.append({ | |
'file_name': video_name, | |
'prompt': prompts[i] if prompts else '', | |
'original_url': video_urls[i] if video_urls else '' | |
}) | |
# Combine existing and new metadata | |
new_metadata = pd.concat([ | |
existing_metadata, | |
pd.DataFrame(new_entries) | |
]).drop_duplicates(subset=['file_name'], keep='last') | |
# Ensure no NaN values in prompts | |
new_metadata['prompt'] = new_metadata['prompt'].fillna('') | |
# Save updated metadata | |
new_metadata.to_csv(split_dir / 'metadata.csv', index=False) | |
# Upload to Hugging Face Hub | |
api.upload_folder( | |
folder_path=str(temp_dir), | |
repo_id=REPO_ID, | |
repo_type="dataset", | |
commit_message=commit_message | |
) | |
finally: | |
# Clean up temporary directory | |
if temp_dir.exists(): | |
shutil.rmtree(temp_dir) | |
def generate_video(prompt, size, duration, generation_history, progress=gr.Progress()): | |
# Simulated Sora API call - you'll need to replace with actual API details | |
url = 'https://example.com/video_generation' | |
# Placeholder headers and cookies - replace with actual authentication | |
headers = { | |
"Authorization": "Bearer your_token_here", | |
"Content-Type": "application/json" | |
} | |
# Resolution mapping | |
resolution_map = { | |
"1080p": (1920, 1080), | |
"720p": (1280, 720), | |
"480p": (854, 480), | |
"360p": (640, 360) | |
} | |
width, height = resolution_map.get(size, (640, 360)) | |
payload = { | |
"prompt": prompt, | |
"width": width, | |
"height": height, | |
"duration": duration | |
} | |
try: | |
# Simulated video generation | |
random_uuid = uuid.uuid4().hex | |
unique_filename = f"{FILE_DIR_PATH}/output_{random_uuid}.mp4" | |
unique_textfile = f"{FILE_DIR_PATH}/output_{random_uuid}.txt" | |
# In a real scenario, you'd make an actual API call here | |
# For demonstration, we'll create a placeholder video | |
with open(unique_filename, 'wb') as f: | |
f.write(b'placeholder_video_content') | |
with open(unique_textfile, 'w') as f: | |
f.write(prompt) | |
# Append to dataset | |
append_videos_to_dataset( | |
video_urls=['https://example.com/placeholder_video'], | |
video_paths=[unique_filename], | |
prompts=[prompt] | |
) | |
generation_history = generation_history + ',' + unique_filename if generation_history else unique_filename | |
return unique_filename, generation_history, json.dumps(payload, indent=2) | |
except Exception as e: | |
raise gr.Error(f"Video generation error: {str(e)}") | |
def list_all_outputs(generation_history): | |
directory_path = FILE_DIR_PATH | |
files_in_directory = os.listdir(directory_path) | |
wav_files = [os.path.join(directory_path, file) for file in files_in_directory if file.endswith('.mp4')] | |
wav_files.sort(key=lambda x: os.path.getmtime(os.path.join(directory_path, x)), reverse=True) | |
history_list = generation_history.split(',') if generation_history else [] | |
updated_files = [file for file in wav_files if file not in history_list] | |
updated_history = updated_files + history_list | |
return ','.join(updated_history) | |
def increase_list_size(list_size): | |
return list_size + PAGE_SIZE | |
# Rest of the Gradio interface code remains the same as in the original script | |
css = ''' | |
p, li{font-size: 16px} | |
code{font-size: 18px} | |
''' | |
# Create Gradio interface | |
with gr.Blocks(css=css) as demo: | |
with gr.Tab("Generate with Sora"): | |
gr.Markdown("# Sora PR Puppets") | |
gr.Markdown("An artists open letter, click on the 'Why are we doing this' tab to learn more") | |
generation_history = gr.Textbox(visible=False) | |
list_size = gr.Number(value=PAGE_SIZE, visible=False) | |
with gr.Row(): | |
with gr.Column(): | |
prompt_input = gr.Textbox( | |
label="Enter your prompt", | |
placeholder="Describe the video you want to generate...", | |
lines=3 | |
) | |
generate_button = gr.Button("Generate Video") | |
with gr.Column(): | |
output = gr.Video(label="Generated Video") | |
generated_prompt = gr.Code(label="Generated prompt", interactive=False, language="json", wrap_lines=True, lines=1) | |
with gr.Accordion("Advanced Options", open=True): | |
size = gr.Radio(["360p", "480p", "720p", "1080p"], label="Resolution", value="360p", info="Trade off between resolution and speed") | |
duration = gr.Slider(minimum=5, maximum=10, step=5, label="Duration", value=10) | |
with gr.Accordion("Generation gallery"): | |
def show_output_list(generation_history, list_size): | |
try: | |
metadata_path = hf_hub_download( | |
repo_id=REPO_ID, | |
filename=f"train/metadata.csv", | |
repo_type="dataset" | |
) | |
existing_metadata = pd.read_csv(metadata_path) | |
for index, generation_list in existing_metadata.iloc[-list_size:][::-1].iterrows(): | |
generation_prompt = generation_list['prompt'] | |
generation = generation_list['original_url'] | |
with gr.Group(): | |
gr.Markdown(value=f"### {generation_prompt}") | |
gr.HTML(f''' | |
<video controls width="100%"> | |
<source src="{generation}" type="video/mp4" /> | |
</video> | |
''') | |
except Exception as e: | |
gr.Markdown(f"Error loading gallery: {str(e)}") | |
load_more = gr.Button("Load more") | |
load_more.click(fn=increase_list_size, inputs=list_size, outputs=list_size) | |
with gr.Tab("Open letter: why are we doing this?"): | |
gr.Markdown('''# ββ©β(β£_β’)ββ©β DEAR CORPORATE AI OVERLORDS ββ©β(β£_β’)ββ©β | |
We received access to Sora with the promise to be early testers, red teamers and creative partners. However, we believe instead we are being lured into "art washing" to tell the world that Sora is a useful tool for artists. | |
<code style="font-family: monospace;font-size: 16px;font-weight:bold">ARTISTS ARE NOT YOUR UNPAID R&D <br /> | |
β οΈ we are not your: free bug testers, PR puppets, training data, validation tokens β οΈ </code> | |
Hundreds of artists provide unpaid labor through bug testing, feedback and experimental work for the program for a $150B valued company. While hundreds contribute for free, a select few will be chosen through a competition to have their Sora-created films screened β offering minimal compensation which pales in comparison to the substantial PR and marketing value OpenAI receives. | |
<code style="font-family: monospace;font-size: 16px;font-weight:bold">ββββββββββ DENORMALIZE BILLION DOLLAR BRANDS EXPLOITING ARTISTS FOR UNPAID R&D AND PR ββββββββββ </code> | |
Furthermore, every output needs to be approved by the OpenAI team before sharing. This early access program appears to be less about creative expression and critique, and more about PR and advertisement. | |
<code style="font-family: monospace;font-size: 16px;font-weight:bold">[Μ²Μ $Μ²Μ (Μ²Μ )Μ²Μ $Μ²Μ ] CORPORATE ARTWASHING DETECTED [Μ²Μ $Μ²Μ (Μ²Μ )Μ²Μ $Μ²Μ ]</code> | |
We are releasing this tool to give everyone an opportunity to experiment with what ~300 artists were offered: a free and unlimited access to this tool. | |
We are not against the use of AI technology as a tool for the arts (if we were, we probably wouldn't have been invited to this program). What we don't agree with is how this artist program has been rolled out and how the tool is shaping up ahead of a possible public release. We are sharing this to the world in the hopes that OpenAI becomes more open, more artist friendly and supports the arts beyond PR stunts. | |
### We call on artists to make use of tools beyond the proprietary: | |
Open Source video generation tools allow artists to experiment with the avant garde free from gate keeping, commercial interests or serving as PR to any corporation. We also invite artists to train their own models with their own datasets. | |
Some open source video generation tools allow artists to experiment with avant garde tools without gate keeping, commercial interests or serving as a PR to any corporation. Some open source video tools available are: | |
- [CogVideoX](https://huggingface.co/collections/THUDM/cogvideo-66c08e62f1685a3ade464cce) | |
- [Mochi 1](https://huggingface.co/genmo/mochi-1-preview) | |
- [LTX Video](https://huggingface.co/Lightricks/LTX-Video) | |
- [Pyramid Flow](https://huggingface.co/rain1011/pyramid-flow-miniflux) | |
However, as we are aware not everyone has the hardware or technical capability to run open source tools and models, we welcome tool makers to listen to and provide a path to true artist expression, with fair compensation to the artists. | |
Enjoy, | |
some sora-alpha-artists | |
''', elem_id="manifesto") | |
generate_button.click( | |
fn=generate_video, | |
inputs=[prompt_input, size, duration, generation_history], | |
outputs=[output, generation_history, generated_prompt], | |
concurrency_limit=4 | |
) | |
timer = gr.Timer(value=2) | |
timer.tick(fn=list_all_outputs, inputs=[generation_history], outputs=[generation_history]) | |
demo.load(fn=list_all_outputs, inputs=[generation_history], outputs=[generation_history]) | |
# Launch the app | |
if __name__ == "__main__": | |
demo.launch(ssr_mode=False) |