Spaces:
Runtime error
Runtime error
Commit
·
aa6df5a
1
Parent(s):
acab9d9
Create app.py
Browse files
app.py
ADDED
|
@@ -0,0 +1,69 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 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.client import Config
|
| 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 |
+
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"))
|
| 29 |
+
|
| 30 |
+
# Function to generate video and upload it to Storj
|
| 31 |
+
def generate_video(prompt: str, seed: int) -> str:
|
| 32 |
+
if seed == -1:
|
| 33 |
+
seed = random.randint(0, 1000000)
|
| 34 |
+
torch.manual_seed(seed)
|
| 35 |
+
result = pipe({'text': prompt})[OutputKeys.OUTPUT_VIDEO]
|
| 36 |
+
|
| 37 |
+
# Upload video to Storj
|
| 38 |
+
bucket_name = "huggingface-demo"
|
| 39 |
+
# Add the code to upload the video to the Storj bucket
|
| 40 |
+
# and return the URL of the uploaded video
|
| 41 |
+
|
| 42 |
+
return result
|
| 43 |
+
|
| 44 |
+
# Gradio Interface
|
| 45 |
+
examples = [
|
| 46 |
+
['An astronaut riding a horse.', 0],
|
| 47 |
+
['A panda eating bamboo on a rock.', 0],
|
| 48 |
+
['Spiderman is surfing.', 0],
|
| 49 |
+
]
|
| 50 |
+
|
| 51 |
+
# Import Storj Theme from the hub
|
| 52 |
+
storj_theme = gr.Theme.from_hub("bethecloud/storj_theme")
|
| 53 |
+
|
| 54 |
+
inputs = [
|
| 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=inputs,
|
| 62 |
+
outputs=gr.outputs.Video(),
|
| 63 |
+
theme=storj_theme,
|
| 64 |
+
allow_flagging=False,
|
| 65 |
+
examples=examples
|
| 66 |
+
)
|
| 67 |
+
|
| 68 |
+
## Run app
|
| 69 |
+
iface.launch(share=True, debug=True)
|