selfit-camera commited on
Commit
c0fdff8
·
1 Parent(s): 0151981
Files changed (5) hide show
  1. README.md +5 -5
  2. app.py +215 -0
  3. push.sh +3 -0
  4. requirements.txt +4 -0
  5. util.py +116 -0
README.md CHANGED
@@ -1,14 +1,14 @@
1
  ---
2
  title: Trump Ai Voice
3
- emoji: 📊
4
- colorFrom: gray
5
- colorTo: blue
6
  sdk: gradio
7
- sdk_version: 5.38.2
8
  app_file: app.py
9
  pinned: false
10
  license: mit
11
- short_description: Trump-Ai-Voice
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
app.py ADDED
@@ -0,0 +1,215 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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, please go to https://donaldtrumpaivoice.com for more"
26
+ yield msg, None, msg, gr.update(visible=False), ""
27
+ return msg, None, msg, gr.update(visible=False), ""
28
+
29
+ if not text or len(text.strip()) < 3:
30
+ return "Text too short, please enter at least 3 characters", None, "No task information", gr.update(visible=False), ""
31
+
32
+ try:
33
+ task_type = "voice"
34
+
35
+ # Create task
36
+ task_result = create_task_v3(task_type, text.strip(), word_num, is_rewrite=False)
37
+ if not task_result:
38
+ return "Failed to create task", None, "Task creation failed", gr.update(visible=False), ""
39
+ else:
40
+ yield "Task created successfully", None, "Task creation successful", gr.update(visible=False), ""
41
+
42
+ max_polls = 300
43
+ poll_interval = 1
44
+ task_url = f"https://donaldtrumpaivoice.com/task/{task_result['uuid']}"
45
+
46
+ for i in range(max_polls):
47
+ time.sleep(poll_interval)
48
+ task = get_task_result(task_result['uuid'])
49
+ # print(task, i, "get_task_result")
50
+ if task.get('data', {}):
51
+ status = task.get('data').get('status', '')
52
+ text_final = task.get('data').get('text_final', '')
53
+ if status in ['completed',]:
54
+ voice_url = task.get('data').get('voice_url', '')
55
+ # Create action buttons HTML
56
+ action_buttons_html = f"""
57
+ <div style='display: flex; justify-content: center; gap: 30px; margin: 25px 0; padding: 20px;'>
58
+ <a href='https://donaldtrumpaivoice.com/#generator' target='_blank' style='
59
+ display: inline-flex;
60
+ align-items: center;
61
+ justify-content: center;
62
+ padding: 16px 32px;
63
+ background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
64
+ color: white;
65
+ text-decoration: none;
66
+ border-radius: 12px;
67
+ font-weight: 600;
68
+ font-size: 16px;
69
+ text-align: center;
70
+ min-width: 160px;
71
+ box-shadow: 0 4px 15px rgba(102, 126, 234, 0.4);
72
+ transition: all 0.3s ease;
73
+ border: none;
74
+ '>🎬 Generate Video</a>
75
+ <a href='{task_url}' target='_blank' style='
76
+ display: inline-flex;
77
+ align-items: center;
78
+ justify-content: center;
79
+ padding: 16px 32px;
80
+ background: linear-gradient(135deg, #11998e 0%, #38ef7d 100%);
81
+ color: white;
82
+ text-decoration: none;
83
+ border-radius: 12px;
84
+ font-weight: 600;
85
+ font-size: 16px;
86
+ text-align: center;
87
+ min-width: 160px;
88
+ box-shadow: 0 4px 15px rgba(17, 153, 142, 0.4);
89
+ transition: all 0.3s ease;
90
+ border: none;
91
+ '>👀 Check Generate Details</a>
92
+ </div>
93
+ """
94
+ yield f"✅ success!!!", voice_url, text_final, gr.update(value=action_buttons_html, visible=True), task_url
95
+ return "✅ Generation successful!", voice_url, "success", gr.update(value=action_buttons_html, visible=True), task_url
96
+ elif status in ['failed', 'voice_error', 'no_credits']:
97
+ yield "❌ Generation failed!", None, None, gr.update(visible=False), ""
98
+ return "❌ Generation failed!", None, None, gr.update(visible=False), ""
99
+ else:
100
+ 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
101
+ return "❌ Generation failed!", None, None, gr.update(visible=False), ""
102
+ except Exception as e:
103
+ error_msg = f"Generation failed: {str(e)}"
104
+ yield error_msg, None, f"❌ Error message: {error_msg}", gr.update(visible=False), ""
105
+ return error_msg, None, f"❌ Error message: {error_msg}", gr.update(visible=False), ""
106
+
107
+ # Create Gradio Interface
108
+ with gr.Blocks(title="Donald Trump AI Voice", theme=gr.themes.Soft()) as demo:
109
+
110
+ # Main title - at the top
111
+ gr.HTML("""
112
+ <div style="text-align: center; margin: 5px auto 0px auto; max-width: 800px;">
113
+ <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);">
114
+ 🎤 Trump AI Voice
115
+ </h1>
116
+ </div>
117
+ """, padding=False)
118
+
119
+ # # Showcase link banner - second
120
+ # gr.HTML("""
121
+ # <div style="text-align: center; margin: 0px auto 40px auto; max-width: 600px;">
122
+ # <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);">
123
+ # <h3 style="color: white; margin: 0; font-size: 18px;">
124
+ # 🎬 <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>
125
+ # </h3>
126
+ # </div>
127
+ # </div>
128
+ # """, padding=False)
129
+
130
+ # Powered by link - small text
131
+ gr.HTML("""
132
+ <div style="text-align: center; margin: 0px auto -5px auto;">
133
+ <p style="margin: 0; font-size: 16px; color: #999; font-weight: 400;">
134
+ powered by <a href="https://donaldtrumpaivoice.com/" target="_blank" style="color: #667eea; text-decoration: none;">donaldtrumpaivoice.com</a>
135
+ </p>
136
+ </div>
137
+ """, padding=False)
138
+
139
+ # Simple description text - third
140
+ # gr.HTML("""
141
+ # <div style="text-align: center; margin: 15px auto 30px auto; max-width: 500px;">
142
+ # <p style="color: #666; margin: 0; font-size: 1em; font-weight: 500; line-height: 1.4;">
143
+ # 🔥 Try the most advanced Trump AI Voice and Video generator for FREE at
144
+ # <a href="https://donaldtrumpaivoice.com/" target="_blank" style="color: #667eea; text-decoration: none; font-weight: bold;">donaldtrumpaivoice.com</a>!
145
+ # </p>
146
+ # </div>
147
+ # """)
148
+
149
+ with gr.Row():
150
+ with gr.Column(scale=2):
151
+ text_input = gr.Textbox(
152
+ label="📝 Input Text",
153
+ lines=4,
154
+ placeholder="Enter what you want Trump to say...",
155
+ value="Hello everyone, this is a demonstration of the Trump AI Voice system with real-time status monitoring."
156
+ )
157
+
158
+ with gr.Column(scale=1):
159
+ word_num_slider = gr.Slider(
160
+ 10, 30, value=20, step=1,
161
+ label="⏱️ Duration (Word Count)"
162
+ )
163
+
164
+ submit_btn = gr.Button(
165
+ "🚀 Generate Trump AI Voice",
166
+ variant="primary",
167
+ size="lg"
168
+ )
169
+
170
+ with gr.Row():
171
+ status_output = gr.Textbox(
172
+ label="📊 Status",
173
+ interactive=False,
174
+ placeholder="Waiting for generation..."
175
+ )
176
+
177
+ with gr.Row():
178
+ audio_output = gr.Audio(
179
+ label="🎵 Trump AI Voice",
180
+ interactive=False
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
+ task_info = gr.Textbox(
189
+ label="📋 AI Rewritten Text with Latest News",
190
+ interactive=False,
191
+ lines=12,
192
+ placeholder="AI rewritten text with the latest news will be shown here..."
193
+ )
194
+
195
+ # Powered by link - small text
196
+ gr.HTML("""
197
+ <div style="text-align: center; margin: 0px auto -5px auto;">
198
+ <p style="margin: 0; font-size: 16px; color: #999; font-weight: 400;">
199
+ Click <a href="https://donaldtrumpaivoice.com/showcase" target="_blank" style="color: #667eea; text-decoration: none;"> trump ai voices showcase </a> to see more videos
200
+ </p>
201
+ </div>
202
+ """, padding=False)
203
+
204
+ # Hidden state to store task_url
205
+ task_url_state = gr.State("")
206
+
207
+ # Bind event
208
+ submit_btn.click(
209
+ generate_trump_voice_with_realtime_updates,
210
+ inputs=[text_input, word_num_slider],
211
+ outputs=[status_output, audio_output, task_info, action_links, task_url_state]
212
+ )
213
+
214
+ if __name__ == "__main__":
215
+ 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,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}")