Commit
·
5cbc67b
1
Parent(s):
416fa6c
init
Browse files- app.py +367 -0
- requirements.txt +4 -0
- util.py +113 -0
app.py
ADDED
@@ -0,0 +1,367 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
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_spongebob_voice_with_realtime_updates(text, word_num, request: gr.Request):
|
13 |
+
"""
|
14 |
+
Spongebob 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://trumpaivoice.net/spongebob-ai-voice#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://trumpaivoice.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 = 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://trumpaivoice.net/spongebob-ai-voice#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="Spongebob 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 |
+
🧽 Spongebob AI Voice
|
142 |
+
</h1>
|
143 |
+
</div>
|
144 |
+
""", padding=False)
|
145 |
+
|
146 |
+
# Powered by link - small text
|
147 |
+
gr.HTML("""
|
148 |
+
<div style="text-align: center; margin: 0px auto -5px auto;">
|
149 |
+
<p style="margin: 0; font-size: 16px; color: #999; font-weight: 400;">
|
150 |
+
powered by <a href="https://trumpaivoice.net/" target="_blank" style="color: #667eea; text-decoration: none;">trumpaivoice.net</a>
|
151 |
+
</p>
|
152 |
+
</div>
|
153 |
+
""", padding=False)
|
154 |
+
|
155 |
+
with gr.Row():
|
156 |
+
with gr.Column(scale=2):
|
157 |
+
text_input = gr.Textbox(
|
158 |
+
label="📝 Input Text",
|
159 |
+
lines=4,
|
160 |
+
placeholder="Enter what you want Spongebob to say...",
|
161 |
+
value="I'm ready! I'm ready! This is a demonstration of the Spongebob AI Voice system with cheerful underwater vibes!"
|
162 |
+
)
|
163 |
+
|
164 |
+
with gr.Column(scale=1):
|
165 |
+
word_num_slider = gr.Slider(
|
166 |
+
20, 60, value=60, step=1,
|
167 |
+
label="⏱️ Duration Limit"
|
168 |
+
)
|
169 |
+
|
170 |
+
submit_btn = gr.Button(
|
171 |
+
"🚀 Generate Spongebob AI Voice",
|
172 |
+
variant="primary",
|
173 |
+
size="lg"
|
174 |
+
)
|
175 |
+
|
176 |
+
with gr.Row():
|
177 |
+
status_output = gr.Textbox(
|
178 |
+
label="📊 Status",
|
179 |
+
interactive=False,
|
180 |
+
placeholder="Waiting for generation..."
|
181 |
+
)
|
182 |
+
|
183 |
+
# Action buttons that will show after task completion
|
184 |
+
with gr.Row():
|
185 |
+
action_links = gr.HTML(visible=False)
|
186 |
+
|
187 |
+
with gr.Row():
|
188 |
+
audio_output = gr.Audio(
|
189 |
+
label="🎵 Spongebob AI Voice",
|
190 |
+
interactive=False
|
191 |
+
)
|
192 |
+
|
193 |
+
with gr.Row():
|
194 |
+
task_info = gr.Textbox(
|
195 |
+
label="📋 AI Rewritten Text with Underwater Fun",
|
196 |
+
interactive=False,
|
197 |
+
lines=12,
|
198 |
+
placeholder="AI rewritten text with underwater fun will be shown here..."
|
199 |
+
)
|
200 |
+
|
201 |
+
|
202 |
+
# Comprehensive introduction section
|
203 |
+
gr.HTML("""
|
204 |
+
<div style="width: 100%; margin: 30px 0; padding: 0 20px;">
|
205 |
+
|
206 |
+
<!-- Hero Description -->
|
207 |
+
<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);">
|
208 |
+
<h2 style="color: #2c3e50; margin: 0 0 15px 0; font-size: 1.8em; font-weight: 700;">
|
209 |
+
🧽 Experience the Fun of AI-Generated Spongebob Voice
|
210 |
+
</h2>
|
211 |
+
<p style="color: #555; font-size: 1.1em; line-height: 1.6; margin: 0 0 20px 0; width: 100%; padding: 0 20px;">
|
212 |
+
Transform any text into authentic Spongebob speech with our cutting-edge AI voice synthesis technology.
|
213 |
+
Whether you're creating content for entertainment, education, or social media, our advanced neural network
|
214 |
+
captures Spongebob's distinctive cheerful style, optimistic intonation, and bubbly underwater patterns with remarkable accuracy.
|
215 |
+
</p>
|
216 |
+
<div style="text-align: center; margin: 15px 0;">
|
217 |
+
<a href="https://trumpaivoice.net/spongebob-ai-voice#generator" target="_blank" style="
|
218 |
+
display: inline-flex;
|
219 |
+
align-items: center;
|
220 |
+
justify-content: center;
|
221 |
+
padding: 12px 28px;
|
222 |
+
background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
|
223 |
+
color: white;
|
224 |
+
text-decoration: none;
|
225 |
+
border-radius: 10px;
|
226 |
+
font-weight: 600;
|
227 |
+
font-size: 14px;
|
228 |
+
box-shadow: 0 4px 15px rgba(102, 126, 234, 0.3);
|
229 |
+
transition: all 0.3s ease;
|
230 |
+
">🎬 Generate Spongebob AI Videos & More →</a>
|
231 |
+
</div>
|
232 |
+
</div>
|
233 |
+
|
234 |
+
<!-- Features Grid -->
|
235 |
+
<div style="display: grid; grid-template-columns: repeat(auto-fit, minmax(280px, 1fr)); gap: 20px; margin: 40px 0;">
|
236 |
+
|
237 |
+
<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;">
|
238 |
+
<h3 style="color: #e74c3c; margin: 0 0 12px 0; font-size: 1.3em; font-weight: 600;">
|
239 |
+
🎯 Ultra-Realistic Voice
|
240 |
+
</h3>
|
241 |
+
<p style="color: #666; margin: 0; line-height: 1.5; font-size: 0.95em;">
|
242 |
+
Our AI model is trained on thousands of hours of Spongebob episodes, capturing his unique vocal characteristics,
|
243 |
+
cheerful pronunciation patterns, and enthusiastic speaking rhythm to deliver incredibly lifelike results.
|
244 |
+
</p>
|
245 |
+
</div>
|
246 |
+
|
247 |
+
<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;">
|
248 |
+
<h3 style="color: #3498db; margin: 0 0 12px 0; font-size: 1.3em; font-weight: 600;">
|
249 |
+
⚡ Lightning Fast Generation
|
250 |
+
</h3>
|
251 |
+
<p style="color: #666; margin: 0; line-height: 1.5; font-size: 0.95em;">
|
252 |
+
Generate high-quality Spongebob AI voice clips in seconds, not minutes. Our optimized infrastructure
|
253 |
+
ensures rapid processing while maintaining exceptional audio quality.
|
254 |
+
</p>
|
255 |
+
</div>
|
256 |
+
|
257 |
+
<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;">
|
258 |
+
<h3 style="color: #27ae60; margin: 0 0 12px 0; font-size: 1.3em; font-weight: 600;">
|
259 |
+
🎨 Creative Content Creation
|
260 |
+
</h3>
|
261 |
+
<p style="color: #666; margin: 0; line-height: 1.5; font-size: 0.95em;">
|
262 |
+
Perfect for memes, podcasts, educational content, entertainment videos, or any creative project
|
263 |
+
that needs an authentic Spongebob voice performance.
|
264 |
+
</p>
|
265 |
+
</div>
|
266 |
+
|
267 |
+
</div>
|
268 |
+
|
269 |
+
|
270 |
+
<!-- Celebrity Voices Section -->
|
271 |
+
<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;">
|
272 |
+
<h2 style="margin: 0 0 20px 0; font-size: 1.8em; font-weight: 700;">
|
273 |
+
🎭 Try More Celebrity AI Voices
|
274 |
+
</h2>
|
275 |
+
<p style="margin: 0 0 25px 0; font-size: 1.1em; opacity: 0.95; line-height: 1.5;">
|
276 |
+
Explore our premium collection of celebrity AI voices! Our high-quality service delivers
|
277 |
+
lightning-fast results with exceptional audio quality. Experience the best AI voice generation
|
278 |
+
with our reliable and responsive platform.
|
279 |
+
</p>
|
280 |
+
<div style="display: flex; justify-content: center; gap: 20px; flex-wrap: wrap;">
|
281 |
+
<a href="https://trumpaivoice.net/explore" target="_blank" style="
|
282 |
+
display: inline-flex;
|
283 |
+
align-items: center;
|
284 |
+
justify-content: center;
|
285 |
+
padding: 18px 35px;
|
286 |
+
background: rgba(255,255,255,0.9);
|
287 |
+
color: #333;
|
288 |
+
text-decoration: none;
|
289 |
+
border-radius: 15px;
|
290 |
+
font-weight: 700;
|
291 |
+
font-size: 16px;
|
292 |
+
text-align: center;
|
293 |
+
min-width: 200px;
|
294 |
+
box-shadow: 0 6px 20px rgba(0,0,0,0.3);
|
295 |
+
transition: all 0.3s ease;
|
296 |
+
border: none;
|
297 |
+
">🌟 Explore Celebrity Voices</a>
|
298 |
+
<a href="https://trumpaivoice.net/showcase" target="_blank" style="
|
299 |
+
display: inline-flex;
|
300 |
+
align-items: center;
|
301 |
+
justify-content: center;
|
302 |
+
padding: 18px 35px;
|
303 |
+
background: rgba(255,255,255,0.2);
|
304 |
+
color: white;
|
305 |
+
text-decoration: none;
|
306 |
+
border-radius: 15px;
|
307 |
+
font-weight: 700;
|
308 |
+
font-size: 16px;
|
309 |
+
text-align: center;
|
310 |
+
min-width: 200px;
|
311 |
+
box-shadow: 0 6px 20px rgba(0,0,0,0.2);
|
312 |
+
transition: all 0.3s ease;
|
313 |
+
border: 2px solid rgba(255,255,255,0.3);
|
314 |
+
">🎭 View Showcase</a>
|
315 |
+
</div>
|
316 |
+
</div>
|
317 |
+
|
318 |
+
<!-- Tips Section -->
|
319 |
+
<div style="background: linear-gradient(135deg, #ff9a9e 0%, #fecfef 50%, #fecfef 100%); padding: 25px; border-radius: 15px; margin: 40px 0;">
|
320 |
+
<h3 style="color: #8b5cf6; text-align: center; margin: 0 0 20px 0; font-size: 1.4em; font-weight: 700;">
|
321 |
+
💡 Pro Tips for Best Results
|
322 |
+
</h3>
|
323 |
+
<div style="display: grid; grid-template-columns: repeat(auto-fit, minmax(280px, 1fr)); gap: 15px;">
|
324 |
+
|
325 |
+
<div style="background: rgba(255,255,255,0.8); padding: 15px; border-radius: 10px;">
|
326 |
+
<strong style="color: #8b5cf6;">📖 Clear Text:</strong>
|
327 |
+
<span style="color: #555;"> Use proper punctuation and avoid special characters for optimal results.</span>
|
328 |
+
</div>
|
329 |
+
|
330 |
+
<div style="background: rgba(255,255,255,0.8); padding: 15px; border-radius: 10px;">
|
331 |
+
<strong style="color: #8b5cf6;">⏱️ Length Matters:</strong>
|
332 |
+
<span style="color: #555;"> Shorter texts (20-60 words) typically produce the most natural-sounding results.</span>
|
333 |
+
</div>
|
334 |
+
|
335 |
+
<div style="background: rgba(255,255,255,0.8); padding: 15px; border-radius: 10px;">
|
336 |
+
<strong style="color: #8b5cf6;">🎯 Spongebob Style:</strong>
|
337 |
+
<span style="color: #555;"> Text written in Spongebob's cheerful, enthusiastic style will sound more authentic and natural.</span>
|
338 |
+
</div>
|
339 |
+
|
340 |
+
</div>
|
341 |
+
</div>
|
342 |
+
|
343 |
+
</div>
|
344 |
+
""", padding=False)
|
345 |
+
|
346 |
+
|
347 |
+
# Powered by link - small text
|
348 |
+
gr.HTML("""
|
349 |
+
<div style="text-align: center; margin: 0px auto -5px auto;">
|
350 |
+
<p style="margin: 0; font-size: 16px; color: #999; font-weight: 400;">
|
351 |
+
Click <a href="https://trumpaivoice.net/showcase" target="_blank" style="color: #667eea; text-decoration: none;"> spongebob ai voices showcase </a> to see more videos
|
352 |
+
</p>
|
353 |
+
</div>
|
354 |
+
""", padding=False)
|
355 |
+
|
356 |
+
# Hidden state to store task_url
|
357 |
+
task_url_state = gr.State("")
|
358 |
+
|
359 |
+
# Bind event
|
360 |
+
submit_btn.click(
|
361 |
+
generate_spongebob_voice_with_realtime_updates,
|
362 |
+
inputs=[text_input, word_num_slider],
|
363 |
+
outputs=[status_output, audio_output, task_info, action_links, task_url_state]
|
364 |
+
)
|
365 |
+
|
366 |
+
if __name__ == "__main__":
|
367 |
+
demo.launch()
|
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.trumpaivoice.net/SelfitAssert/Heygem/Spongebob/Spongebob_template.wav",
|
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}")
|