temptrip commited on
Commit
dee7798
·
1 Parent(s): 88950dd
Files changed (5) hide show
  1. __pycache__/util.cpython-313.pyc +0 -0
  2. app.py +388 -0
  3. push.sh +3 -0
  4. requirements.txt +4 -0
  5. util.py +113 -0
__pycache__/util.cpython-313.pyc ADDED
Binary file (4.55 kB). View file
 
app.py ADDED
@@ -0,0 +1,388 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import gradio as gr
2
+ import time
3
+ import uuid
4
+ from util import (
5
+ create_task_v3,
6
+ get_task_result,
7
+ )
8
+
9
+
10
+ IP_Dict = {}
11
+
12
+ def generate_biden_voice_with_realtime_updates(text, word_num, request: gr.Request):
13
+ """
14
+ Biden AI voice generation function with real-time status updates
15
+ """
16
+ client_ip = request.client.host
17
+ x_forwarded_for = dict(request.headers).get('x-forwarded-for')
18
+ if x_forwarded_for:
19
+ client_ip = x_forwarded_for
20
+ if client_ip not in IP_Dict:
21
+ IP_Dict[client_ip] = 0
22
+ IP_Dict[client_ip] += 1
23
+ print(f"client_ip: {client_ip}, count: {IP_Dict[client_ip]}")
24
+ if IP_Dict[client_ip] > 5:
25
+ msg = "You have reached the maximum number of requests"
26
+ # Create "Get More Tries" button HTML
27
+ get_more_tries_html = f"""
28
+ <div style='display: flex; justify-content: center; gap: 30px; margin: 10px 0 25px 0; padding: 0px;'>
29
+ <a href='https://joebidenaivoice.net/#generator' target='_blank' style='
30
+ display: inline-flex;
31
+ align-items: center;
32
+ justify-content: center;
33
+ padding: 16px 32px;
34
+ background: linear-gradient(135deg, #11998e 0%, #38ef7d 100%);
35
+ color: white;
36
+ text-decoration: none;
37
+ border-radius: 12px;
38
+ font-weight: 600;
39
+ font-size: 16px;
40
+ text-align: center;
41
+ min-width: 160px;
42
+ box-shadow: 0 4px 15px rgba(17, 153, 142, 0.4);
43
+ transition: all 0.3s ease;
44
+ border: none;
45
+ '>🚀 Get More Tries for Free</a>
46
+ </div>
47
+ """
48
+ yield msg, None, "", gr.update(value=get_more_tries_html, visible=True), ""
49
+ return msg, None, "", gr.update(value=get_more_tries_html, visible=True), ""
50
+
51
+ if not text or len(text.strip()) < 3:
52
+ return "Text too short, please enter at least 3 characters", None, "No task information", gr.update(visible=False), ""
53
+
54
+ try:
55
+ task_type = "voice"
56
+
57
+ # Create task
58
+ task_result = create_task_v3(task_type, text.strip(), word_num, is_rewrite=False)
59
+ if not task_result:
60
+ return "Failed to create task", None, "Task creation failed", gr.update(visible=False), ""
61
+ else:
62
+ yield "Task created successfully", None, "Task creation successful", gr.update(visible=False), ""
63
+
64
+ max_polls = 300
65
+ poll_interval = 1
66
+ task_url = f"https://joebidenaivoice.net/task/{task_result['uuid']}"
67
+
68
+ for i in range(max_polls):
69
+ time.sleep(poll_interval)
70
+ task = get_task_result(task_result['uuid'])
71
+ # print(task, i, "get_task_result")
72
+ if task.get('data', {}):
73
+ status = task.get('data').get('status', '')
74
+ text_final = task.get('data').get('text_final', '')
75
+ if status in ['completed',]:
76
+ voice_url = task.get('data').get('voice_url', '')
77
+ print(voice_url, "===>voice_url")
78
+
79
+ # 下载音频文件到本地以避免SSRF保护问题
80
+ local_audio_path = download_audio_file(voice_url)
81
+
82
+ # Create action buttons HTML
83
+ action_buttons_html = f"""
84
+ <div style='display: flex; justify-content: center; gap: 30px; margin: 25px 0; padding: 20px;'>
85
+ <a href='https://joebidenaivoice.net/#generator' target='_blank' style='
86
+ display: inline-flex;
87
+ align-items: center;
88
+ justify-content: center;
89
+ padding: 16px 32px;
90
+ background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
91
+ color: white;
92
+ text-decoration: none;
93
+ border-radius: 12px;
94
+ font-weight: 600;
95
+ font-size: 16px;
96
+ text-align: center;
97
+ min-width: 160px;
98
+ box-shadow: 0 4px 15px rgba(102, 126, 234, 0.4);
99
+ transition: all 0.3s ease;
100
+ border: none;
101
+ '>🎬 Generate Video</a>
102
+ <a href='{task_url}' target='_blank' style='
103
+ display: inline-flex;
104
+ align-items: center;
105
+ justify-content: center;
106
+ padding: 16px 32px;
107
+ background: linear-gradient(135deg, #11998e 0%, #38ef7d 100%);
108
+ color: white;
109
+ text-decoration: none;
110
+ border-radius: 12px;
111
+ font-weight: 600;
112
+ font-size: 16px;
113
+ text-align: center;
114
+ min-width: 160px;
115
+ box-shadow: 0 4px 15px rgba(17, 153, 142, 0.4);
116
+ transition: all 0.3s ease;
117
+ border: none;
118
+ '>👀 Check Generate Details</a>
119
+ </div>
120
+ """
121
+ yield f"✅ success!!!", local_audio_path, text_final, gr.update(value=action_buttons_html, visible=True), task_url
122
+ return "✅ Generation successful!", local_audio_path, "success", gr.update(value=action_buttons_html, visible=True), task_url
123
+ elif status in ['failed', 'voice_error', 'no_credits']:
124
+ yield "❌ Generation failed!", None, None, gr.update(visible=False), ""
125
+ return "❌ Generation failed!", None, None, gr.update(visible=False), ""
126
+ else:
127
+ yield f"query {i} times, on processing, go to task page {task_url} to check status", None, text_final, gr.update(visible=False), task_url
128
+ return "❌ Generation failed!", None, None, gr.update(visible=False), ""
129
+ except Exception as e:
130
+ error_msg = f"Generation failed: {str(e)}"
131
+ yield error_msg, None, f"❌ Error message: {error_msg}", gr.update(visible=False), ""
132
+ return error_msg, None, f"❌ Error message: {error_msg}", gr.update(visible=False), ""
133
+
134
+ # Create Gradio Interface
135
+ with gr.Blocks(title="Joe Biden AI Voice", theme=gr.themes.Soft()) as demo:
136
+
137
+ # Main title - at the top
138
+ gr.HTML("""
139
+ <div style="text-align: center; margin: 5px auto 0px auto; max-width: 800px;">
140
+ <h1 style="color: #2c3e50; margin: 0; font-size: 3.5em; font-weight: 800; letter-spacing: 3px; text-shadow: 2px 2px 4px rgba(0,0,0,0.1);">
141
+ 🎤 Joe Biden AI Voice
142
+ </h1>
143
+ </div>
144
+ """, padding=False)
145
+
146
+ # # Showcase link banner - second
147
+ # gr.HTML("""
148
+ # <div style="text-align: center; margin: 0px auto 40px auto; max-width: 600px;">
149
+ # <div style="background: linear-gradient(135deg, #ff6b6b 0%, #feca57 50%, #48dbfb 100%); padding: 15px 5px; border-radius: 15px; box-shadow: 0 8px 25px rgba(255, 107, 107, 0.3);">
150
+ # <h3 style="color: white; margin: 0; font-size: 18px;">
151
+ # 🎬 <a href="https://joebidenaivoice.net/showcase" target="_blank" style="color: white; text-decoration: none; font-weight: bold;">Check out Biden AI videos created by others →</a>
152
+ # </h3>
153
+ # </div>
154
+ # </div>
155
+ # """, padding=False)
156
+
157
+ # Powered by link - small text
158
+ gr.HTML("""
159
+ <div style="text-align: center; margin: 0px auto -5px auto;">
160
+ <p style="margin: 0; font-size: 16px; color: #999; font-weight: 400;">
161
+ powered by <a href="https://joebidenaivoice.net/" target="_blank" style="color: #667eea; text-decoration: none;">joebidenaivoice.net</a>
162
+ </p>
163
+ </div>
164
+ """, padding=False)
165
+
166
+ # Simple description text - third
167
+ # gr.HTML("""
168
+ # <div style="text-align: center; margin: 15px auto 30px auto; max-width: 500px;">
169
+ # <p style="color: #666; margin: 0; font-size: 1em; font-weight: 500; line-height: 1.4;">
170
+ # 🔥 Try the most advanced Biden AI Voice and Video generator for FREE at
171
+ # <a href="https://joebidenaivoice.net/" target="_blank" style="color: #667eea; text-decoration: none; font-weight: bold;">joebidenaivoice.net</a>!
172
+ # </p>
173
+ # </div>
174
+ # """)
175
+
176
+ with gr.Row():
177
+ with gr.Column(scale=2):
178
+ text_input = gr.Textbox(
179
+ label="📝 Input Text",
180
+ lines=4,
181
+ placeholder="Enter what you want President Biden to say...",
182
+ value="Hello everyone, this is a demonstration of the Biden AI Voice system with real-time status monitoring."
183
+ )
184
+
185
+ with gr.Column(scale=1):
186
+ word_num_slider = gr.Slider(
187
+ 20, 60, value=60, step=1,
188
+ label="⏱️ Duration Limit"
189
+ )
190
+
191
+ submit_btn = gr.Button(
192
+ "🚀 Generate Biden AI Voice",
193
+ variant="primary",
194
+ size="lg"
195
+ )
196
+
197
+ with gr.Row():
198
+ status_output = gr.Textbox(
199
+ label="📊 Status",
200
+ interactive=False,
201
+ placeholder="Waiting for generation..."
202
+ )
203
+
204
+ # Action buttons that will show after task completion
205
+ with gr.Row():
206
+ action_links = gr.HTML(visible=False)
207
+
208
+ with gr.Row():
209
+ audio_output = gr.Audio(
210
+ label="🎵 Biden AI Voice",
211
+ interactive=False
212
+ )
213
+
214
+ with gr.Row():
215
+ task_info = gr.Textbox(
216
+ label="📋 AI Rewritten Text with Latest News",
217
+ interactive=False,
218
+ lines=12,
219
+ placeholder="AI rewritten text with the latest news will be shown here..."
220
+ )
221
+
222
+
223
+ # Comprehensive introduction section
224
+ gr.HTML("""
225
+ <div style="width: 100%; margin: 30px 0; padding: 0 20px;">
226
+
227
+ <!-- Hero Description -->
228
+ <div style="text-align: center; margin: 25px auto; background: linear-gradient(135deg, #f5f7fa 0%, #c3cfe2 100%); padding: 30px; border-radius: 20px; box-shadow: 0 10px 30px rgba(0,0,0,0.1);">
229
+ <h2 style="color: #2c3e50; margin: 0 0 15px 0; font-size: 1.8em; font-weight: 700;">
230
+ 🇺🇸 Experience the Power of AI-Generated Biden Voice
231
+ </h2>
232
+ <p style="color: #555; font-size: 1.1em; line-height: 1.6; margin: 0 0 20px 0; width: 100%; padding: 0 20px;">
233
+ Transform any text into authentic Joe Biden speech with our cutting-edge AI voice synthesis technology.
234
+ Whether you're creating content for entertainment, education, or social media, our advanced neural network
235
+ captures President Biden's distinctive speaking style, intonation, and rhetorical patterns with remarkable accuracy.
236
+ </p>
237
+ <div style="text-align: center; margin: 15px 0;">
238
+ <a href="https://joebidenaivoice.net/" target="_blank" style="
239
+ display: inline-flex;
240
+ align-items: center;
241
+ justify-content: center;
242
+ padding: 12px 28px;
243
+ background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
244
+ color: white;
245
+ text-decoration: none;
246
+ border-radius: 10px;
247
+ font-weight: 600;
248
+ font-size: 14px;
249
+ box-shadow: 0 4px 15px rgba(102, 126, 234, 0.3);
250
+ transition: all 0.3s ease;
251
+ ">🎬 Generate Biden AI Videos & More →</a>
252
+ </div>
253
+ </div>
254
+
255
+ <!-- Features Grid -->
256
+ <div style="display: grid; grid-template-columns: repeat(auto-fit, minmax(280px, 1fr)); gap: 20px; margin: 40px 0;">
257
+
258
+ <div style="background: white; padding: 25px; border-radius: 15px; box-shadow: 0 5px 20px rgba(0,0,0,0.08); border-left: 5px solid #e74c3c;">
259
+ <h3 style="color: #e74c3c; margin: 0 0 12px 0; font-size: 1.3em; font-weight: 600;">
260
+ 🎯 Ultra-Realistic Voice
261
+ </h3>
262
+ <p style="color: #666; margin: 0; line-height: 1.5; font-size: 0.95em;">
263
+ Our AI model is trained on thousands of hours of Biden speeches, capturing his unique vocal characteristics,
264
+ pronunciation patterns, and speaking rhythm to deliver incredibly lifelike results.
265
+ </p>
266
+ </div>
267
+
268
+ <div style="background: white; padding: 25px; border-radius: 15px; box-shadow: 0 5px 20px rgba(0,0,0,0.08); border-left: 5px solid #3498db;">
269
+ <h3 style="color: #3498db; margin: 0 0 12px 0; font-size: 1.3em; font-weight: 600;">
270
+ ⚡ Lightning Fast Generation
271
+ </h3>
272
+ <p style="color: #666; margin: 0; line-height: 1.5; font-size: 0.95em;">
273
+ Generate high-quality Biden AI voice clips in seconds, not minutes. Our optimized infrastructure
274
+ ensures rapid processing while maintaining exceptional audio quality.
275
+ </p>
276
+ </div>
277
+
278
+ <div style="background: white; padding: 25px; border-radius: 15px; box-shadow: 0 5px 20px rgba(0,0,0,0.08); border-left: 5px solid #27ae60;">
279
+ <h3 style="color: #27ae60; margin: 0 0 12px 0; font-size: 1.3em; font-weight: 600;">
280
+ 🎨 Creative Content Creation
281
+ </h3>
282
+ <p style="color: #666; margin: 0; line-height: 1.5; font-size: 0.95em;">
283
+ Perfect for memes, podcasts, educational content, entertainment videos, or any creative project
284
+ that needs an authentic Biden voice performance.
285
+ </p>
286
+ </div>
287
+
288
+ </div>
289
+
290
+
291
+ <!-- Celebrity Voices Section -->
292
+ <div style="background: linear-gradient(135deg, #ff6b6b 0%, #feca57 50%, #48dbfb 100%); color: white; padding: 40px; border-radius: 20px; margin: 40px 0; text-align: center;">
293
+ <h2 style="margin: 0 0 20px 0; font-size: 1.8em; font-weight: 700;">
294
+ 🎭 Try More Celebrity AI Voices
295
+ </h2>
296
+ <p style="margin: 0 0 25px 0; font-size: 1.1em; opacity: 0.95; line-height: 1.5;">
297
+ Explore our premium collection of celebrity AI voices! Our high-quality service delivers
298
+ lightning-fast results with exceptional audio quality. Experience the best AI voice generation
299
+ with our reliable and responsive platform.
300
+ </p>
301
+ <div style="display: flex; justify-content: center; gap: 20px; flex-wrap: wrap;">
302
+ <a href="https://joebidenaivoice.net/explore" target="_blank" style="
303
+ display: inline-flex;
304
+ align-items: center;
305
+ justify-content: center;
306
+ padding: 18px 35px;
307
+ background: rgba(255,255,255,0.9);
308
+ color: #333;
309
+ text-decoration: none;
310
+ border-radius: 15px;
311
+ font-weight: 700;
312
+ font-size: 16px;
313
+ text-align: center;
314
+ min-width: 200px;
315
+ box-shadow: 0 6px 20px rgba(0,0,0,0.3);
316
+ transition: all 0.3s ease;
317
+ border: none;
318
+ ">🌟 Explore Celebrity Voices</a>
319
+ <a href="https://joebidenaivoice.net/showcase" target="_blank" style="
320
+ display: inline-flex;
321
+ align-items: center;
322
+ justify-content: center;
323
+ padding: 18px 35px;
324
+ background: rgba(255,255,255,0.2);
325
+ color: white;
326
+ text-decoration: none;
327
+ border-radius: 15px;
328
+ font-weight: 700;
329
+ font-size: 16px;
330
+ text-align: center;
331
+ min-width: 200px;
332
+ box-shadow: 0 6px 20px rgba(0,0,0,0.2);
333
+ transition: all 0.3s ease;
334
+ border: 2px solid rgba(255,255,255,0.3);
335
+ ">🎭 View Showcase</a>
336
+ </div>
337
+ </div>
338
+
339
+ <!-- Tips Section -->
340
+ <div style="background: linear-gradient(135deg, #ff9a9e 0%, #fecfef 50%, #fecfef 100%); padding: 25px; border-radius: 15px; margin: 40px 0;">
341
+ <h3 style="color: #8b5cf6; text-align: center; margin: 0 0 20px 0; font-size: 1.4em; font-weight: 700;">
342
+ 💡 Pro Tips for Best Results
343
+ </h3>
344
+ <div style="display: grid; grid-template-columns: repeat(auto-fit, minmax(280px, 1fr)); gap: 15px;">
345
+
346
+ <div style="background: rgba(255,255,255,0.8); padding: 15px; border-radius: 10px;">
347
+ <strong style="color: #8b5cf6;">📖 Clear Text:</strong>
348
+ <span style="color: #555;"> Use proper punctuation and avoid special characters for optimal results.</span>
349
+ </div>
350
+
351
+ <div style="background: rgba(255,255,255,0.8); padding: 15px; border-radius: 10px;">
352
+ <strong style="color: #8b5cf6;">⏱️ Length Matters:</strong>
353
+ <span style="color: #555;"> Shorter texts (20-60 words) typically produce the most natural-sounding results.</span>
354
+ </div>
355
+
356
+ <div style="background: rgba(255,255,255,0.8); padding: 15px; border-radius: 10px;">
357
+ <strong style="color: #8b5cf6;">🎯 Biden Style:</strong>
358
+ <span style="color: #555;"> Text written in Biden's speaking style will sound more authentic and natural.</span>
359
+ </div>
360
+
361
+ </div>
362
+ </div>
363
+
364
+ </div>
365
+ """, padding=False)
366
+
367
+
368
+ # Powered by link - small text
369
+ gr.HTML("""
370
+ <div style="text-align: center; margin: 0px auto -5px auto;">
371
+ <p style="margin: 0; font-size: 16px; color: #999; font-weight: 400;">
372
+ Click <a href="https://joebidenaivoice.net/showcase" target="_blank" style="color: #667eea; text-decoration: none;"> biden ai voices showcase </a> to see more videos
373
+ </p>
374
+ </div>
375
+ """, padding=False)
376
+
377
+ # Hidden state to store task_url
378
+ task_url_state = gr.State("")
379
+
380
+ # Bind event
381
+ submit_btn.click(
382
+ generate_biden_voice_with_realtime_updates,
383
+ inputs=[text_input, word_num_slider],
384
+ outputs=[status_output, audio_output, task_info, action_links, task_url_state]
385
+ )
386
+
387
+ if __name__ == "__main__":
388
+ demo.launch()
push.sh ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ git add .
2
+ git commit -m "init"
3
+ git push
requirements.txt ADDED
@@ -0,0 +1,4 @@
 
 
 
 
 
