Spaces:
Runtime error
Runtime error
bethecloud
commited on
Commit
•
06945c0
1
Parent(s):
8b66d41
Update app.py
Browse filesUpdated to new version
app.py
CHANGED
@@ -1,69 +1,72 @@
|
|
1 |
import os
|
2 |
-
import pathlib
|
3 |
-
import random
|
4 |
-
import shlex
|
5 |
-
import subprocess
|
6 |
import gradio as gr
|
7 |
-
from gradio import inputs, outputs
|
8 |
-
import torch
|
9 |
-
from huggingface_hub import snapshot_download
|
10 |
from modelscope.pipelines import pipeline
|
11 |
from modelscope.outputs import OutputKeys
|
|
|
|
|
12 |
import boto3
|
13 |
-
from botocore.
|
14 |
-
import gradio as gr
|
15 |
-
|
16 |
-
# Downloading and setting up the model
|
17 |
-
model_dir = pathlib.Path('weights')
|
18 |
-
if not model_dir.exists():
|
19 |
-
model_dir.mkdir()
|
20 |
-
snapshot_download('damo-vilab/modelscope-damo-text-to-video-synthesis',
|
21 |
-
repo_type='model',
|
22 |
-
local_dir=model_dir)
|
23 |
|
|
|
24 |
s3_access_key = "juj22qxqxql7u2pl6nomgxu3ip7a"
|
25 |
s3_secret_key = "j3uwidtozhboy5vczhymhzkkjsaumznnqlzck5zjs5qxgsung4ukk"
|
26 |
s3_endpoint = "https://gateway.storjshare.io"
|
27 |
|
28 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
29 |
|
30 |
-
|
31 |
-
|
32 |
-
|
33 |
-
|
34 |
-
|
35 |
-
|
|
|
|
|
36 |
|
37 |
-
#
|
38 |
-
|
39 |
-
|
40 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
41 |
|
42 |
-
|
|
|
|
|
43 |
|
44 |
-
|
45 |
-
|
46 |
-
|
47 |
-
|
48 |
-
['Spiderman is surfing.', 0],
|
49 |
-
]
|
50 |
|
51 |
-
|
52 |
-
storj_theme = gr.Theme.from_hub("bethecloud/storj_theme")
|
53 |
|
54 |
-
|
55 |
-
gr.inputs.Textbox(lines=1, placeholder="Enter your text here..."),
|
56 |
-
gr.inputs.Slider(minimum=-1, maximum=1000000, step=1, default=-1, label="Seed")
|
57 |
-
]
|
58 |
|
59 |
iface = gr.Interface(
|
60 |
fn=generate_video,
|
61 |
-
inputs=
|
62 |
-
|
63 |
-
|
64 |
-
|
65 |
-
|
|
|
|
|
|
|
|
|
|
|
66 |
)
|
67 |
|
68 |
-
## Run app
|
69 |
iface.launch(share=True, debug=True)
|
|
|
1 |
import os
|
|
|
|
|
|
|
|
|
2 |
import gradio as gr
|
|
|
|
|
|
|
3 |
from modelscope.pipelines import pipeline
|
4 |
from modelscope.outputs import OutputKeys
|
5 |
+
import requests
|
6 |
+
import tempfile
|
7 |
import boto3
|
8 |
+
from botocore.exceptions import NoCredentialsError
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
9 |
|
10 |
+
# Hardcoded S3 keys
|
11 |
s3_access_key = "juj22qxqxql7u2pl6nomgxu3ip7a"
|
12 |
s3_secret_key = "j3uwidtozhboy5vczhymhzkkjsaumznnqlzck5zjs5qxgsung4ukk"
|
13 |
s3_endpoint = "https://gateway.storjshare.io"
|
14 |
|
15 |
+
# Initialize Storj with boto3
|
16 |
+
s3 = boto3.client(
|
17 |
+
"s3",
|
18 |
+
endpoint_url=s3_endpoint,
|
19 |
+
aws_access_key_id=s3_access_key,
|
20 |
+
aws_secret_access_key=s3_secret_key,
|
21 |
+
)
|
22 |
+
|
23 |
+
p = pipeline("text-to-video-synthesis", "damo/text-to-video-synthesis")
|
24 |
|
25 |
+
async def generate_video(text_input: str, duration: int) -> (str, str):
|
26 |
+
test_text = {'text': text_input, 'duration': duration}
|
27 |
+
output_video_path = p(test_text,)[OutputKeys.OUTPUT_VIDEO]
|
28 |
+
|
29 |
+
# Upload to Storj
|
30 |
+
with open(output_video_path, "rb") as f:
|
31 |
+
video_key = os.path.basename(output_video_path)
|
32 |
+
s3.upload_fileobj(f, "huggingface-demo", video_key)
|
33 |
|
34 |
+
# Generate signed URL for uploaded video
|
35 |
+
try:
|
36 |
+
storj_video_url = s3.generate_presigned_url(
|
37 |
+
"get_object",
|
38 |
+
Params={"Bucket": "huggingface-demo", "Key": video_key},
|
39 |
+
ExpiresIn=3600,
|
40 |
+
)
|
41 |
+
except NoCredentialsError:
|
42 |
+
print("Credentials not available")
|
43 |
+
return None
|
44 |
|
45 |
+
# Download the video from Storj to a temporary file
|
46 |
+
response = requests.get(storj_video_url, stream=True)
|
47 |
+
response.raise_for_status()
|
48 |
|
49 |
+
with tempfile.NamedTemporaryFile(delete=False, suffix=".mp4") as temp_file:
|
50 |
+
for chunk in response.iter_content(chunk_size=8192):
|
51 |
+
temp_file.write(chunk)
|
52 |
+
local_video_path = temp_file.name
|
|
|
|
|
53 |
|
54 |
+
return local_video_path, storj_video_url
|
|
|
55 |
|
56 |
+
storj_theme = gr.Theme.from_hub("bethecloud/storj_theme")
|
|
|
|
|
|
|
57 |
|
58 |
iface = gr.Interface(
|
59 |
fn=generate_video,
|
60 |
+
inputs=[
|
61 |
+
gr.inputs.Textbox(lines=3, label="Input text"),
|
62 |
+
gr.inputs.Slider(minimum=1, maximum=60, step=1, default=5, label="Duration (seconds)")
|
63 |
+
],
|
64 |
+
outputs=[
|
65 |
+
gr.outputs.Video(label="Generated Video"),
|
66 |
+
gr.outputs.Textbox(label="Storj Video URL")
|
67 |
+
],
|
68 |
+
title="Text to Video to Storj",
|
69 |
+
theme=storj_theme
|
70 |
)
|
71 |
|
|
|
72 |
iface.launch(share=True, debug=True)
|