Spaces:
Runtime error
Runtime error
import os | |
import pathlib | |
import random | |
import shlex | |
import subprocess | |
import gradio as gr | |
from gradio import inputs, outputs | |
import torch | |
from huggingface_hub import snapshot_download | |
from modelscope.pipelines import pipeline | |
from modelscope.outputs import OutputKeys | |
import boto3 | |
from botocore.client import Config | |
import gradio as gr | |
# Downloading and setting up the model | |
model_dir = pathlib.Path('weights') | |
if not model_dir.exists(): | |
model_dir.mkdir() | |
snapshot_download('damo-vilab/modelscope-damo-text-to-video-synthesis', | |
repo_type='model', | |
local_dir=model_dir) | |
s3_access_key = "juj22qxqxql7u2pl6nomgxu3ip7a" | |
s3_secret_key = "j3uwidtozhboy5vczhymhzkkjsaumznnqlzck5zjs5qxgsung4ukk" | |
s3_endpoint = "https://gateway.storjshare.io" | |
s3 = boto3.client("s3", aws_access_key_id=s3_access_key, aws_secret_access_key=s3_secret_key, endpoint_url=s3_endpoint, config=Config(signature_version="s3v4")) | |
# Function to generate video and upload it to Storj | |
def generate_video(prompt: str, seed: int) -> str: | |
if seed == -1: | |
seed = random.randint(0, 1000000) | |
torch.manual_seed(seed) | |
result = pipe({'text': prompt})[OutputKeys.OUTPUT_VIDEO] | |
# Upload video to Storj | |
bucket_name = "huggingface-demo" | |
# Add the code to upload the video to the Storj bucket | |
# and return the URL of the uploaded video | |
return result | |
# Gradio Interface | |
examples = [ | |
['An astronaut riding a horse.', 0], | |
['A panda eating bamboo on a rock.', 0], | |
['Spiderman is surfing.', 0], | |
] | |
# Import Storj Theme from the hub | |
storj_theme = gr.Theme.from_hub("bethecloud/storj_theme") | |
inputs = [ | |
gr.inputs.Textbox(lines=1, placeholder="Enter your text here..."), | |
gr.inputs.Slider(minimum=-1, maximum=1000000, step=1, default=-1, label="Seed") | |
] | |
iface = gr.Interface( | |
fn=generate_video, | |
inputs=inputs, | |
outputs=gr.outputs.Video(), | |
theme=storj_theme, | |
allow_flagging=False, | |
examples=examples | |
) | |
## Run app | |
iface.launch(share=True, debug=True) |