Spaces:
Runtime error
Runtime error
Chen ZiLu
commited on
Commit
·
c24cfde
1
Parent(s):
f864090
Init5
Browse files- api_get.py +83 -17
- app.py +29 -23
api_get.py
CHANGED
@@ -6,6 +6,7 @@ import time
|
|
6 |
import base64
|
7 |
import urllib
|
8 |
import urllib3
|
|
|
9 |
# 加密函数
|
10 |
def hmac_sha256_encrypt(message, key):
|
11 |
message = message.encode('utf-8')
|
@@ -44,11 +45,37 @@ def pre_request():
|
|
44 |
# // 设置本次请求的签名签名串
|
45 |
global reqSignature
|
46 |
reqSignature = encodeSign;
|
47 |
-
print(reqTimestamp, reqSignature, appkey)
|
48 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
49 |
|
|
|
|
|
|
|
50 |
|
51 |
-
def
|
52 |
pre_request()
|
53 |
taskID = ""
|
54 |
|
@@ -74,19 +101,21 @@ def get_taskID(text = "你好"):
|
|
74 |
headers = {
|
75 |
'Content-Type': 'application/json'
|
76 |
}
|
77 |
-
|
78 |
response = requests.request("POST", url, headers=headers, data=payload)
|
79 |
-
time.sleep(1)
|
80 |
-
print("11111111112222222222")
|
81 |
|
82 |
-
|
83 |
-
|
|
|
|
|
84 |
|
|
|
|
|
85 |
return taskID
|
86 |
|
87 |
|
88 |
|
89 |
-
def
|
90 |
|
91 |
pre_request()
|
92 |
url = "https://gw.tvs.qq.com/v2/ivh/videomaker/broadcastservice/getprogress?timestamp="+reqTimestamp+"&signature="+reqSignature+"&appkey="+appkey
|
@@ -103,22 +132,59 @@ def get_video(taskID):
|
|
103 |
|
104 |
response = requests.request("POST", url, headers=headers, data=payload)
|
105 |
|
106 |
-
print(response.text)
|
107 |
return response.text
|
108 |
|
109 |
|
110 |
def generate_video(text = "你好"):
|
111 |
-
taskID =
|
112 |
-
print(taskID)
|
113 |
-
|
114 |
-
|
115 |
-
|
116 |
-
|
117 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
118 |
print(status)
|
119 |
|
120 |
-
|
|
|
|
|
|
|
|
|
121 |
|
122 |
return mediaUrl
|
123 |
|
124 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
6 |
import base64
|
7 |
import urllib
|
8 |
import urllib3
|
9 |
+
import gradio as gr
|
10 |
# 加密函数
|
11 |
def hmac_sha256_encrypt(message, key):
|
12 |
message = message.encode('utf-8')
|
|
|
45 |
# // 设置本次请求的签名签名串
|
46 |
global reqSignature
|
47 |
reqSignature = encodeSign;
|
48 |
+
# print(reqTimestamp, reqSignature, appkey)
|
49 |
|
50 |
+
def req_audioMake(text):
|
51 |
+
pre_request()
|
52 |
+
url = "https://gw.tvs.qq.com/v2/ivh/videomaker/broadcastservice/tts?timestamp="+reqTimestamp+"&signature="+reqSignature+"&appkey="+appkey
|
53 |
+
|
54 |
+
payload = json.dumps({
|
55 |
+
"Header": {},
|
56 |
+
"Payload": {
|
57 |
+
"TimbreKey": "",
|
58 |
+
"VirtualmanKey": "36b88108f6de6da255534eaf4363c7d7",
|
59 |
+
"InputSsml": text,
|
60 |
+
"Speed": 1
|
61 |
+
}
|
62 |
+
})
|
63 |
+
headers = {
|
64 |
+
'Content-Type': 'application/json'
|
65 |
+
}
|
66 |
+
|
67 |
+
response = requests.request("POST", url, headers=headers, data=payload)
|
68 |
+
|
69 |
+
res = json.loads(response.text)
|
70 |
+
if res["Header"]["Code"] != 0:
|
71 |
+
print(response.text)
|
72 |
+
return
|
73 |
|
74 |
+
taskID = (res["Payload"]["TaskId"])
|
75 |
+
print(taskID)
|
76 |
+
return taskID
|
77 |
|
78 |
+
def req_videoMake(text = "你好"):
|
79 |
pre_request()
|
80 |
taskID = ""
|
81 |
|
|
|
101 |
headers = {
|
102 |
'Content-Type': 'application/json'
|
103 |
}
|
104 |
+
|
105 |
response = requests.request("POST", url, headers=headers, data=payload)
|
|
|
|
|
106 |
|
107 |
+
res = json.loads(response.text)
|
108 |
+
if res["Header"]["Code"] != 0:
|
109 |
+
print(response.text)
|
110 |
+
return
|
111 |
|
112 |
+
taskID = (res["Payload"]["TaskId"])
|
113 |
+
print(taskID)
|
114 |
return taskID
|
115 |
|
116 |
|
117 |
|
118 |
+
def get_media(taskID):
|
119 |
|
120 |
pre_request()
|
121 |
url = "https://gw.tvs.qq.com/v2/ivh/videomaker/broadcastservice/getprogress?timestamp="+reqTimestamp+"&signature="+reqSignature+"&appkey="+appkey
|
|
|
132 |
|
133 |
response = requests.request("POST", url, headers=headers, data=payload)
|
134 |
|
135 |
+
# print(response.text)
|
136 |
return response.text
|
137 |
|
138 |
|
139 |
def generate_video(text = "你好"):
|
140 |
+
taskID = req_videoMake(text)
|
141 |
+
# print(taskID)
|
142 |
+
|
143 |
+
sleepSecond = 5
|
144 |
+
time.sleep(sleepSecond)
|
145 |
+
videoRep = json.loads(get_media(taskID))
|
146 |
+
|
147 |
+
status = videoRep["Payload"]["Status"]
|
148 |
+
|
149 |
+
while status == "COMMIT" or status == "MAKING":
|
150 |
+
time.sleep(1)
|
151 |
+
videoRep = json.loads(get_media(taskID))
|
152 |
+
status = videoRep["Payload"]["Status"]
|
153 |
print(status)
|
154 |
|
155 |
+
if status == "FAIL":
|
156 |
+
print(videoRep)
|
157 |
+
return
|
158 |
+
|
159 |
+
mediaUrl = videoRep["Payload"]["MediaUrl"]
|
160 |
|
161 |
return mediaUrl
|
162 |
|
163 |
|
164 |
+
def generate_audio(text):
|
165 |
+
taskID = req_audioMake(text)
|
166 |
+
# print(taskID)
|
167 |
+
|
168 |
+
sleepSecond = 5
|
169 |
+
time.sleep(sleepSecond)
|
170 |
+
videoRep = json.loads(get_media(taskID))
|
171 |
+
|
172 |
+
status = videoRep["Payload"]["Status"]
|
173 |
+
|
174 |
+
while status == "COMMIT" or status == "MAKING":
|
175 |
+
time.sleep(1)
|
176 |
+
videoRep = json.loads(get_media(taskID))
|
177 |
+
status = videoRep["Payload"]["Status"]
|
178 |
+
print(status)
|
179 |
+
|
180 |
+
if status == "FAIL":
|
181 |
+
print(videoRep)
|
182 |
+
return
|
183 |
+
|
184 |
+
mediaUrl = videoRep["Payload"]["MediaUrl"]
|
185 |
+
|
186 |
+
return mediaUrl
|
187 |
+
|
188 |
+
|
189 |
+
|
190 |
+
|
app.py
CHANGED
@@ -7,15 +7,12 @@ from modules.ui_components import FormRow, FormGroup, ToolButton, FormHTML
|
|
7 |
# c = os.path.join(os.path.dirname(__file__), "files/b.mp4") # Video
|
8 |
clear_prompt_symbol = '\U0001f5d1\ufe0f' # 🗑️
|
9 |
def generate_video(text = "<break time=\"5000\"/>,大家奖fsdfdf,房间号是吗?<break time=\"5000\"/>"):
|
|
|
10 |
return api_get.generate_video( text = text)
|
11 |
|
12 |
-
|
13 |
-
|
14 |
-
|
15 |
-
# inputs=gr.Textbox(placeholder = "输入文案", label = "文字转视频"),
|
16 |
-
# outputs=gr.Video(type="mp4", label = "视频"),
|
17 |
-
# title="文字转视频",
|
18 |
-
# description="输入文案,生成视频")
|
19 |
|
20 |
|
21 |
with gr.Blocks() as demo:
|
@@ -24,26 +21,35 @@ with gr.Blocks() as demo:
|
|
24 |
id_part = "text_to_video"
|
25 |
with gr.Row():
|
26 |
with gr.Column():
|
27 |
-
|
28 |
with gr.Row():
|
29 |
-
|
30 |
-
|
31 |
-
|
32 |
-
|
33 |
-
text_button = gr.Button("生成", variant='primary')
|
34 |
|
35 |
video_output = gr.Video(type="mp4", label = "视频")
|
36 |
-
|
37 |
-
|
38 |
-
|
|
|
39 |
with gr.Tab("文生音频"):
|
40 |
-
|
41 |
-
|
42 |
-
with gr.
|
43 |
-
|
44 |
-
|
45 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
46 |
|
47 |
if __name__ == "__main__":
|
48 |
-
demo.launch()
|
49 |
|
|
|
7 |
# c = os.path.join(os.path.dirname(__file__), "files/b.mp4") # Video
|
8 |
clear_prompt_symbol = '\U0001f5d1\ufe0f' # 🗑️
|
9 |
def generate_video(text = "<break time=\"5000\"/>,大家奖fsdfdf,房间号是吗?<break time=\"5000\"/>"):
|
10 |
+
# gr.Warning("fjskdf=======")
|
11 |
return api_get.generate_video( text = text)
|
12 |
|
13 |
+
def generate_audio(text = "<break time=\"5000\"/>,大家奖fsdfdf,房间号是吗?<break time=\"5000\"/>"):
|
14 |
+
# gr.Warning("fjskdf=======")
|
15 |
+
return api_get.generate_audio( text = text)
|
|
|
|
|
|
|
|
|
16 |
|
17 |
|
18 |
with gr.Blocks() as demo:
|
|
|
21 |
id_part = "text_to_video"
|
22 |
with gr.Row():
|
23 |
with gr.Column():
|
24 |
+
text2video_input = gr.Textbox(placeholder = "输入文案", label = "文字")
|
25 |
with gr.Row():
|
26 |
+
text2video_button2 = gr.Button("插入停顿", variant='secondary')
|
27 |
+
text2video_button3 = gr.Button("插入数量", variant='secondary')
|
28 |
+
cancel_button1 = gr.ClearButton(variant='stop')
|
29 |
+
text2video_button = gr.Button("生成", variant='primary')
|
|
|
30 |
|
31 |
video_output = gr.Video(type="mp4", label = "视频")
|
32 |
+
text2video_button.click(generate_video, inputs=text2video_input, outputs=video_output)
|
33 |
+
cancel_button1.click(lambda x: "", outputs=text2video_input)
|
34 |
+
text2video_button2.click(lambda x: x+"<break time=\"5000\"/>,", inputs = text2video_input, outputs=text2video_input)
|
35 |
+
text2video_button3.click(lambda x: x+"<say-as interpret-as=\"cardinal\">123456</say-as>,", inputs = text2video_input, outputs=text2video_input)
|
36 |
with gr.Tab("文生音频"):
|
37 |
+
id_part = "text_to_audio"
|
38 |
+
with gr.Row():
|
39 |
+
with gr.Column():
|
40 |
+
text2audio_input = gr.Textbox(placeholder = "输入文案", label = "文字")
|
41 |
+
with gr.Row():
|
42 |
+
text2audio_button2 = gr.Button("插入停顿", variant='secondary')
|
43 |
+
text2audio_button3 = gr.Button("插入数量", variant='secondary')
|
44 |
+
cancel_button2 = gr.ClearButton(variant='stop')
|
45 |
+
text2audio_button = gr.Button("生成", variant='primary')
|
46 |
+
|
47 |
+
audio_output = gr.Video(type="mp3", label = "音频")
|
48 |
+
text2audio_button.click(generate_audio, inputs=text2audio_input, outputs=audio_output)
|
49 |
+
cancel_button2.click(lambda x: "", outputs=text2audio_input)
|
50 |
+
text2audio_button2.click(lambda x: x+"<break time=\"5000\"/>,", inputs = text2audio_input, outputs=text2audio_input)
|
51 |
+
text2audio_button3.click(lambda x: x+"<say-as interpret-as=\"cardinal\">123456</say-as>,", inputs = text2audio_input, outputs=text2audio_input)
|
52 |
|
53 |
if __name__ == "__main__":
|
54 |
+
demo.launch(server_port = 8080)
|
55 |
|