hysts HF staff commited on
Commit
62f5cce
β€’
1 Parent(s): 9ac3fc2
Files changed (6) hide show
  1. .pre-commit-config.yaml +37 -0
  2. .style.yapf +5 -0
  3. README.md +2 -2
  4. app.py +66 -0
  5. requirements.txt +5 -0
  6. style.css +3 -0
.pre-commit-config.yaml ADDED
@@ -0,0 +1,37 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ exclude: patch
2
+ repos:
3
+ - repo: https://github.com/pre-commit/pre-commit-hooks
4
+ rev: v4.2.0
5
+ hooks:
6
+ - id: check-executables-have-shebangs
7
+ - id: check-json
8
+ - id: check-merge-conflict
9
+ - id: check-shebang-scripts-are-executable
10
+ - id: check-toml
11
+ - id: check-yaml
12
+ - id: double-quote-string-fixer
13
+ - id: end-of-file-fixer
14
+ - id: mixed-line-ending
15
+ args: ['--fix=lf']
16
+ - id: requirements-txt-fixer
17
+ - id: trailing-whitespace
18
+ - repo: https://github.com/myint/docformatter
19
+ rev: v1.4
20
+ hooks:
21
+ - id: docformatter
22
+ args: ['--in-place']
23
+ - repo: https://github.com/pycqa/isort
24
+ rev: 5.12.0
25
+ hooks:
26
+ - id: isort
27
+ - repo: https://github.com/pre-commit/mirrors-mypy
28
+ rev: v0.991
29
+ hooks:
30
+ - id: mypy
31
+ args: ['--ignore-missing-imports']
32
+ additional_dependencies: ['types-python-slugify']
33
+ - repo: https://github.com/google/yapf
34
+ rev: v0.32.0
35
+ hooks:
36
+ - id: yapf
37
+ args: ['--parallel', '--in-place']
.style.yapf ADDED
@@ -0,0 +1,5 @@
 
 
 
 
 
 
1
+ [style]
2
+ based_on_style = pep8
3
+ blank_line_before_nested_class_or_def = false
4
+ spaces_before_comment = 2
5
+ split_before_logical_operator = true
README.md CHANGED
@@ -1,10 +1,10 @@
1
  ---
2
- title: Modelscope Text To Video Synthesis
3
  emoji: πŸš€
4
  colorFrom: pink
5
  colorTo: pink
6
  sdk: gradio
7
- sdk_version: 3.21.0
8
  app_file: app.py
9
  pinned: false
10
  ---
 
1
  ---
2
+ title: ModelScope Text To Video Synthesis
3
  emoji: πŸš€
4
  colorFrom: pink
5
  colorTo: pink
6
  sdk: gradio
7
+ sdk_version: 3.22.1
8
  app_file: app.py
9
  pinned: false
10
  ---
app.py ADDED
@@ -0,0 +1,66 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ #!/usr/bin/env python
2
+
3
+ from __future__ import annotations
4
+
5
+ import os
6
+ import shlex
7
+ import subprocess
8
+
9
+ import gradio as gr
10
+ import torch
11
+
12
+ if os.getenv('SYSTEM') == 'spaces':
13
+ subprocess.run(shlex.split('pip uninstall -y modelscope'))
14
+ subprocess.run(
15
+ shlex.split(
16
+ 'pip install git+https://github.com/modelscope/modelscope.git@refs/pull/207/head'
17
+ ))
18
+
19
+ from modelscope.outputs import OutputKeys
20
+ from modelscope.pipelines import pipeline
21
+
22
+ DESCRIPTION = '# [ModelScope Text to Video Synthesis](https://modelscope.cn/models/damo/text-to-video-synthesis/summary)'
23
+ if (SPACE_ID := os.getenv('SPACE_ID')) is not None:
24
+ DESCRIPTION += f'\n<p>For faster inference without waiting in queue, you may duplicate the space and upgrade to GPU in settings. <a href="https://huggingface.co/spaces/{SPACE_ID}?duplicate=true"><img style="display: inline; margin-top: 0em; margin-bottom: 0em" src="https://bit.ly/3gLdBN6" alt="Duplicate Space" /></a></p>'
25
+
26
+ pipe = pipeline('text-to-video-synthesis', 'damo/text-to-video-synthesis')
27
+
28
+
29
+ def generate(prompt: str, seed: int) -> str:
30
+ torch.manual_seed(seed)
31
+ return pipe({'text': prompt})[OutputKeys.OUTPUT_VIDEO]
32
+
33
+
34
+ examples = [
35
+ ['An astronaut riding a horse.', 0],
36
+ ['A panda eating bamboo on a rock.', 0],
37
+ ['Spiderman is surfing.', 0],
38
+ ]
39
+
40
+ with gr.Blocks(css='style.css') as demo:
41
+ gr.Markdown(DESCRIPTION)
42
+ with gr.Row():
43
+ with gr.Column():
44
+ prompt = gr.Text(label='Prompt', max_lines=1)
45
+ seed = gr.Slider(
46
+ label='Seed',
47
+ minimum=-1,
48
+ maximum=1000000,
49
+ step=1,
50
+ value=-1,
51
+ info='If set to -1, a different seed will be used each time.')
52
+ run_button = gr.Button('Run')
53
+ with gr.Column():
54
+ result = gr.Video(label='Result')
55
+
56
+ inputs = [prompt, seed]
57
+ gr.Examples(examples=examples,
58
+ inputs=inputs,
59
+ outputs=result,
60
+ fn=generate,
61
+ cache_examples=os.getenv('SYSTEM') == 'spaces')
62
+
63
+ prompt.submit(fn=generate, inputs=inputs, outputs=result)
64
+ run_button.click(fn=generate, inputs=inputs, outputs=result)
65
+
66
+ demo.queue(api_open=False).launch()
requirements.txt ADDED
@@ -0,0 +1,5 @@
 
 
 
 
 
 
1
+ decord==0.6.0
2
+ fairseq==0.12.2
3
+ gradio==3.22.1
4
+ modelscope[multi-modal]==1.4.1
5
+ open_clip_torch==2.16.0
style.css ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ h1 {
2
+ text-align: center;
3
+ }