Spaces:
Running
Running
Navid Arabi
commited on
Commit
·
d271760
1
Parent(s):
2731b0f
test
Browse files- app.py +2 -33
- import_db.py +71 -0
app.py
CHANGED
@@ -1,38 +1,7 @@
|
|
1 |
-
import mysql.connector
|
2 |
-
from mysql.connector import Error
|
3 |
-
|
4 |
-
|
5 |
-
config = {
|
6 |
-
"host": "annotation-db.apps.teh2.abrhapaas.com",
|
7 |
-
"user": "navid",
|
8 |
-
"password": "ZUJSK!1V!PF4ZEnIaylX",
|
9 |
-
"charset": "utf8mb4",
|
10 |
-
"port": 32107,
|
11 |
-
"use_unicode": True
|
12 |
-
}
|
13 |
-
|
14 |
-
|
15 |
import gradio as gr
|
16 |
|
17 |
def greet(name):
|
18 |
-
|
19 |
-
conn = mysql.connector.connect(**config)
|
20 |
-
if conn.is_connected():
|
21 |
-
cursor = conn.cursor()
|
22 |
-
cursor.execute("SELECT VERSION()")
|
23 |
-
version = cursor.fetchone()
|
24 |
-
return f"🟢 MySQL Server Version: {version[0]}"
|
25 |
-
|
26 |
-
except Error as e:
|
27 |
-
return f"❌ error: {e}"
|
28 |
-
|
29 |
-
finally:
|
30 |
-
if 'cursor' in locals():
|
31 |
-
cursor.close()
|
32 |
-
if 'conn' in locals() and conn.is_connected():
|
33 |
-
conn.close()
|
34 |
-
print("⛔️Closed.")
|
35 |
-
|
36 |
|
37 |
-
demo = gr.Interface(fn=greet,
|
38 |
demo.launch()
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
import gradio as gr
|
2 |
|
3 |
def greet(name):
|
4 |
+
return name
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
5 |
|
6 |
+
demo = gr.Interface(fn=greet, outputs="text")
|
7 |
demo.launch()
|
import_db.py
ADDED
@@ -0,0 +1,71 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
from datasets import load_dataset
|
2 |
+
from huggingface_hub import login
|
3 |
+
import os
|
4 |
+
|
5 |
+
token = os.environ.get('HF_TOKEN')
|
6 |
+
|
7 |
+
login(token=token)
|
8 |
+
|
9 |
+
dataset = load_dataset("navidved/channelb-raw-data", split="train", trust_remote_code=True)
|
10 |
+
|
11 |
+
|
12 |
+
print(dataset.column_names)
|
13 |
+
print(dataset[0])
|
14 |
+
|
15 |
+
|
16 |
+
|
17 |
+
import mysql.connector
|
18 |
+
|
19 |
+
# اتصال به دیتابیس (مقدارها رو بر اساس نیاز ست کن)
|
20 |
+
conn = mysql.connector.connect(
|
21 |
+
host="",
|
22 |
+
user="",
|
23 |
+
password="",
|
24 |
+
database="",
|
25 |
+
port=32107,
|
26 |
+
charset="utf8mb4",
|
27 |
+
use_unicode=True
|
28 |
+
)
|
29 |
+
|
30 |
+
cursor = conn.cursor()
|
31 |
+
|
32 |
+
# ساخت جدول اگر وجود نداشت
|
33 |
+
cursor.execute("""
|
34 |
+
CREATE TABLE IF NOT EXISTS tts_data (
|
35 |
+
id INT AUTO_INCREMENT PRIMARY KEY,
|
36 |
+
filename VARCHAR(255),
|
37 |
+
sentence TEXT
|
38 |
+
)
|
39 |
+
""")
|
40 |
+
|
41 |
+
# تعداد رکورد در هر batch
|
42 |
+
batch_size = 1000
|
43 |
+
batch = []
|
44 |
+
|
45 |
+
for i, item in enumerate(dataset):
|
46 |
+
filename = f"sample_{i}.wav"
|
47 |
+
sentence = item["sentence"]
|
48 |
+
batch.append((filename, sentence))
|
49 |
+
|
50 |
+
# وقتی batch کامل شد
|
51 |
+
if len(batch) == batch_size:
|
52 |
+
cursor.executemany(
|
53 |
+
"INSERT INTO tts_data (filename, sentence) VALUES (%s, %s)", batch
|
54 |
+
)
|
55 |
+
conn.commit()
|
56 |
+
print(f"✅ {i + 1} رکورد تا الان ثبت شد")
|
57 |
+
batch = []
|
58 |
+
|
59 |
+
# ثبت رکوردهای باقیمانده (کمتر از batch_size)
|
60 |
+
if batch:
|
61 |
+
cursor.executemany(
|
62 |
+
"INSERT INTO tts_data (filename, sentence) VALUES (%s, %s)", batch
|
63 |
+
)
|
64 |
+
conn.commit()
|
65 |
+
print(f"✅ آخرین {len(batch)} رکورد هم ثبت شد")
|
66 |
+
|
67 |
+
# بستن ارتباط
|
68 |
+
cursor.close()
|
69 |
+
conn.close()
|
70 |
+
|
71 |
+
|