Kabatubare commited on
Commit
0c35856
·
verified ·
1 Parent(s): 75918b8

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +12 -13
app.py CHANGED
@@ -1,23 +1,22 @@
1
  import gradio as gr
 
2
 
3
- def predict_voice(audio_path):
4
- # Load the Hugging Face model directly through gr.Interface.load
5
- model = gr.Interface.load("models/Kabatubare/ast_celeb_spoof")
6
-
7
- # Since we're loading the model directly inside the prediction function,
8
- # we use it immediately to make a prediction on the provided audio file.
9
- predictions = model(audio_path)
10
-
11
- # Format predictions for display
12
  formatted_predictions = [f"Label: {prediction['label']}, Confidence: {prediction['score']:.4f}" for prediction in predictions]
13
- return formatted_predictions
14
 
15
  # Define the Gradio interface
16
  iface = gr.Interface(
17
  fn=predict_voice,
18
- inputs=gr.Audio(label="Upload Audio File", type="filepath"),
19
- outputs=gr.Text(label="Model Predictions"),
20
- title="Voice Authenticity Detection with AST Celeb Spoof",
21
  description="This model detects whether a voice is real or AI-generated. Upload an audio file to get started.",
22
  allow_flagging="never",
23
  theme="huggingface"
 
1
  import gradio as gr
2
+ from transformers import pipeline
3
 
4
+ # Initialize the pipeline for audio classification
5
+ # Ensure you have the transformers library installed
6
+ model_pipeline = pipeline("audio-classification", model="Kabatubare/ast_celeb_spoof")
7
+
8
+ def predict_voice(audio_file):
9
+ predictions = model_pipeline(audio_file.name)
10
+ # Format the predictions for display
 
 
11
  formatted_predictions = [f"Label: {prediction['label']}, Confidence: {prediction['score']:.4f}" for prediction in predictions]
12
+ return "\n".join(formatted_predictions)
13
 
14
  # Define the Gradio interface
15
  iface = gr.Interface(
16
  fn=predict_voice,
17
+ inputs=gr.Audio(source="upload", type="file", label="Upload Audio File"),
18
+ outputs=gr.Text(label="Predictions"),
19
+ title="Voice Authenticity Detection",
20
  description="This model detects whether a voice is real or AI-generated. Upload an audio file to get started.",
21
  allow_flagging="never",
22
  theme="huggingface"