File size: 16,124 Bytes
ea6481e
 
 
 
 
 
 
 
 
 
 
da28342
ea6481e
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
6c4f918
ea6481e
 
 
8f9aa68
3db7913
 
 
bc05981
b8c8933
9a1177d
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
9090ba7
5ca822f
76bd1a4
 
2923dad
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
f2bceec
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
ea6481e
 
 
 
ae8545d
ea6481e
da28342
ea6481e
 
 
 
 
66a9010
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
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
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

PAGE_SIZE = 5
FILE_DIR_PATH = "."

repo_id = os.environ["DATASET"]

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'])
        
        # 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()):
    url = 'https://sora.openai.com/backend/video_gen?force_paragen=false'
    
    headers = json.loads(os.environ["HEADERS"])

    cookies = json.loads(os.environ["COOKIES"])
    if size == "1080p":
        width = 1920
        height = 1080
    elif size == "720p":
        width = 1280
        height = 720
    elif size == "480p":
        width = 854
        height = 480
    elif size == "360p":
        width = 640
        height = 360
    payload = {
        "type": "video_gen",
        "prompt": prompt,
        "n_variants": 1,
        "n_frames": 30 * duration,
        "height": height,
        "width": width,
        "style": "natural",
        "inpaint_items": [],
        "model": "turbo",
        "operation": "simple_compose"
    }
    
    # Initial request to generate video
    response = requests.post(url, headers=headers, cookies=cookies, json=payload)
    
    if response.status_code != 200:
        raise gr.Error("Something went wrong")
    
    task_id = response.json()["id"]
    gr.Info("Video generation started. Please wait...")

    # Check status URL
    status_url = 'https://sora.openai.com/backend/video_gen?limit=10'
    
    # Poll for completion
    max_attempts = 60  # Maximum number of attempts
    attempt = 0
    
    while attempt < max_attempts:
        try:
            status_response = requests.get(status_url, headers=headers, cookies=cookies)
            if status_response.status_code == 200:
                list_responses = status_response.json()
                
                for task_response in list_responses["task_responses"]:
                    if task_response["id"] == task_id:
                        print(task_response)
                        if "progress_pct" in task_response:
                            if(task_response["progress_pct"]):
                                progress(task_response["progress_pct"])
                        if "failure_reason" in task_response:
                            if(task_response["failure_reason"]):
                                raise gr.Error(f"Your generation errored due to: {task_response['failure_reason']}")
                        if "moderation_result" in task_response:
                            if(task_response["moderation_result"]):
                                if "is_output_rejection" in task_response["moderation_result"]:
                                    if(task_response["moderation_result"]["is_output_rejection"]):
                                        raise gr.Error(f"Your generation got blocked by OpenAI")
                        if "generations" in task_response:
                            if(task_response["generations"]):
                                print("Generation suceeded")
                                video_url = task_response["generations"][0]["url"]
                                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"
                                video_path, prompt_path = download_video(video_url, prompt, unique_textfile, unique_filename)
                                generation_history = generation_history + ',' + unique_filename
                                append_videos_to_dataset([video_url], [video_path], [prompt])
                                if "actions" in task_response:
                                    if(task_response["actions"]):
                                        generated_prompt = json.dumps(task_response["actions"], sort_keys=True, indent=4)
                                    else:
                                        generated_prompt = None                                        
                                print(generated_prompt)
                                return video_path, generation_history, generated_prompt
            else:
                print(status_response.text)

            time.sleep(5)  # Wait 10 seconds before next attempt
            attempt += 1    
            
        except Exception as e:
            raise gr.Error(f"Error checking status: {str(e)}")
    gr.Error("Timeout: Video generation took too long. Please try again.")

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

