TGPro1 commited on
Commit
1ce7f77
·
verified ·
1 Parent(s): 20b7425

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +11 -36
app.py CHANGED
@@ -1,37 +1,11 @@
1
  import gradio as gr
2
- import requests
3
- import base64
4
  import os
5
- import json
6
- import numpy as np
7
- import scipy.io.wavfile as wavfile
8
- import tempfile
9
  import torch
10
- from google import genai
11
- from google.genai import types
12
- from gradio_client import Client, handle_file
13
  from pyannote.audio import Pipeline
14
 
15
  # Configuration
16
- SEAMLESS_SPACE = "tgpro1/sttr"
17
- GEMINI_API_KEY = os.environ.get('GEMINI_API_KEY')
18
  HF_TOKEN = os.environ.get('HF_TOKEN')
19
 
20
- LANGUAGES = {
21
- "Darija": "ar-SA",
22
- "Arabic": "ar-SA",
23
- "French": "fr-FR",
24
- "English": "en-US",
25
- "Spanish": "es-ES",
26
- "German": "de-DE",
27
- "Italian": "it-IT",
28
- "Portuguese": "pt-PT",
29
- "Chinese": "zh-CN",
30
- "Japanese": "ja-JP",
31
- "Korean": "ko-KR",
32
- "Russian": "ru-RU",
33
- }
34
-
35
  # Pyannote Diarization
36
  diarization_pipeline = None
37
  try:
@@ -50,7 +24,7 @@ except Exception as e:
50
 
51
  def diarize_audio(audio_path, min_speakers=1, max_speakers=5):
52
  if not diarization_pipeline:
53
- return {"error": "Diarization not available"}
54
  try:
55
  diarization = diarization_pipeline(audio_path, min_speakers=int(min_speakers), max_speakers=int(max_speakers))
56
  speakers = []
@@ -60,16 +34,17 @@ def diarize_audio(audio_path, min_speakers=1, max_speakers=5):
60
  except Exception as e:
61
  return {"error": str(e)}
62
 
63
- with gr.Blocks(title="STTR") as demo:
64
  gr.Markdown("# STTR - Speaker Diarization")
65
- with gr.Tab("Diarization"):
66
- audio_in = gr.Audio(type="filepath", label="Audio")
67
- with gr.Row():
68
- min_spk = gr.Slider(1, 10, value=1, step=1, label="Min Speakers")
69
- max_spk = gr.Slider(1, 10, value=5, step=1, label="Max Speakers")
70
- btn = gr.Button("Analyze", variant="primary")
71
- output = gr.JSON(label="Result")
72
- btn.click(diarize_audio, [audio_in, min_spk, max_spk], output, api_name="/diarize")
 
73
 
74
  if __name__ == "__main__":
75
  demo.launch(server_name="0.0.0.0", server_port=int(os.environ.get("PORT", 7860)))
 
1
  import gradio as gr
 
 
2
  import os
 
 
 
 
3
  import torch
 
 
 
4
  from pyannote.audio import Pipeline
5
 
6
  # Configuration
 
 
7
  HF_TOKEN = os.environ.get('HF_TOKEN')
8
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
9
  # Pyannote Diarization
10
  diarization_pipeline = None
11
  try:
 
24
 
25
  def diarize_audio(audio_path, min_speakers=1, max_speakers=5):
26
  if not diarization_pipeline:
27
+ return {"error": "Diarization not available. Check HF_TOKEN."}
28
  try:
29
  diarization = diarization_pipeline(audio_path, min_speakers=int(min_speakers), max_speakers=int(max_speakers))
30
  speakers = []
 
34
  except Exception as e:
35
  return {"error": str(e)}
36
 
37
+ with gr.Blocks(title="STTR - Speaker Diarization") as demo:
38
  gr.Markdown("# STTR - Speaker Diarization")
39
+ gr.Markdown("### Identify who speaks when (pyannote 3.1)")
40
+
41
+ audio_in = gr.Audio(type="filepath", label="Upload Audio")
42
+ with gr.Row():
43
+ min_spk = gr.Slider(1, 10, value=1, step=1, label="Min Speakers")
44
+ max_spk = gr.Slider(1, 10, value=5, step=1, label="Max Speakers")
45
+ btn = gr.Button("Analyze Speakers", variant="primary")
46
+ output = gr.JSON(label="Speaker Segments")
47
+ btn.click(diarize_audio, [audio_in, min_spk, max_spk], output, api_name="/diarize")
48
 
49
  if __name__ == "__main__":
50
  demo.launch(server_name="0.0.0.0", server_port=int(os.environ.get("PORT", 7860)))