Spaces:
Runtime error
Runtime error
Update app.py
Browse files
app.py
CHANGED
@@ -6,7 +6,7 @@ import traceback
|
|
6 |
import threading
|
7 |
import os
|
8 |
|
9 |
-
# --- دیکشنری زبانها و صداها
|
10 |
language_dict = {
|
11 |
'English-Jenny (Female)': 'en-US-JennyNeural',
|
12 |
'English-Guy (Male)': 'en-US-GuyNeural',
|
@@ -311,14 +311,11 @@ async def text_to_speech_edge_async(text, language_code, rate, volume, pitch):
|
|
311 |
return "تبدیل با موفقیت انجام شد.", tmp_path
|
312 |
except edge_tts.exceptions.NoAudioReceived:
|
313 |
error_msg = f"خطا: صدایی برای متن و صدای انتخاب شده دریافت نشد (صدا: {voice_id})."
|
314 |
-
# print(f"NoAudioReceived Error: {error_msg}"); # کامنت برای کاهش لاگ ها
|
315 |
return error_msg, None
|
316 |
except ValueError as ve:
|
317 |
error_msg = f"خطا در پارامترهای ورودی edge-tts: {ve}"
|
318 |
-
# print(f"ValueError in edge-tts: {error_msg}"); traceback.print_exc(); # کامنت برای کاهش لاگ ها
|
319 |
return error_msg, None
|
320 |
except Exception as e:
|
321 |
-
# print(f"Unexpected error in TTS async: {type(e).__name__}"); traceback.print_exc() # کامنت برای کاهش لاگ ها
|
322 |
return f"خطای غیرمنتظره در سرور: {type(e).__name__}", None
|
323 |
|
324 |
_event_loops_by_thread = {}
|
@@ -337,12 +334,8 @@ def text_to_speech_edge_sync_wrapper(text, language_code, rate, volume, pitch):
|
|
337 |
new_loop = asyncio.new_event_loop(); asyncio.set_event_loop(new_loop)
|
338 |
try: result = new_loop.run_until_complete(text_to_speech_edge_async(text, language_code, rate, volume, pitch))
|
339 |
finally: new_loop.close()
|
340 |
-
else:
|
341 |
-
|
342 |
-
return f"خطای اجرایی: {e}", None
|
343 |
-
except Exception as e:
|
344 |
-
# print(f"Unexpected Exception in wrapper: {e}"); traceback.print_exc() # کامنت برای کاهش لاگ ها
|
345 |
-
return f"خطای غیرمنتظره: {type(e).__name__}", None
|
346 |
return result
|
347 |
|
348 |
# --- تعریف تم و CSS ---
|
@@ -358,20 +351,13 @@ app_theme = gr.themes.Soft(
|
|
358 |
custom_css = """
|
359 |
body { font-family: 'Vazirmatn', 'Arial', sans-serif; direction: rtl; }
|
360 |
.gradio-container {
|
361 |
-
max-width: 95% !important;
|
362 |
-
|
363 |
-
padding: 1rem !important;
|
364 |
-
border-radius: 16px !important;
|
365 |
-
box-shadow: 0 6px 20px rgba(0, 0, 0, 0.07) !important;
|
366 |
background-color: #ffffff !important;
|
367 |
}
|
368 |
.app-header {
|
369 |
-
text-align: center;
|
370 |
-
|
371 |
-
background: #34495e;
|
372 |
-
color: white;
|
373 |
-
border-radius: 12px;
|
374 |
-
margin-bottom: 1.5rem;
|
375 |
}
|
376 |
.app-header img.logo {
|
377 |
width: 50px; height: auto; margin-bottom: 5px;
|
@@ -414,12 +400,13 @@ label > span {
|
|
414 |
.gr-examples th, .gr-examples td { padding: 6px 8px !important; }
|
415 |
|
416 |
/* مخفی کردن پاورقی پیش فرض Gradio و دکمه Flag و لینک های Settings/API */
|
417 |
-
footer
|
418 |
-
.gradio-footer { display: none !important; visibility: hidden !important; }
|
419 |
-
.flagging-container { display: none !important; visibility: hidden !important; }
|
420 |
-
.flex.row.gap-2.absolute.bottom-2.right-2.gr-compact.gr-box.gr-text-gray-500 { display: none !important; visibility: hidden !important; }
|
421 |
-
div[data-testid="flag"] { display: none !important; }
|
422 |
-
button[title="Flag"], button[aria-label="Flag"] {display: none !important; }
|
|
|
423 |
|
424 |
@keyframes float_soft {
|
425 |
0% { transform: translatey(0px) scale(1); }
|
@@ -460,7 +447,7 @@ with gr.Blocks(theme=app_theme, css=custom_css) as demo:
|
|
460 |
lines=5,
|
461 |
label="📝 متن خود را وارد نمایید",
|
462 |
placeholder="متن برای تبدیل...",
|
463 |
-
value=""
|
464 |
)
|
465 |
language = gr.Dropdown(
|
466 |
choices=list(language_dict.keys()),
|
@@ -494,13 +481,8 @@ with gr.Blocks(theme=app_theme, css=custom_css) as demo:
|
|
494 |
label="💡 نمونههای آماده برای تست"
|
495 |
)
|
496 |
|
497 |
-
# پاورقی
|
498 |
-
#
|
499 |
-
# اگر می خواهید یک پاورقی کاملا متفاوت داشته باشید، می توانید اینجا gr.HTML یا gr.Markdown خودتان را قرار دهید.
|
500 |
-
# مثال:
|
501 |
-
# with gr.Row():
|
502 |
-
# gr.HTML("<div style='text-align:center; font-size:0.8em; color:#aaa; padding-top:20px;'>© 2024 Your App Name</div>")
|
503 |
-
|
504 |
|
505 |
submit_button.click(
|
506 |
fn=text_to_speech_edge_sync_wrapper,
|
@@ -508,15 +490,5 @@ with gr.Blocks(theme=app_theme, css=custom_css) as demo:
|
|
508 |
outputs=[output_text_status, output_audio],
|
509 |
)
|
510 |
|
511 |
-
#
|
512 |
-
|
513 |
-
# اما برای اطمینان می توانید allow_flagging="never" را نگه دارید.
|
514 |
-
# analytics_enabled=False هم برای غیرفعال کردن جمع آوری داده توسط Gradio است.
|
515 |
-
# ... (تمام کد قبلی شما تا قبل از launch) ...
|
516 |
-
|
517 |
-
# پارامتر allow_flagging حذف شده است
|
518 |
-
# analytics_enabled را می توانید نگه دارید یا اگر آن هم خطا داد حذف کنید.
|
519 |
-
demo.launch(analytics_enabled=False)
|
520 |
-
|
521 |
-
# یا اگر analytics_enabled هم باعث خطا شد (کمتر محتمل است):
|
522 |
-
# demo.launch()
|
|
|
6 |
import threading
|
7 |
import os
|
8 |
|
9 |
+
# --- دیکشنری زبانها و صداها ---
|
10 |
language_dict = {
|
11 |
'English-Jenny (Female)': 'en-US-JennyNeural',
|
12 |
'English-Guy (Male)': 'en-US-GuyNeural',
|
|
|
311 |
return "تبدیل با موفقیت انجام شد.", tmp_path
|
312 |
except edge_tts.exceptions.NoAudioReceived:
|
313 |
error_msg = f"خطا: صدایی برای متن و صدای انتخاب شده دریافت نشد (صدا: {voice_id})."
|
|
|
314 |
return error_msg, None
|
315 |
except ValueError as ve:
|
316 |
error_msg = f"خطا در پارامترهای ورودی edge-tts: {ve}"
|
|
|
317 |
return error_msg, None
|
318 |
except Exception as e:
|
|
|
319 |
return f"خطای غیرمنتظره در سرور: {type(e).__name__}", None
|
320 |
|
321 |
_event_loops_by_thread = {}
|
|
|
334 |
new_loop = asyncio.new_event_loop(); asyncio.set_event_loop(new_loop)
|
335 |
try: result = new_loop.run_until_complete(text_to_speech_edge_async(text, language_code, rate, volume, pitch))
|
336 |
finally: new_loop.close()
|
337 |
+
else: return f"خطای اجرایی: {e}", None
|
338 |
+
except Exception as e: return f"خطای غیرمنتظره: {type(e).__name__}", None
|
|
|
|
|
|
|
|
|
339 |
return result
|
340 |
|
341 |
# --- تعریف تم و CSS ---
|
|
|
351 |
custom_css = """
|
352 |
body { font-family: 'Vazirmatn', 'Arial', sans-serif; direction: rtl; }
|
353 |
.gradio-container {
|
354 |
+
max-width: 95% !important; margin: 1rem auto !important; padding: 1rem !important;
|
355 |
+
border-radius: 16px !important; box-shadow: 0 6px 20px rgba(0, 0, 0, 0.07) !important;
|
|
|
|
|
|
|
356 |
background-color: #ffffff !important;
|
357 |
}
|
358 |
.app-header {
|
359 |
+
text-align: center; padding: 20px 10px; background: #34495e; color: white;
|
360 |
+
border-radius: 12px; margin-bottom: 1.5rem;
|
|
|
|
|
|
|
|
|
361 |
}
|
362 |
.app-header img.logo {
|
363 |
width: 50px; height: auto; margin-bottom: 5px;
|
|
|
400 |
.gr-examples th, .gr-examples td { padding: 6px 8px !important; }
|
401 |
|
402 |
/* مخفی کردن پاورقی پیش فرض Gradio و دکمه Flag و لینک های Settings/API */
|
403 |
+
footer { display: none !important; visibility: hidden !important; } /* برای اطمینان از مخفی شدن پاورقی اصلی */
|
404 |
+
.gradio-footer { display: none !important; visibility: hidden !important; }
|
405 |
+
.flagging-container { display: none !important; visibility: hidden !important; }
|
406 |
+
.flex.row.gap-2.absolute.bottom-2.right-2.gr-compact.gr-box.gr-text-gray-500 { display: none !important; visibility: hidden !important; }
|
407 |
+
div[data-testid="flag"] { display: none !important; }
|
408 |
+
button[title="Flag"], button[aria-label="Flag"] {display: none !important; }
|
409 |
+
.footer-utils { display: none !important; visibility: hidden !important; } /* یک کلاس دیگر که گاهی برای پاورقی utils استفاده می شود */
|
410 |
|
411 |
@keyframes float_soft {
|
412 |
0% { transform: translatey(0px) scale(1); }
|
|
|
447 |
lines=5,
|
448 |
label="📝 متن خود را وارد نمایید",
|
449 |
placeholder="متن برای تبدیل...",
|
450 |
+
value=""
|
451 |
)
|
452 |
language = gr.Dropdown(
|
453 |
choices=list(language_dict.keys()),
|
|
|
481 |
label="💡 نمونههای آماده برای تست"
|
482 |
)
|
483 |
|
484 |
+
# بخش پاورقی کاملا حذف شده است تا هیچ نامی از Gradio یا چیز دیگری نباشد
|
485 |
+
# اگر نیاز به پاورقی سفارشی دارید، اینجا می توانید gr.HTML یا gr.Markdown خود را قرار دهید.
|
|
|
|
|
|
|
|
|
|
|
486 |
|
487 |
submit_button.click(
|
488 |
fn=text_to_speech_edge_sync_wrapper,
|
|
|
490 |
outputs=[output_text_status, output_audio],
|
491 |
)
|
492 |
|
493 |
+
# اجرای برنامه بدون پارامترهای اضافی در launch
|
494 |
+
demo.launch()
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|