Intercept-Intelligence commited on
Commit
0653206
·
verified ·
1 Parent(s): 28f0a93

Create App.py

Browse files
Files changed (1) hide show
  1. App.py +69 -0
App.py ADDED
@@ -0,0 +1,69 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import gradio as gr
2
+ from huggingface_hub import InferenceClient
3
+
4
+ """
5
+ For more information on `huggingface_hub` Inference API support, please check the docs:
6
+ https://huggingface.co/docs/huggingface_hub/v0.22.2/en/guides/inference
7
+ """
8
+ client = InferenceClient("damo-vilab/modelscope-text-to-video-synthesis")
9
+
10
+ def respond(
11
+ message,
12
+ history: list[tuple[str, str]],
13
+ system_message,
14
+ max_tokens,
15
+ temperature,
16
+ top_p,
17
+ ):
18
+ messages = [{"role": "system", "content": system_message}]
19
+
20
+ for val in history:
21
+ if val[0]:
22
+ messages.append({"role": "user", "content": val[0]})
23
+ if val[1]:
24
+ messages.append({"role": "assistant", "content": val[1]})
25
+
26
+ messages.append({"role": "user", "content": message})
27
+
28
+ # NOTE: Video models don't usually use "streaming" generation, so we'll just call once
29
+ payload = {
30
+ "inputs": message,
31
+ "parameters": {
32
+ "max_new_tokens": max_tokens,
33
+ "temperature": temperature,
34
+ "top_p": top_p,
35
+ }
36
+ }
37
+
38
+ # Post directly to the model
39
+ response = client.post(json=payload)
40
+
41
+ video_url = response.get("video", None)
42
+
43
+ if video_url:
44
+ yield video_url
45
+ else:
46
+ yield "Failed to generate video."
47
+
48
+ """
49
+ For information on how to customize the ChatInterface, peruse the gradio docs:
50
+ https://www.gradio.app/docs/chatinterface
51
+ """
52
+ demo = gr.ChatInterface(
53
+ respond,
54
+ additional_inputs=[
55
+ gr.Textbox(value="You are generating a creative video.", label="System message"),
56
+ gr.Slider(minimum=1, maximum=1000, value=250, step=1, label="Max new tokens"),
57
+ gr.Slider(minimum=0.1, maximum=2.0, value=1.0, step=0.1, label="Temperature"),
58
+ gr.Slider(
59
+ minimum=0.1,
60
+ maximum=1.0,
61
+ value=0.9,
62
+ step=0.05,
63
+ label="Top-p (nucleus sampling)",
64
+ ),
65
+ ],
66
+ )
67
+
68
+ if __name__ == "__main__":
69
+ demo.launch()