navidved commited on
Commit
eed5ed8
·
verified ·
1 Parent(s): 1ef7530

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +15 -81
app.py CHANGED
@@ -7,27 +7,19 @@ ASR_API_URL = os.getenv("ASR_API_URL")
7
  AUTH_TOKEN = os.getenv("AUTH_TOKEN")
8
 
9
  def transcribe_audio(file_path: str):
10
- """
11
- دریافت مسیر فایل صوتی (به‌دلیل type='filepath') و برگرداندن
12
- رونوشت و مدت زمان پردازش.
13
- """
14
  if not ASR_API_URL or not AUTH_TOKEN:
15
  return "❌ Error: ASR_API_URL or AUTH_TOKEN is not set.", ""
16
-
17
  headers = {
18
  "accept": "application/json",
19
  "Authorization": f"Bearer {AUTH_TOKEN}",
20
  }
21
  files = {"file": (file_path, open(file_path, "rb"), "audio/mpeg")}
22
-
23
  start = time.time()
24
  try:
25
  resp = requests.post(ASR_API_URL, headers=headers, files=files)
26
  except Exception as e:
27
  return f"❌ Error: {e}", ""
28
-
29
  elapsed = time.time() - start
30
-
31
  if resp.status_code == 200:
32
  data = resp.json()
33
  transcript = data.get("transcription", "No transcription returned.")
@@ -36,79 +28,21 @@ def transcribe_audio(file_path: str):
36
  else:
37
  return f"❌ Error: {resp.status_code}, {resp.text}", ""
38
 
39
- custom_css = """
40
- #gooya-title{color:#fff;
41
- background:linear-gradient(90deg,#224CA5 0%,#2CD8D5 100%);
42
- border-radius:12px;padding:20px 10px;margin-bottom:12px;}
43
- .gooya-badge{display:inline-block;background:#224CA5;color:#fff;
44
- border-radius:16px;padding:6px 16px;font-size:.97rem;margin-top:4px;}
45
- #gooya-box{background:#F7FAFF;border:1px solid #e7e9ef;border-radius:14px;
46
- padding:22px 18px;margin-top:12px;}
47
- """
48
-
49
- with gr.Blocks(css=custom_css) as demo:
50
- gr.HTML(
51
- """
52
- <div id="gooya-title">
53
- <h1 style='margin-bottom:10px;font-weight:800;font-size:2rem;'>
54
- Gooya ASR <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;'>
57
- High-performance Persian Speech-to-Text
58
- </p>
59
- <p style='font-size:.98rem;color:#c6e8fa'>
60
- Upload or record a Persian audio file (max 30 s) and instantly receive the transcription.
61
- </p>
62
- </div>
63
- """
64
- )
65
-
66
- with gr.Row():
67
- with gr.Column():
68
- audio = gr.Audio(
69
- label="Audio Input (upload or record, up to 30 s)",
70
- type="filepath",
71
- sources=["upload", "microphone"],
72
- )
73
- with gr.Column():
74
- inference_time = gr.Label(
75
- label="⏱️ Processing Time", elem_classes="gooya-badge"
76
- )
77
- transcription = gr.Textbox(
78
- label="📝 Transcription",
79
- lines=5,
80
- show_copy_button=True,
81
- placeholder="The transcription will appear here...",
82
- elem_id="gooya-textbox",
83
- )
84
-
85
- with gr.Row():
86
- btn_transcribe = gr.Button("Transcribe", variant="primary")
87
- btn_clear = gr.Button("Clear", variant="secondary")
88
-
89
- gr.Markdown(
90
- """
91
- **دستورالعمل‌ها**
92
- - حداکثر طول صدا: **۳۰ ثانیه**
93
- - صدا باید فارسی باشد.
94
- - نتیجه‌ی رونویسی و زمان پردازش بلافاصله نمایش داده می‌شود.
95
-
96
- برای مشاهده بنچمارک‌ها به [Persian ASR Leaderboard](https://huggingface.co/spaces/navidved/open_persian_asr_leaderboard) مراجعه کنید.
97
- """
98
- )
99
-
100
- btn_transcribe.click(
101
- transcribe_audio,
102
- inputs=audio,
103
- outputs=[transcription, inference_time],
104
- )
105
-
106
- btn_clear.click(
107
- lambda: ("", "", None),
108
- inputs=None,
109
- outputs=[transcription, inference_time, audio],
110
  )
 
111
 
112
  if __name__ == "__main__":
113
- demo.queue()
114
- demo.launch(share=True)
 
7
  AUTH_TOKEN = os.getenv("AUTH_TOKEN")
8
 
9
  def transcribe_audio(file_path: str):
 
 
 
 
10
  if not ASR_API_URL or not AUTH_TOKEN:
11
  return "❌ Error: ASR_API_URL or AUTH_TOKEN is not set.", ""
 
12
  headers = {
13
  "accept": "application/json",
14
  "Authorization": f"Bearer {AUTH_TOKEN}",
15
  }
16
  files = {"file": (file_path, open(file_path, "rb"), "audio/mpeg")}
 
17
  start = time.time()
18
  try:
19
  resp = requests.post(ASR_API_URL, headers=headers, files=files)
20
  except Exception as e:
21
  return f"❌ Error: {e}", ""
 
22
  elapsed = time.time() - start
 
23
  if resp.status_code == 200:
24
  data = resp.json()
25
  transcript = data.get("transcription", "No transcription returned.")
 
28
  else:
29
  return f"❌ Error: {resp.status_code}, {resp.text}", ""
30
 
31
+ def main():
32
+ iface = gr.Interface(
33
+ fn=transcribe_audio,
34
+ inputs=gr.Audio(label="Audio Input (upload or record, up to 30 s)", type="filepath", sources=["upload", "microphone"]),
35
+ outputs=[
36
+ gr.Textbox(label="📝 Transcription", lines=5, show_copy_button=True, placeholder="The transcription will appear here..."),
37
+ gr.Label(label="⏱️ Processing Time")
38
+ ],
39
+ title="Gooya ASR v1.4",
40
+ description="High-performance Persian Speech-to-Text. Upload or record a Persian audio file (max 30 s) and instantly receive the transcription.",
41
+ examples=[],
42
+ cache_examples=False,
43
+ allow_flagging="never"
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
44
  )
45
+ iface.launch()
46
 
47
  if __name__ == "__main__":
48
+ main()