Spaces:
Configuration error
Configuration error
Delete app.py
Browse files
app.py
DELETED
|
@@ -1,84 +0,0 @@
|
|
| 1 |
-
import os
|
| 2 |
-
import telegram
|
| 3 |
-
from telegram.ext import Application, CommandHandler, MessageHandler, filters
|
| 4 |
-
from rvc_python.infer import RVC_pipeline
|
| 5 |
-
import torch
|
| 6 |
-
import logging
|
| 7 |
-
|
| 8 |
-
# تفعيل سجلات بسيطة لرؤية ما يحدث
|
| 9 |
-
logging.basicConfig(
|
| 10 |
-
format='%(asctime)s - %(name)s - %(levelname)s - %(message)s',
|
| 11 |
-
level=logging.INFO
|
| 12 |
-
)
|
| 13 |
-
|
| 14 |
-
logger = logging.getLogger(__name__)
|
| 15 |
-
|
| 16 |
-
# --- إعدادات النموذج ---
|
| 17 |
-
YOUR_HF_REPO_ID = "Hashim-dotcom/Hashim.ai.rvc"
|
| 18 |
-
MODEL_PATH = "model.pth"
|
| 19 |
-
device = "cpu"
|
| 20 |
-
|
| 21 |
-
try:
|
| 22 |
-
logger.info("جاري تحميل النموذج...")
|
| 23 |
-
rvc = RVC_pipeline(repo_id=YOUR_HF_REPO_ID, model_path=MODEL_PATH, device=device)
|
| 24 |
-
logger.info("النموذج جاهز!")
|
| 25 |
-
except Exception as e:
|
| 26 |
-
logger.error(f"فشل تحميل النموذج: {e}")
|
| 27 |
-
rvc = None
|
| 28 |
-
|
| 29 |
-
# --- دوال البوت ---
|
| 30 |
-
async def start(update, context):
|
| 31 |
-
await update.message.reply_text("مرحباً! أنا بوت تحويل الصوت. أرسل لي رسالة صوتية وسأقوم بتحويلها باستخدام صوتي الخاص.")
|
| 32 |
-
|
| 33 |
-
async def handle_voice(update, context):
|
| 34 |
-
if rvc is None:
|
| 35 |
-
await update.message.reply_text("عذراً، النموذج غير جاهز حالياً بسبب مشكلة في التحميل.")
|
| 36 |
-
return
|
| 37 |
-
|
| 38 |
-
message = update.message
|
| 39 |
-
await message.reply_text("تم استلام رسالتك الصوتية، جاري المعالجة... قد يستغرق هذا بعض الوقت.")
|
| 40 |
-
|
| 41 |
-
input_audio_path = f"{message.message_id}_input.oga"
|
| 42 |
-
output_audio_path_name = f"{message.message_id}_output.wav"
|
| 43 |
-
|
| 44 |
-
try:
|
| 45 |
-
voice_file = await message.voice.get_file()
|
| 46 |
-
await voice_file.download_to_drive(input_audio_path)
|
| 47 |
-
logger.info(f"تم تحميل الملف الصوتي: {input_audio_path}")
|
| 48 |
-
|
| 49 |
-
# استدعاء النموذج لتحويل الصوت
|
| 50 |
-
output_audio_path, sampling_rate = rvc.infer(
|
| 51 |
-
input_audio_path=input_audio_path,
|
| 52 |
-
pitch_shift=0
|
| 53 |
-
)
|
| 54 |
-
logger.info(f"تمت المعالجة بنجاح: {output_audio_path}")
|
| 55 |
-
|
| 56 |
-
# إعادة تسمية الملف الناتج إلى اسم فريد لتجنب التضارب
|
| 57 |
-
os.rename(output_audio_path, output_audio_path_name)
|
| 58 |
-
|
| 59 |
-
# إرسال الملف الصوتي المحول
|
| 60 |
-
await message.reply_audio(audio=open(output_audio_path_name, 'rb'), title="صوت محول")
|
| 61 |
-
|
| 62 |
-
# تنظيف الملفات المؤقتة
|
| 63 |
-
os.remove(input_audio_path)
|
| 64 |
-
os.remove(output_audio_path_name)
|
| 65 |
-
|
| 66 |
-
except Exception as e:
|
| 67 |
-
logger.error(f"حدث خطأ أثناء المعالجة: {e}")
|
| 68 |
-
await update.message.reply_text(f"حدث خطأ: {str(e)}")
|
| 69 |
-
|
| 70 |
-
def main():
|
| 71 |
-
TOKEN = os.getenv("TELEGRAM_TOKEN")
|
| 72 |
-
if not TOKEN:
|
| 73 |
-
logger.critical("خطأ فادح: لم يتم العثور على TELEGRAM_TOKEN في الأسرار (secrets).")
|
| 74 |
-
return
|
| 75 |
-
|
| 76 |
-
application = Application.builder().token(TOKEN).build()
|
| 77 |
-
application.add_handler(CommandHandler("start", start))
|
| 78 |
-
application.add_handler(MessageHandler(filters.VOICE, handle_voice))
|
| 79 |
-
|
| 80 |
-
logger.info("البوت قيد التشغيل ويبدأ الاستماع...")
|
| 81 |
-
application.run_polling()
|
| 82 |
-
|
| 83 |
-
if __name__ == "__main__":
|
| 84 |
-
main()
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|