1
+ gradio>=4.0.0
2
+ requests>=2.31.0
3
+ supabase>=2.0.0
4
+ python-dotenv>=1.0.0
util.py ADDED
@@ -0,0 +1,113 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import requests
2
+ import time
3
+ import uuid
4
+ import os
5
+ from datetime import datetime
6
+ from supabase import create_client, Client
7
+
8
+ try:
9
+ OneKey = os.environ['OneKey'].strip()
10
+
11
+ OneKey = OneKey.split("#")
12
+ TrumpAiUrl = OneKey[0]
13
+ ApiKey = OneKey[1]
14
+ SUPABASE_URL = OneKey[2]
15
+ UserUuid = OneKey[3]
16
+ BackendUrl = OneKey[4]
17
+ BackendApiKey = OneKey[5]
18
+ SUPABASE_KEY = OneKey[6]
19
+ # GRADIO_ALLOWED_HOSTNAMES = OneKey[7]
20
+ # os.environ["GRADIO_ALLOWED_HOSTNAMES"] = GRADIO_ALLOWED_HOSTNAMES
21
+ except Exception as e:
22
+ print(f"OneKey: {e}")
23
+ # exit(1)
24
+
25
+
26
+ # 创建Supabase客户端
27
+ supabase: Client = create_client(SUPABASE_URL, SUPABASE_KEY)
28
+
29
+ # 任务状态枚举
30
+ class TaskStatus:
31
+ Created = "created"
32
+ Processing = "processing"
33
+ TextRewrited = "text_rewrited"
34
+ TextFormated = "text_formated"
35
+ VoiceCompleted = "voice_completed"
36
+ VoiceError = "voice_error"
37
+ VideoCompleted = "video_completed"
38
+ VideoPublished = "video_published"
39
+ VideoError = "video_error"
40
+ Completed = "completed"
41
+ Failed = "failed"
42
+ Cancelled = "cancelled"
43
+ NoCredits = "no_credits"
44
+
45
+
46
+ def create_task_v3(task_type, text, word_num, is_rewrite):
47
+ import json
48
+ is_rewrite = False
49
+ url = f"{BackendUrl}/trump_process_ctx_api_v2"
50
+ headers = {
51
+ "Content-Type": "application/json"
52
+ }
53
+ print(url)
54
+ data = {
55
+ "video_template": "",
56
+ "speaker_template": "https://www.selfitcamera.site/SelfitAssert/Heygem/Biden/Joe_Biden_template.MP3",
57
+ "text": text,
58
+ "word_num": word_num,
59
+ "is_rewrite": False,
60
+ "watermark": True,
61
+ "type": "voice",
62
+ "cost_credits": 2,
63
+ "user_uuid": UserUuid,
64
+ "secret_key": "219ngu"
65
+ }
66
+ try:
67
+ resp = requests.post(url, headers=headers, data=json.dumps(data), timeout=60)
68
+ if not resp.ok:
69
+ print(f"调用trump_process_ctx_api失败: {resp.status_code} {resp.text}")
70
+ return None
71
+ try:
72
+ ctx_json = resp.json()
73
+ except Exception as e:
74
+ print(f"解析trump_process_ctx_api返回异常: {e}")
75
+ return None
76
+ if not ctx_json or ctx_json.get("code") != 0 or not ctx_json.get("data") or not ctx_json["data"].get("task_id"):
77
+ print(f"trump_process_ctx_api返回异常: {ctx_json}")
78
+ return None
79
+ return {
80
+ "task_id": ctx_json["data"]["task_id"],
81
+ "uuid": ctx_json["data"]["task_uuid"],
82
+ "status": "created",
83
+ "message": "任务创建成功,后台处理中"
84
+ }
85
+ except Exception as err:
86
+ print(f"create_task_v3异常: {err}")
87
+ return None
88
+
89
+ def get_task_result(task_id):
90
+ # Poll for task status and result
91
+ url = f"{TrumpAiUrl}/api/task-status/uuid/{task_id}"
92
+ headers = {
93
+ "Content-Type": "application/json",
94
+ "Authorization": f"Bearer {ApiKey}"
95
+ }
96
+ print(url)
97
+ try:
98
+ resp = requests.get(url, headers=headers, timeout=30)
99
+ resp.raise_for_status()
100
+ result = resp.json()
101
+ return result
102
+ except Exception as e:
103
+ return {}
104
+
105
+
106
+ if __name__ == "__main__":
107
+
108
+ task_type = "voice"
109
+ text = "Hello, this is a test message for Trump AI Voice."
110
+ word_num = 10
111
+ is_rewrite = True
112
+ task_result = create_task_v2(task_type, text, word_num, is_rewrite)
113
+ print(f"task_result: {task_result}")