temptrip commited on
Commit
6784ca6
·
1 Parent(s): 08251b4
Files changed (6) hide show
  1. .gitattributes +35 -35
  2. README.md +14 -14
  3. __pycache__/util.cpython-313.pyc +0 -0
  4. app.py +236 -236
  5. requirements.txt +3 -3
  6. util.py +116 -116
.gitattributes CHANGED
@@ -1,35 +1,35 @@
1
- *.7z filter=lfs diff=lfs merge=lfs -text
2
- *.arrow filter=lfs diff=lfs merge=lfs -text
3
- *.bin filter=lfs diff=lfs merge=lfs -text
4
- *.bz2 filter=lfs diff=lfs merge=lfs -text
5
- *.ckpt filter=lfs diff=lfs merge=lfs -text
6
- *.ftz filter=lfs diff=lfs merge=lfs -text
7
- *.gz filter=lfs diff=lfs merge=lfs -text
8
- *.h5 filter=lfs diff=lfs merge=lfs -text
9
- *.joblib filter=lfs diff=lfs merge=lfs -text
10
- *.lfs.* filter=lfs diff=lfs merge=lfs -text
11
- *.mlmodel filter=lfs diff=lfs merge=lfs -text
12
- *.model filter=lfs diff=lfs merge=lfs -text
13
- *.msgpack filter=lfs diff=lfs merge=lfs -text
14
- *.npy filter=lfs diff=lfs merge=lfs -text
15
- *.npz filter=lfs diff=lfs merge=lfs -text
16
- *.onnx filter=lfs diff=lfs merge=lfs -text
17
- *.ot filter=lfs diff=lfs merge=lfs -text
18
- *.parquet filter=lfs diff=lfs merge=lfs -text
19
- *.pb filter=lfs diff=lfs merge=lfs -text
20
- *.pickle filter=lfs diff=lfs merge=lfs -text
21
- *.pkl filter=lfs diff=lfs merge=lfs -text
22
- *.pt filter=lfs diff=lfs merge=lfs -text
23
- *.pth filter=lfs diff=lfs merge=lfs -text
24
- *.rar filter=lfs diff=lfs merge=lfs -text
25
- *.safetensors filter=lfs diff=lfs merge=lfs -text
26
- saved_model/**/* filter=lfs diff=lfs merge=lfs -text
27
- *.tar.* filter=lfs diff=lfs merge=lfs -text
28
- *.tar filter=lfs diff=lfs merge=lfs -text
29
- *.tflite filter=lfs diff=lfs merge=lfs -text
30
- *.tgz filter=lfs diff=lfs merge=lfs -text
31
- *.wasm filter=lfs diff=lfs merge=lfs -text
32
- *.xz filter=lfs diff=lfs merge=lfs -text
33
- *.zip filter=lfs diff=lfs merge=lfs -text
34
- *.zst filter=lfs diff=lfs merge=lfs -text
35
- *tfevents* filter=lfs diff=lfs merge=lfs -text
 
