Spaces:
Sleeping
Sleeping
Create app.py
Browse files
app.py
ADDED
|
@@ -0,0 +1,32 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import gradio as gr
|
| 2 |
+
from transformers import pipeline
|
| 3 |
+
import torch
|
| 4 |
+
|
| 5 |
+
# اختر الجهاز: استخدم GPU إذا كان متاحاً في الـ Space، وإلا CPU
|
| 6 |
+
device = "cuda:0" if torch.cuda.is_available() else "cpu"
|
| 7 |
+
|
| 8 |
+
# تحميل الـ pipeline للنموذج العربي المتخصص
|
| 9 |
+
# سيتم تحميل النموذج تلقائياً عند أول تشغيل للـ Space
|
| 10 |
+
pipe = pipeline(
|
| 11 |
+
"automatic-speech-recognition",
|
| 12 |
+
model="abdo-mustafa/whisper-large-v2-arabic",
|
| 13 |
+
device=device
|
| 14 |
+
)
|
| 15 |
+
|
| 16 |
+
def transcribe(audio):
|
| 17 |
+
if audio is None:
|
| 18 |
+
return "لم يتم رفع أي ملف صوتي."
|
| 19 |
+
|
| 20 |
+
# استدعاء النموذج لتحويل الصوت (المسار المؤقت للملف)
|
| 21 |
+
text = pipe(audio)["text"]
|
| 22 |
+
return text
|
| 23 |
+
|
| 24 |
+
# بناء واجهة Gradio التي ستوفر لنا الـ API
|
| 25 |
+
gr.Interface(
|
| 26 |
+
fn=transcribe,
|
| 27 |
+
inputs=gr.Audio(sources=["upload"], type="filepath", label="ارفع ملفاً صوتياً"),
|
| 28 |
+
outputs=gr.Textbox(label="النص المُحوَّل"),
|
| 29 |
+
title="API لتحويل الكلام العربي إلى نص",
|
| 30 |
+
description="واجهة لنموذج Whisper المتخصص باللغة العربية (abdo-mustafa/whisper-large-v2-arabic).",
|
| 31 |
+
allow_flagging="never"
|
| 32 |
+
).launch()
|