import gradio as gr from transformers import pipeline # Whisper لتحويل الصوت إلى نص whisper = pipeline( "automatic-speech-recognition", model="openai/whisper-base" ) # موديلك classifier = pipeline( "text-classification", model="MennatullahHany/Abert" ) label_map = { "LABEL_0": "Safe", "LABEL_1": "Danger" } def predict(audio): # تحويل الصوت إلى نص transcription = whisper(audio)["text"] # تشغيل الموديل result = classifier(transcription)[0] label = label_map[result["label"]] return { "text":transcription, "result": label, "confidence": round(float(result["score"]), 4) } demo = gr.Interface( fn=predict, inputs=gr.Audio(type="filepath", label="Upload Audio"), outputs=gr.JSON(label="Prediction"), title="Voice Emotion Detection", description="Upload an audio file to detect whether it is Safe or Danger." ) demo.launch()