1
+ *.7z filter=lfs diff=lfs merge=lfs -text
2
+ *.arrow filter=lfs diff=lfs merge=lfs -text
3
+ *.bin filter=lfs diff=lfs merge=lfs -text
4
+ *.bz2 filter=lfs diff=lfs merge=lfs -text
5
+ *.ckpt filter=lfs diff=lfs merge=lfs -text
6
+ *.ftz filter=lfs diff=lfs merge=lfs -text
7
+ *.gz filter=lfs diff=lfs merge=lfs -text
8
+ *.h5 filter=lfs diff=lfs merge=lfs -text
9
+ *.joblib filter=lfs diff=lfs merge=lfs -text
10
+ *.lfs.* filter=lfs diff=lfs merge=lfs -text
11
+ *.mlmodel filter=lfs diff=lfs merge=lfs -text
12
+ *.model filter=lfs diff=lfs merge=lfs -text
13
+ *.msgpack filter=lfs diff=lfs merge=lfs -text
14
+ *.npy filter=lfs diff=lfs merge=lfs -text
15
+ *.npz filter=lfs diff=lfs merge=lfs -text
16
+ *.onnx filter=lfs diff=lfs merge=lfs -text
17
+ *.ot filter=lfs diff=lfs merge=lfs -text
18
+ *.parquet filter=lfs diff=lfs merge=lfs -text
19
+ *.pb filter=lfs diff=lfs merge=lfs -text
20
+ *.pickle filter=lfs diff=lfs merge=lfs -text
21
+ *.pkl filter=lfs diff=lfs merge=lfs -text
22
+ *.pt filter=lfs diff=lfs merge=lfs -text
23
+ *.pth filter=lfs diff=lfs merge=lfs -text
24
+ *.rar filter=lfs diff=lfs merge=lfs -text
25
+ *.safetensors filter=lfs diff=lfs merge=lfs -text
26
+ saved_model/**/* filter=lfs diff=lfs merge=lfs -text
27
+ *.tar.* filter=lfs diff=lfs merge=lfs -text
28
+ *.tar filter=lfs diff=lfs merge=lfs -text
29
+ *.tflite filter=lfs diff=lfs merge=lfs -text
30
+ *.tgz filter=lfs diff=lfs merge=lfs -text
31
+ *.wasm filter=lfs diff=lfs merge=lfs -text
32
+ *.xz filter=lfs diff=lfs merge=lfs -text
33
+ *.zip filter=lfs diff=lfs merge=lfs -text
34
+ *.zst filter=lfs diff=lfs merge=lfs -text
35
+ *tfevents* filter=lfs diff=lfs merge=lfs -text
README.md CHANGED
@@ -1,14 +1,14 @@
1
- ---
2
- title: Trump Ai Voice
3
- emoji: 📉
4
- colorFrom: blue
5
- colorTo: purple
6
- sdk: gradio
7
- sdk_version: 5.37.0
8
- app_file: app.py
9
- pinned: false
10
- license: mit
11
- short_description: Trump Ai Voice Generator
12
- ---
13
-
14
- Check out the configuration reference at https://huggingface.co/docs/hub/spaces-config-reference
 
1
+ ---
2
+ title: Trump Ai Voice
3
+ emoji: 📉
4
+ colorFrom: blue
5
+ colorTo: purple
6
+ sdk: gradio
7
+ sdk_version: 5.37.0
8
+ app_file: app.py
9
+ pinned: false
10
+ license: mit
11
+ short_description: Trump Ai Voice Generator
12
+ ---
13
+
14
+ Check out the configuration reference at https://huggingface.co/docs/hub/spaces-config-reference
__pycache__/util.cpython-313.pyc ADDED
Binary file (4.79 kB). View file
 
