Spaces:
Running
Running
Update app.py
Browse files
app.py
CHANGED
@@ -1,20 +1,27 @@
|
|
1 |
import os, time, requests, gradio as gr
|
2 |
-
print("Gradio version:", gr.__version__)
|
3 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
4 |
ASR_API_URL = os.getenv("ASR_API_URL")
|
5 |
AUTH_TOKEN = os.getenv("AUTH_TOKEN")
|
6 |
-
|
7 |
if not ASR_API_URL or not AUTH_TOKEN:
|
8 |
print("⚠️ Warning: ASR_API_URL or AUTH_TOKEN is not set; calls will fail.")
|
9 |
|
|
|
10 |
def transcribe_audio(file_path: str):
|
11 |
if not ASR_API_URL or not AUTH_TOKEN:
|
12 |
return "❌ Error: ASR_API_URL or AUTH_TOKEN is not set.", ""
|
13 |
|
14 |
-
headers = {
|
15 |
-
|
16 |
-
|
17 |
-
}
|
18 |
start = time.time()
|
19 |
try:
|
20 |
with open(file_path, "rb") as f:
|
@@ -26,11 +33,11 @@ def transcribe_audio(file_path: str):
|
|
26 |
elapsed = time.time() - start
|
27 |
if resp.status_code == 200:
|
28 |
data = resp.json()
|
29 |
-
|
30 |
-
|
31 |
-
|
32 |
-
return f"❌ Error: {resp.status_code}, {resp.text}", ""
|
33 |
|
|
|
34 |
custom_css = """
|
35 |
#gooya-title{color:#fff;background:linear-gradient(90deg,#224CA5 0%,#2CD8D5 100%);
|
36 |
border-radius:12px;padding:20px 10px;margin-bottom:12px;}
|
@@ -38,18 +45,17 @@ custom_css = """
|
|
38 |
padding:6px 16px;font-size:.97rem;margin-top:4px;}
|
39 |
"""
|
40 |
|
|
|
41 |
with gr.Blocks(css=custom_css, title="Gooya ASR v1.4") as demo:
|
42 |
gr.HTML(
|
43 |
"""
|
44 |
<div id="gooya-title">
|
45 |
-
<h1 style='margin-bottom:10px;font-weight:800;font-size:2rem;'>
|
46 |
-
|
47 |
</h1>
|
48 |
-
<p style='font-size:1.12rem;margin-bottom:2px;'>
|
49 |
-
High-performance Persian Speech-to-Text
|
50 |
-
</p>
|
51 |
<p style='font-size:.98rem;color:#c6e8fa'>
|
52 |
-
|
53 |
</p>
|
54 |
</div>
|
55 |
"""
|
@@ -87,7 +93,9 @@ with gr.Blocks(css=custom_css, title="Gooya ASR v1.4") as demo:
|
|
87 |
- صدا باید فارسی باشد.
|
88 |
- نتیجهی رونویسی و زمان پردازش بلافاصله نمایش داده میشود.
|
89 |
|
90 |
-
برای مشاهده بنچمارکها به
|
|
|
|
|
91 |
"""
|
92 |
)
|
93 |
|
@@ -103,6 +111,8 @@ with gr.Blocks(css=custom_css, title="Gooya ASR v1.4") as demo:
|
|
103 |
outputs=[transcription_tb, processing_time_tb, audio_input],
|
104 |
)
|
105 |
|
|
|
106 |
if __name__ == "__main__":
|
107 |
-
# show_api=False
|
108 |
-
|
|
|
|
1 |
import os, time, requests, gradio as gr
|
|
|
2 |
|
3 |
+
# ---------- Hot-patch برای دورزدن باگ JSON-schema ----------
|
4 |
+
import gradio.blocks as _blocks
|
5 |
+
if not hasattr(_blocks.Blocks, "_api_info_patched"): # یک بار پَچ شود
|
6 |
+
_blocks.Blocks._api_info_patched = True
|
7 |
+
_blocks.Blocks.get_api_info = lambda self: {} # صرفاً API را غیرفعال میکنیم
|
8 |
+
|
9 |
+
print("Gradio version:", gr.__version__) # باید 4.44.0 باشد
|
10 |
+
|
11 |
+
# ---------- متغیّرهای محیطی ----------
|
12 |
ASR_API_URL = os.getenv("ASR_API_URL")
|
13 |
AUTH_TOKEN = os.getenv("AUTH_TOKEN")
|
|
|
14 |
if not ASR_API_URL or not AUTH_TOKEN:
|
15 |
print("⚠️ Warning: ASR_API_URL or AUTH_TOKEN is not set; calls will fail.")
|
16 |
|
17 |
+
# ---------- تابع پردازش ----------
|
18 |
def transcribe_audio(file_path: str):
|
19 |
if not ASR_API_URL or not AUTH_TOKEN:
|
20 |
return "❌ Error: ASR_API_URL or AUTH_TOKEN is not set.", ""
|
21 |
|
22 |
+
headers = {"accept": "application/json",
|
23 |
+
"Authorization": f"Bearer {AUTH_TOKEN}"}
|
24 |
+
|
|
|
25 |
start = time.time()
|
26 |
try:
|
27 |
with open(file_path, "rb") as f:
|
|
|
33 |
elapsed = time.time() - start
|
34 |
if resp.status_code == 200:
|
35 |
data = resp.json()
|
36 |
+
return data.get("transcription", "No transcription returned."), \
|
37 |
+
f"{data.get('time', elapsed):.2f} ثانیه"
|
38 |
+
return f"❌ Error: {resp.status_code}, {resp.text}", ""
|
|
|
39 |
|
40 |
+
# ---------- CSS ----------
|
41 |
custom_css = """
|
42 |
#gooya-title{color:#fff;background:linear-gradient(90deg,#224CA5 0%,#2CD8D5 100%);
|
43 |
border-radius:12px;padding:20px 10px;margin-bottom:12px;}
|
|
|
45 |
padding:6px 16px;font-size:.97rem;margin-top:4px;}
|
46 |
"""
|
47 |
|
48 |
+
# ---------- رابط کاربری ----------
|
49 |
with gr.Blocks(css=custom_css, title="Gooya ASR v1.4") as demo:
|
50 |
gr.HTML(
|
51 |
"""
|
52 |
<div id="gooya-title">
|
53 |
+
<h1 style='margin-bottom:10px;font-weight:800;font-size:2rem;'>Gooya ASR
|
54 |
+
<span style="font-size:1.1rem;font-weight:400;opacity:.8;">v1.4</span>
|
55 |
</h1>
|
56 |
+
<p style='font-size:1.12rem;margin-bottom:2px;'>High-performance Persian Speech-to-Text</p>
|
|
|
|
|
57 |
<p style='font-size:.98rem;color:#c6e8fa'>
|
58 |
+
Upload or record a Persian audio file (max 30 s) and instantly receive the transcription.
|
59 |
</p>
|
60 |
</div>
|
61 |
"""
|
|
|
93 |
- صدا باید فارسی باشد.
|
94 |
- نتیجهی رونویسی و زمان پردازش بلافاصله نمایش داده میشود.
|
95 |
|
96 |
+
برای مشاهده بنچمارکها به
|
97 |
+
[Persian ASR Leaderboard](https://huggingface.co/spaces/navidved/open_persian_asr_leaderboard)
|
98 |
+
مراجعه کنید.
|
99 |
"""
|
100 |
)
|
101 |
|
|
|
111 |
outputs=[transcription_tb, processing_time_tb, audio_input],
|
112 |
)
|
113 |
|
114 |
+
# ---------- اجرا ----------
|
115 |
if __name__ == "__main__":
|
116 |
+
# show_api=False => مسیر /api-info ساخته نمیشود.
|
117 |
+
# share=True => در محیطهایی که localhost قابل دسترس نیست، لینک عمومی میسازد.
|
118 |
+
demo.queue().launch(show_api=False, debug=True, share=False)
|