alexx-ai commited on
Commit
e4716f1
·
verified ·
1 Parent(s): 6b45a3c

Create app.py

Browse files
Files changed (1) hide show
  1. app.py +132 -0
app.py ADDED
@@ -0,0 +1,132 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import os
2
+ import gradio as gr
3
+ import requests
4
+ import time
5
+ import random
6
+ import string
7
+ import secrets
8
+ import json
9
+
10
+ REG_URL = os.getenv('REG_URL')
11
+ VB_ADD = os.getenv('VB_ADD')
12
+ TTS_URL = os.getenv('TTS_URL')
13
+
14
+ def generate_random_email():
15
+ username = ''.join(random.choices(string.ascii_lowercase + string.digits, k=12))
16
+ return f"{username}@boxmach.com"
17
+
18
+ def generate_random_sign():
19
+ return secrets.token_hex(16).upper()
20
+
21
+ def register_user():
22
+ url = REG_URL
23
+ email = generate_random_email()
24
+ timestamp = str(int(time.time() * 1000))
25
+ sign = generate_random_sign()
26
+
27
+ data = {
28
+ "email": email,
29
+ "password": "631929e14ba175f4ef95151d6f630c92",
30
+ "equipment_code": "emulator_arm64",
31
+ "first_name": "MOON",
32
+ "last_name": "VoxBox",
33
+ "information_sources": "200053",
34
+ "lang": "EN",
35
+ "source_site": "null",
36
+ "platform": "phone-app",
37
+ "from_language": "EN",
38
+ "operating_system": "android",
39
+ "token": "",
40
+ "timestamp": timestamp,
41
+ "sign": sign
42
+ }
43
+
44
+ headers = {
45
+ "Content-Type": "application/x-www-form-urlencoded",
46
+ "Accept-Encoding": "gzip, deflate, br",
47
+ "User-Agent": "okhttp/4.10.0"
48
+ }
49
+
50
+ response = requests.post(url, data=data, headers=headers)
51
+ if response.status_code == 200:
52
+ resp_json = response.json()
53
+ if resp_json.get("code") == 200:
54
+ data = resp_json["data"]
55
+ return data["member_id"], email, data["token"]
56
+ return None, None, None
57
+
58
+ def add_vip_status(member_id, email):
59
+ url = VB_ADD
60
+ create_time = int(time.time())
61
+ data = {
62
+ "member_id": member_id,
63
+ "vip_type": "1",
64
+ "create_time": str(create_time),
65
+ "email": email.replace("@", "%40"),
66
+ "product_type": "5"
67
+ }
68
+ headers = {
69
+ "Content-Type": "application/x-www-form-urlencoded",
70
+ "Accept-Encoding": "gzip, deflate, br",
71
+ "User-Agent": "okhttp/4.10.0"
72
+ }
73
+ requests.post(url, data=data, headers=headers)
74
+
75
+ def synthesize_tts_full(text, voice_id, similarity_boost, speed, stability, style):
76
+ member_id, email, token = register_user()
77
+ if not token:
78
+ return "❌ Registration failed"
79
+
80
+ add_vip_status(member_id, email)
81
+
82
+ url = TTS_URL
83
+ headers = {
84
+ "Token": token,
85
+ "Product-Id": "200053",
86
+ "Content-Type": "application/json; charset=utf-8",
87
+ "Accept-Encoding": "gzip, deflate, br",
88
+ "User-Agent": "okhttp/4.10.0"
89
+ }
90
+
91
+ payload = {
92
+ "raw_text": text,
93
+ "voice_id": voice_id,
94
+ "product_id": "200053",
95
+ "convert_data": [
96
+ {
97
+ "volume": "50",
98
+ "voice_id": voice_id,
99
+ "pos": 0,
100
+ "similarity_boost": float(similarity_boost),
101
+ "style": int(style),
102
+ "text": text,
103
+ "emotion_name": "Default",
104
+ "accent": "en-US",
105
+ "speed": str(speed),
106
+ "stability": float(stability)
107
+ }
108
+ ],
109
+ "is_audition": 0
110
+ }
111
+
112
+ response = requests.post(url, headers=headers, data=json.dumps(payload))
113
+ try:
114
+ return json.dumps(response.json(), indent=2)
115
+ except:
116
+ return f"❌ Error:\n{response.text}"
117
+
118
+ # Gradio UI
119
+ gr.Interface(
120
+ fn=synthesize_tts_full,
121
+ inputs=[
122
+ gr.Textbox(label="Text to Synthesize", lines=4, value="एक बार की बात है, एक छोटे से गाँव में चार दोस्त रहते थे..."),
123
+ gr.Textbox(label="Voice ID", value="67ada33c-5d4b-11ee-a861-00163e2ac61b"),
124
+ gr.Textbox(label="Similarity Boost", value="0.95"),
125
+ gr.Textbox(label="Speed", value="1"),
126
+ gr.Textbox(label="Stability", value="0.51"),
127
+ gr.Textbox(label="Style", value="0")
128
+ ],
129
+ outputs=gr.Textbox(label="TTS API Response", lines=20),
130
+ title="🗣️ VoxBox TTS Generator (Auto Register + VIP)",
131
+ description="Generate TTS using VoxBox API. Input voice parameters below. A temporary account will be registered automatically."
132
+ ).launch()