app.py CHANGED
@@ -1,237 +1,237 @@
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_trump_voice_with_realtime_updates(text, word_num, request: gr.Request):
13
- """
14
- Trump 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] > 2:
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://donaldtrumpaivoice.com/#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://donaldtrumpaivoice.com/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
- # Create action buttons HTML
78
- action_buttons_html = f"""
79
- <div style='display: flex; justify-content: center; gap: 30px; margin: 25px 0; padding: 20px;'>
80
- <a href='https://donaldtrumpaivoice.com/#generator' target='_blank' style='
81
- display: inline-flex;
82
- align-items: center;
83
- justify-content: center;
84
- padding: 16px 32px;
85
- background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
86
- color: white;
87
- text-decoration: none;
88
- border-radius: 12px;
89
- font-weight: 600;
90
- font-size: 16px;
91
- text-align: center;
92
- min-width: 160px;
93
- box-shadow: 0 4px 15px rgba(102, 126, 234, 0.4);
94
- transition: all 0.3s ease;
95
- border: none;
96
- '>🎬 Generate Video</a>
97
- <a href='{task_url}' target='_blank' style='
98
- display: inline-flex;
99
- align-items: center;
100
- justify-content: center;
101
- padding: 16px 32px;
102
- background: linear-gradient(135deg, #11998e 0%, #38ef7d 100%);
103
- color: white;
104
- text-decoration: none;
105
- border-radius: 12px;
106
- font-weight: 600;
107
- font-size: 16px;
108
- text-align: center;
109
- min-width: 160px;
110
- box-shadow: 0 4px 15px rgba(17, 153, 142, 0.4);
111
- transition: all 0.3s ease;
112
- border: none;
113
- '>👀 Check Generate Details</a>
114
- </div>
115
- """
116
- yield f"✅ success!!!", voice_url, text_final, gr.update(value=action_buttons_html, visible=True), task_url
117
- return "✅ Generation successful!", voice_url, "success", gr.update(value=action_buttons_html, visible=True), task_url
118
- elif status in ['failed', 'voice_error', 'no_credits']:
119
- yield "❌ Generation failed!", None, None, gr.update(visible=False), ""
120
- return "❌ Generation failed!", None, None, gr.update(visible=False), ""
121
- else:
122
- 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
123
- return "❌ Generation failed!", None, None, gr.update(visible=False), ""
124
- except Exception as e:
125
- error_msg = f"Generation failed: {str(e)}"
126
- yield error_msg, None, f"❌ Error message: {error_msg}", gr.update(visible=False), ""
127
- return error_msg, None, f"❌ Error message: {error_msg}", gr.update(visible=False), ""
128
-
129
- # Create Gradio Interface
130
- with gr.Blocks(title="Donald Trump AI Voice", theme=gr.themes.Soft()) as demo:
131
-
132
- # Main title - at the top
133
- gr.HTML("""
134
- <div style="text-align: center; margin: 5px auto 0px auto; max-width: 800px;">
135
- <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);">
136
- 🎤 Trump AI Voice
137
- </h1>
138
- </div>
139
- """, padding=False)
140
-
141
- # # Showcase link banner - second
142
- # gr.HTML("""
143
- # <div style="text-align: center; margin: 0px auto 40px auto; max-width: 600px;">
144
- # <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);">
145
- # <h3 style="color: white; margin: 0; font-size: 18px;">
146
- # 🎬 <a href="https://donaldtrumpaivoice.com/showcase" target="_blank" style="color: white; text-decoration: none; font-weight: bold;">Check out Trump AI videos created by others →</a>
147
- # </h3>
148
- # </div>
149
- # </div>
150
- # """, padding=False)
151
-
152
- # Powered by link - small text
153
- gr.HTML("""
154
- <div style="text-align: center; margin: 0px auto -5px auto;">
155
- <p style="margin: 0; font-size: 16px; color: #999; font-weight: 400;">
156
- powered by <a href="https://donaldtrumpaivoice.com/" target="_blank" style="color: #667eea; text-decoration: none;">donaldtrumpaivoice.com</a>
157
- </p>
158
- </div>
159
- """, padding=False)
160
-
161
- # Simple description text - third
162
- # gr.HTML("""
163
- # <div style="text-align: center; margin: 15px auto 30px auto; max-width: 500px;">
164
- # <p style="color: #666; margin: 0; font-size: 1em; font-weight: 500; line-height: 1.4;">
165
- # 🔥 Try the most advanced Trump AI Voice and Video generator for FREE at
166
- # <a href="https://donaldtrumpaivoice.com/" target="_blank" style="color: #667eea; text-decoration: none; font-weight: bold;">donaldtrumpaivoice.com</a>!
167
- # </p>
168
- # </div>
169
- # """)
170
-
171
- with gr.Row():
172
- with gr.Column(scale=2):
173
- text_input = gr.Textbox(
174
- label="📝 Input Text",
175
- lines=4,
176
- placeholder="Enter what you want Trump to say...",
177
- value="Hello everyone, this is a demonstration of the Trump AI Voice system with real-time status monitoring."
178
- )
179
-
180
- with gr.Column(scale=1):
181
- word_num_slider = gr.Slider(
182
- 10, 30, value=20, step=1,
183
- label="⏱️ Duration (Word Count)"
184
- )
185
-
186
- submit_btn = gr.Button(
187
- "🚀 Generate Trump AI Voice",
188
- variant="primary",
189
- size="lg"
190
- )
191
-
192
- with gr.Row():
193
- status_output = gr.Textbox(
194
- label="📊 Status",
195
- interactive=False,
196
- placeholder="Waiting for generation..."
197
- )
198
-
199
- # Action buttons that will show after task completion
200
- with gr.Row():
201
- action_links = gr.HTML(visible=False)
202
-
203
- with gr.Row():
204
- audio_output = gr.Audio(
205
- label="🎵 Trump AI Voice",
206
- interactive=False
207
- )
208
-
209
- with gr.Row():
210
- task_info = gr.Textbox(
211
- label="📋 AI Rewritten Text with Latest News",
212
- interactive=False,
213
- lines=12,
214
- placeholder="AI rewritten text with the latest news will be shown here..."
215
- )
216
-
217
- # Powered by link - small text
218
- gr.HTML("""
219
- <div style="text-align: center; margin: 0px auto -5px auto;">
220
- <p style="margin: 0; font-size: 16px; color: #999; font-weight: 400;">
221
- Click <a href="https://donaldtrumpaivoice.com/showcase" target="_blank" style="color: #667eea; text-decoration: none;"> trump ai voices showcase </a> to see more videos
222
- </p>
223
- </div>
224
- """, padding=False)
225
-
226
- # Hidden state to store task_url
227
- task_url_state = gr.State("")
228
-
229
- # Bind event
230
- submit_btn.click(
231
- generate_trump_voice_with_realtime_updates,
232
- inputs=[text_input, word_num_slider],
233
- outputs=[status_output, audio_output, task_info, action_links, task_url_state]
234
- )
235
-
236
- if __name__ == "__main__":
237
  demo.launch()
 
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_trump_voice_with_realtime_updates(text, word_num, request: gr.Request):
13
+ """
14
+ Trump 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] > 3:
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://donaldtrumpaivoice.com/#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://donaldtrumpaivoice.com/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
+ # Create action buttons HTML
78
+ action_buttons_html = f"""
79
+ <div style='display: flex; justify-content: center; gap: 30px; margin: 25px 0; padding: 20px;'>
80
+ <a href='https://donaldtrumpaivoice.com/#generator' target='_blank' style='
81
+ display: inline-flex;
82
+ align-items: center;
83
+ justify-content: center;
84
+ padding: 16px 32px;
85
+ background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
86
+ color: white;
87
+ text-decoration: none;
88
+ border-radius: 12px;
89
+ font-weight: 600;
90
+ font-size: 16px;
91
+ text-align: center;
92
+ min-width: 160px;
93
+ box-shadow: 0 4px 15px rgba(102, 126, 234, 0.4);
94
+ transition: all 0.3s ease;
95
+ border: none;
96
+ '>🎬 Generate Video</a>
97
+ <a href='{task_url}' target='_blank' style='
98
+ display: inline-flex;
99
+ align-items: center;
100
+ justify-content: center;
101
+ padding: 16px 32px;
102
+ background: linear-gradient(135deg, #11998e 0%, #38ef7d 100%);
103
+ color: white;
104
+ text-decoration: none;
105
+ border-radius: 12px;
106
+ font-weight: 600;
107
+ font-size: 16px;
108
+ text-align: center;
109
+ min-width: 160px;
110
+ box-shadow: 0 4px 15px rgba(17, 153, 142, 0.4);
111
+ transition: all 0.3s ease;
112
+ border: none;
113
+ '>👀 Check Generate Details</a>
114
+ </div>
115
+ """
116
+ yield f"✅ success!!!", voice_url, text_final, gr.update(value=action_buttons_html, visible=True), task_url
117
+ return "✅ Generation successful!", voice_url, "success", gr.update(value=action_buttons_html, visible=True), task_url
118
+ elif status in ['failed', 'voice_error', 'no_credits']:
119
+ yield "❌ Generation failed!", None, None, gr.update(visible=False), ""
120
+ return "❌ Generation failed!", None, None, gr.update(visible=False), ""
121
+ else:
122
+ 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
123
+ return "❌ Generation failed!", None, None, gr.update(visible=False), ""
124
+ except Exception as e:
125
+ error_msg = f"Generation failed: {str(e)}"
126
+ yield error_msg, None, f"❌ Error message: {error_msg}", gr.update(visible=False), ""
127
+ return error_msg, None, f"❌ Error message: {error_msg}", gr.update(visible=False), ""
128
+
129
+ # Create Gradio Interface
130
+ with gr.Blocks(title="Donald Trump AI Voice", theme=gr.themes.Soft()) as demo:
131
+
132
+ # Main title - at the top
133
+ gr.HTML("""
134
+ <div style="text-align: center; margin: 5px auto 0px auto; max-width: 800px;">
135
+ <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);">
136
+ 🎤 Trump AI Voice
137
+ </h1>
138
+ </div>
139
+ """, padding=False)
140
+
141
+ # # Showcase link banner - second
142
+ # gr.HTML("""
143
+ # <div style="text-align: center; margin: 0px auto 40px auto; max-width: 600px;">
144
+ # <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);">
145
+ # <h3 style="color: white; margin: 0; font-size: 18px;">
146
+ # 🎬 <a href="https://donaldtrumpaivoice.com/showcase" target="_blank" style="color: white; text-decoration: none; font-weight: bold;">Check out Trump AI videos created by others →</a>
147
+ # </h3>
148
+ # </div>
149
+ # </div>
150
+ # """, padding=False)
151
+
152
+ # Powered by link - small text
153
+ gr.HTML("""
154
+ <div style="text-align: center; margin: 0px auto -5px auto;">
155
+ <p style="margin: 0; font-size: 16px; color: #999; font-weight: 400;">
156
+ powered by <a href="https://donaldtrumpaivoice.com/" target="_blank" style="color: #667eea; text-decoration: none;">donaldtrumpaivoice.com</a>
157
+ </p>
158
+ </div>
159
+ """, padding=False)
160
+
161
+ # Simple description text - third
162
+ # gr.HTML("""
163
+ # <div style="text-align: center; margin: 15px auto 30px auto; max-width: 500px;">
164
+ # <p style="color: #666; margin: 0; font-size: 1em; font-weight: 500; line-height: 1.4;">
165
+ # 🔥 Try the most advanced Trump AI Voice and Video generator for FREE at
166
+ # <a href="https://donaldtrumpaivoice.com/" target="_blank" style="color: #667eea; text-decoration: none; font-weight: bold;">donaldtrumpaivoice.com</a>!
167
+ # </p>
168
+ # </div>
169
+ # """)
170
+
171
+ with gr.Row():
172
+ with gr.Column(scale=2):
173
+ text_input = gr.Textbox(
174
+ label="📝 Input Text",
175
+ lines=4,
176
+ placeholder="Enter what you want Trump to say...",
177
+ value="Hello everyone, this is a demonstration of the Trump AI Voice system with real-time status monitoring."
178
+ )
179
+
180
+ with gr.Column(scale=1):
181
+ word_num_slider = gr.Slider(
182
+ 10, 50, value=30, step=1,
183
+ label="⏱️ Duration (Word Count)"
184
+ )
185
+
186
+ submit_btn = gr.Button(
187
+ "🚀 Generate Trump AI Voice",
188
+ variant="primary",
189
+ size="lg"
190
+ )
191
+
192
+ with gr.Row():
193
+ status_output = gr.Textbox(
194
+ label="📊 Status",
195
+ interactive=False,
196
+ placeholder="Waiting for generation..."
197
+ )
198
+
199
+ # Action buttons that will show after task completion
200
+ with gr.Row():
201
+ action_links = gr.HTML(visible=False)
202
+
203
+ with gr.Row():
204
+ audio_output = gr.Audio(
205
+ label="🎵 Trump AI Voice",
206
+ interactive=False
207
+ )
208
+
209
+ with gr.Row():
210
+ task_info = gr.Textbox(
211
+ label="📋 AI Rewritten Text with Latest News",
212
+ interactive=False,
213
+ lines=12,
214
+ placeholder="AI rewritten text with the latest news will be shown here..."
215
+ )
216
+
217
+ # Powered by link - small text
218
+ gr.HTML("""
219
+ <div style="text-align: center; margin: 0px auto -5px auto;">
220
+ <p style="margin: 0; font-size: 16px; color: #999; font-weight: 400;">
221
+ Click <a href="https://donaldtrumpaivoice.com/showcase" target="_blank" style="color: #667eea; text-decoration: none;"> trump ai voices showcase </a> to see more videos
222
+ </p>
223
+ </div>
224
+ """, padding=False)
225
+
226
+ # Hidden state to store task_url
227
+ task_url_state = gr.State("")
228
+
229
+ # Bind event
230
+ submit_btn.click(
231
+ generate_trump_voice_with_realtime_updates,
232
+ inputs=[text_input, word_num_slider],
233
+ outputs=[status_output, audio_output, task_info, action_links, task_url_state]
234
+ )
235
+
236
+ if __name__ == "__main__":
237
  demo.launch()
