Spaces:
Running
Running
File size: 11,542 Bytes
ea6481e b83e916 ea6481e b83e916 ea6481e b83e916 ea6481e b83e916 ea6481e b83e916 ea6481e b83e916 ea6481e b83e916 ea6481e b83e916 ea6481e b83e916 ea6481e b83e916 ea6481e b83e916 ea6481e b83e916 ea6481e b83e916 ea6481e b83e916 ea6481e b83e916 ea6481e b83e916 ea6481e b83e916 ea6481e b83e916 ea6481e 2f633d1 e105b0c ea6481e 2f633d1 ea6481e b83e916 ea6481e b83e916 ea6481e b83e916 ea6481e 71a6f05 |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 |
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"):
@gr.render(inputs=[generation_history, list_size])
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) |