def download_video(url, prompt, save_path_text, save_path_video):
    try:
        # Send a GET request to the URL
        print("Starting download...")
        response = requests.get(url, stream=True)
        response.raise_for_status()
        
        with open(save_path_text, "w") as file:
            file.write(prompt)

        # Open the file in binary write mode
        with open(save_path_video, 'wb') as video_file:
            # Write the content to the file with progress updates
            for chunk in response.iter_content(chunk_size=2 * 1024 * 1024):
                if chunk:
                    video_file.write(chunk)
        
    except requests.exceptions.RequestException as e:
        print(f"Error downloading the video: {e}")
    except IOError as e:
        print(f"Error saving the file: {e}")
    return save_path_video, save_path_text
css = '''
p, li{font-size: 16px}
code{font-size: 18px}
#component-4{opacity: 0.5; pointer-events: none}
'''
# Create Gradio interface
with gr.Blocks(css=css) as demo:
    gr.Markdown("# After 3 hours, OpenAI shut down Sora's early access temporarily for all artists.")
    with gr.Tab("Open letter: why are we doing this?"):
        gr.Markdown('''# ┌∩┐(◣_◢)┌∩┐ DEAR CORPORATE AI OVERLORDS ┌∩┐(◣_◢)┌∩┐

If this letter resonates with you add your signature [here](https://openletter.earth/dear-corporate-ai-overlords-90668a95).

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 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, [Jake Elwes](https://www.jakeelwes.com/), [Memo Akten](https://www.memo.tv/), [CROSSLUCID](https://crosslucid.zone/), [Maribeth Rauh](https://uk.linkedin.com/in/maribethrauh), [Joel Simon](https://www.joelsimon.net/), [Jake Hartnell](https://x.com/JakeHartnell), [Bea Ramos, Power Dada](https://x.com/powerdada), [aurèce vettier](https://www.aurecevettier.com/), [acfp](https://www.andreachiampo.com/), [Iannis Bardakos](http://www.johnbardakos.com/), [204 no-content | Cintia Aguiar Pinto & Dimitri De Jonghe](https://204.ai), [Emmanuelle Collet](https://www.linkedin.com/in/emmanuelle-collet), [XU Cheng](https://floating.pt/), [Operator](https://x.com/operator_______), [Katie Peyton Hofstadter](https://katiepeyton.com/), [Anika Meier](https://anikameierstatusupdate.substack.com/), [Solimán López](https://solimanlopez.com/)

If this letter resonates with you add your signature [here](https://openletter.earth/dear-corporate-ai-overlords-90668a95).

''', elem_id="manifesto")
    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", open=True):
            gr.Markdown("Videos generated while the tool was up")
            @gr.render(inputs=[generation_history, list_size])
            def show_output_list(generation_history, list_size):
                metadata_path = hf_hub_download(
                    repo_id=repo_id,
                    filename=f"train/metadata.csv",
                    repo_type="dataset"
                )
                existing_metadata = pd.read_csv(metadata_path)
                print(existing_metadata)
                for index, generation_list in existing_metadata.iloc[-list_size:][::-1].iterrows():
                    print(generation_list)
                    generation_prompt = generation_list['prompt']
                    generation = generation_list['original_url']                    
                #history_list = generation_history.split(',') if generation_history else []
                #history_list_latest = history_list[:list_size]
                #for generation in history_list_latest:
                #    generation_prompt_file = generation.replace('.mp4', '.txt')
                #    with open(generation_prompt_file, 'r') as file:
                #        generation_prompt = file.read()
                    with gr.Group():
                        gr.Markdown(value=f"### {generation_prompt}")
                        gr.HTML(f'''
                        <video controls width="100%">
                          <source src="{generation}" type="video/mp4" />
                        </video>
                        ''')
            load_more = gr.Button("Load more")
            load_more.click(fn=increase_list_size, inputs=list_size, outputs=list_size)    
    generate_button.click(
        fn=generate_video,
        inputs=[prompt_input, size, duration, generation_history],
        outputs=[output, generation_history, generated_prompt],
        concurrency_limit=1
    )
    timer = gr.Timer(value=30)
    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=True)