requirements.txt CHANGED
@@ -1,4 +1,4 @@
1
- gradio>=4.0.0
2
- requests>=2.31.0
3
- supabase>=2.0.0
4
  python-dotenv>=1.0.0
 
1
+ gradio>=4.0.0
2
+ requests>=2.31.0
3
+ supabase>=2.0.0
4
  python-dotenv>=1.0.0
util.py CHANGED
@@ -1,116 +1,116 @@
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
- except Exception as e:
20
- print(f"OneKey: {e}")
21
- # exit(1)
22
-
23
-
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
- class VideoTemplate:
47
- Outdoor = "outdoor"
48
- UsFlag = "us-flag"
49
- WhiteHouse = "white-house"
50
-
51
- def create_task_v3(task_type, text, word_num, is_rewrite):
52
- import json
53
- is_rewrite = False
54
- url = f"{BackendUrl}/trump_process_ctx_api"
55
- headers = {
56
- "Content-Type": "application/json"
57
- }
58
- data = {
59
- "template": VideoTemplate.UsFlag,
60
- "text": text,
61
- "word_num": word_num,
62
- "is_rewrite": is_rewrite,
63
- "watermark": True,
64
- "type": task_type,
65
- "cost_credits": 2,
66
- "user_uuid": UserUuid,
67
- "secret_key": "219ngu"
68
- }
69
- try:
70
- resp = requests.post(url, headers=headers, data=json.dumps(data), timeout=60)
71
- if not resp.ok:
72
- print(f"调用trump_process_ctx_api失败: {resp.status_code} {resp.text}")
73
- return None
74
- try:
75
- ctx_json = resp.json()
76
- except Exception as e:
77
- print(f"解析trump_process_ctx_api返回异常: {e}")
78
- return None
79
- if not ctx_json or ctx_json.get("code") != 0 or not ctx_json.get("data") or not ctx_json["data"].get("task_id"):
80
- print(f"trump_process_ctx_api返回异常: {ctx_json}")
81
- return None
82
- return {
83
- "task_id": ctx_json["data"]["task_id"],
84
- "uuid": ctx_json["data"]["task_uuid"],
85
- "status": "created",
86
- "message": "任务创建成功,后台处理中"
87
- }
88
- except Exception as err:
89
- print(f"create_task_v3异常: {err}")
90
- return None
91
-
92
- def get_task_result(task_id):
93
- # Poll for task status and result
94
- url = f"{TrumpAiUrl}/api/task-status/uuid/{task_id}"
95
- headers = {
96
- "Content-Type": "application/json",
97
- "Authorization": f"Bearer {ApiKey}"
98
- }
99
- print(url)
100
- try:
101
- resp = requests.get(url, headers=headers, timeout=30)
102
- resp.raise_for_status()
103
- result = resp.json()
104
- return result
105
- except Exception as e:
106
- return {}
107
-
108
-
109
- if __name__ == "__main__":
110
-
111
- task_type = "voice"
112
- text = "Hello, this is a test message for Trump AI Voice."
113
- word_num = 10
114
- is_rewrite = True
115
- task_result = create_task_v2(task_type, text, word_num, is_rewrite)
116
- print(f"task_result: {task_result}")
 
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
+ except Exception as e:
20
+ print(f"OneKey: {e}")
21
+ # exit(1)
22
+
23
+
24
+ # 创建Supabase客户端
25
+ supabase: Client = create_client(SUPABASE_URL, SUPABASE_KEY)
26
+
27
+ # 任务状态枚举
28
+ class TaskStatus:
29
+ Created = "created"
30
+ Processing = "processing"
31
+ TextRewrited = "text_rewrited"
32
+ TextFormated = "text_formated"
33
+ VoiceCompleted = "voice_completed"
34
+ VoiceError = "voice_error"
35
+ VideoCompleted = "video_completed"
36
+ VideoPublished = "video_published"
37
+ VideoError = "video_error"
38
+ Completed = "completed"
39
+ Failed = "failed"
40
+ Cancelled = "cancelled"
41
+ NoCredits = "no_credits"
42
+
43
+ # 视频模板枚举
44
+ class VideoTemplate:
45
+ Outdoor = "outdoor"
46
+ UsFlag = "us-flag"
47
+ WhiteHouse = "white-house"
48
+
49
+ def create_task_v3(task_type, text, word_num, is_rewrite):
50
+ import json
51
+ is_rewrite = False
52
+ url = f"{BackendUrl}/trump_process_ctx_api_v2"
53
+ headers = {
54
+ "Content-Type": "application/json"
55
+ }
56
+ print(url)
57
+ data = {
58
+ "video_template": VideoTemplate.UsFlag,
59
+ "speaker_template": "trump",
60
+ "text": text,
61
+ "word_num": word_num,
62
+ "is_rewrite": False,
63
+ "watermark": True,
64
+ "type": "voice",
65
+ "cost_credits": 2,
66
+ "user_uuid": UserUuid,
67
+ "secret_key": "219ngu"
68
+ }
69
+ try:
70
+ resp = requests.post(url, headers=headers, data=json.dumps(data), timeout=60)
71
+ if not resp.ok:
72
+ print(f"调用trump_process_ctx_api失败: {resp.status_code} {resp.text}")
73
+ return None
74
+ try:
75
+ ctx_json = resp.json()
76
+ except Exception as e:
77
+ print(f"解析trump_process_ctx_api返回异常: {e}")
78
+ return None
79
+ if not ctx_json or ctx_json.get("code") != 0 or not ctx_json.get("data") or not ctx_json["data"].get("task_id"):
80
+ print(f"trump_process_ctx_api返回异常: {ctx_json}")
81
+ return None
82
+ return {
83
+ "task_id": ctx_json["data"]["task_id"],
84
+ "uuid": ctx_json["data"]["task_uuid"],
85
+ "status": "created",
86
+ "message": "任务创建成功,后台处理中"
87
+ }
88
+ except Exception as err:
89
+ print(f"create_task_v3异常: {err}")
90
+ return None
91
+
92
+ def get_task_result(task_id):
93
+ # Poll for task status and result
94
+ url = f"{TrumpAiUrl}/api/task-status/uuid/{task_id}"
95
+ headers = {
96
+ "Content-Type": "application/json",
97
+ "Authorization": f"Bearer {ApiKey}"
98
+ }
99
+ print(url)
100
+ try:
101
+ resp = requests.get(url, headers=headers, timeout=30)
102
+ resp.raise_for_status()
103
+ result = resp.json()
104
+ return result
105
+ except Exception as e:
106
+ return {}
107
+
108
+
109
+ if __name__ == "__main__":
110
+
111
+ task_type = "voice"
112
+ text = "Hello, this is a test message for Trump AI Voice."
113
+ word_num = 10
114
+ is_rewrite = True
115
+ task_result = create_task_v2(task_type, text, word_num, is_rewrite)
116
+ print(f"task_result: {task_result}")