Spaces:
Running
Running
Upload app.py
Browse files
app.py
ADDED
@@ -0,0 +1,112 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
#!/usr/bin/env python
|
2 |
+
|
3 |
+
from __future__ import annotations
|
4 |
+
|
5 |
+
import gradio as gr
|
6 |
+
|
7 |
+
# from model import AppModel
|
8 |
+
|
9 |
+
MAINTENANCE_NOTICE='Sorry, due to computing resources issues, this space is under maintenance, and will be restored as soon as possible. '
|
10 |
+
|
11 |
+
DESCRIPTION = '''# <a href="https://github.com/THUDM/CogVideo">CogVideo</a>
|
12 |
+
|
13 |
+
Currently, this Space only supports the first stage of the CogVideo pipeline due to hardware limitations.
|
14 |
+
|
15 |
+
The model accepts only Chinese as input.
|
16 |
+
By checking the "Translate to Chinese" checkbox, the results of English to Chinese translation with [this Space](https://huggingface.co/spaces/chinhon/translation_eng2ch) will be used as input.
|
17 |
+
Since the translation model may mistranslate, you may want to use the translation results from other translation services.
|
18 |
+
'''
|
19 |
+
NOTES = 'This app is adapted from <a href="https://github.com/hysts/CogVideo_demo">https://github.com/hysts/CogVideo_demo</a>. It would be recommended to use the repo if you want to run the app yourself.'
|
20 |
+
FOOTER = '<img id="visitor-badge" alt="visitor badge" src="https://visitor-badge.glitch.me/badge?page_id=THUDM.CogVideo" />'
|
21 |
+
|
22 |
+
import json
|
23 |
+
import requests
|
24 |
+
|
25 |
+
def post(
|
26 |
+
text,
|
27 |
+
translate,
|
28 |
+
seed,
|
29 |
+
only_first_stage,
|
30 |
+
image_prompt
|
31 |
+
):
|
32 |
+
url = 'https://ccb8is4fqtofrtdsfjebg.ml-platform-cn-beijing.volces.com/devinstance/di-20221130120908-bhpxq/proxy/6201/cogvideo-s1'
|
33 |
+
headers = {
|
34 |
+
"Content-Type": "application/json; charset=UTF-8",
|
35 |
+
"User-Agent": "Mozilla/5.0 (Windows NT 6.1; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/67.0.3396.87 Safari/537.36",
|
36 |
+
}
|
37 |
+
|
38 |
+
data = json.dumps({'text': text,
|
39 |
+
'translate': translate,
|
40 |
+
'seed': seed,
|
41 |
+
'only_first_stage': only_first_stage,
|
42 |
+
'image_prompt': image_prompt
|
43 |
+
})
|
44 |
+
r = requests.post(url, data, headers=headers)
|
45 |
+
|
46 |
+
translated_text = r.json()['data']['translated_text']
|
47 |
+
result_video = r.json()['data']['result_video']
|
48 |
+
return translated_text, result_video
|
49 |
+
|
50 |
+
def main():
|
51 |
+
only_first_stage = True
|
52 |
+
# model = AppModel(only_first_stage)
|
53 |
+
|
54 |
+
with gr.Blocks(css='style.css') as demo:
|
55 |
+
# gr.Markdown(MAINTENANCE_NOTICE)
|
56 |
+
|
57 |
+
gr.Markdown(DESCRIPTION)
|
58 |
+
|
59 |
+
with gr.Row():
|
60 |
+
with gr.Column():
|
61 |
+
with gr.Group():
|
62 |
+
text = gr.Textbox(label='Input Text')
|
63 |
+
translate = gr.Checkbox(label='Translate to Chinese',
|
64 |
+
value=False)
|
65 |
+
seed = gr.Slider(0,
|
66 |
+
100000,
|
67 |
+
step=1,
|
68 |
+
value=1234,
|
69 |
+
label='Seed')
|
70 |
+
only_first_stage = gr.Checkbox(
|
71 |
+
label='Only First Stage',
|
72 |
+
value=only_first_stage,
|
73 |
+
visible=not only_first_stage)
|
74 |
+
image_prompt = gr.Image(type="filepath",
|
75 |
+
label="Image Prompt",
|
76 |
+
value=None)
|
77 |
+
run_button = gr.Button('Run')
|
78 |
+
|
79 |
+
with gr.Column():
|
80 |
+
with gr.Group():
|
81 |
+
translated_text = gr.Textbox(label='Translated Text')
|
82 |
+
with gr.Tabs():
|
83 |
+
with gr.TabItem('Output (Video)'):
|
84 |
+
result_video = gr.Video(show_label=False)
|
85 |
+
|
86 |
+
# examples = gr.Examples(
|
87 |
+
# examples=[['骑滑板的皮卡丘', False, 1234, True,None],
|
88 |
+
# ['a cat playing chess', True, 1253, True,None]],
|
89 |
+
# fn=model.run_with_translation,
|
90 |
+
# inputs=[text, translate, seed, only_first_stage,image_prompt],
|
91 |
+
# outputs=[translated_text, result_video],
|
92 |
+
# cache_examples=True)
|
93 |
+
|
94 |
+
gr.Markdown(NOTES)
|
95 |
+
gr.Markdown(FOOTER)
|
96 |
+
print(gr.__version__)
|
97 |
+
run_button.click(fn=post,
|
98 |
+
inputs=[
|
99 |
+
text,
|
100 |
+
translate,
|
101 |
+
seed,
|
102 |
+
only_first_stage,
|
103 |
+
image_prompt
|
104 |
+
],
|
105 |
+
outputs=[translated_text, result_video])
|
106 |
+
print(gr.__version__)
|
107 |
+
|
108 |
+
demo.launch()
|
109 |
+
|
110 |
+
|
111 |
+
if __name__ == '__main__':
|
112 |
+
main()
|