Spaces:
Runtime error
Runtime error
File size: 2,033 Bytes
aa6df5a |
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 |
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) |