rkihacker commited on
Commit
ff7d450
·
verified ·
1 Parent(s): e0f5861

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +15 -3
app.py CHANGED
@@ -48,6 +48,9 @@ WHISPER_LANGUAGES = {
48
  "Lingala": "ln", "Hausa": "ha", "Bashkir": "ba", "Javanese": "jw", "Sundanese": "su",
49
  }
50
  SORTED_LANGUAGES = dict(sorted(WHISPER_LANGUAGES.items()))
 
 
 
51
  def file_to_base64(filepath: str) -> str:
52
  if not filepath: return None
53
  try:
@@ -73,9 +76,13 @@ def moderate_content(text_input, image_input, video_input, audio_input, language
73
  if video_b64 := file_to_base64(video_input): payload["video"] = video_b64
74
  if audio_b64 := file_to_base64(audio_input):
75
  payload["voice"] = audio_b64
76
- language_code = SORTED_LANGUAGES.get(language_full_name, "en")
77
  payload["language"] = language_code
78
- logging.info(f"Audio detected. Using language: {language_full_name} ({language_code})")
 
 
 
 
79
  logging.info(f"Sending request to {MODERATION_ENDPOINT} with inputs: {list(payload.keys())}")
80
  latency_ms = None
81
  start_time = time.monotonic()
@@ -140,7 +147,12 @@ with gr.Blocks(theme=gr.themes.Soft(primary_hue="blue", secondary_hue="sky"), cs
140
  video_input = gr.Video(label="Video Input")
141
  with gr.TabItem("🎤 Audio"):
142
  audio_input = gr.Audio(label="Voice/Audio Input", type="filepath")
143
- language_input = gr.Dropdown(label="Audio Language", choices=list(SORTED_LANGUAGES.keys()), value="English", interactive=True)
 
 
 
 
 
144
  with gr.Row():
145
  clear_button = gr.Button("Clear All")
146
  submit_button = gr.Button("▶️ Moderate Content", variant="primary")
 
48
  "Lingala": "ln", "Hausa": "ha", "Bashkir": "ba", "Javanese": "jw", "Sundanese": "su",
49
  }
50
  SORTED_LANGUAGES = dict(sorted(WHISPER_LANGUAGES.items()))
51
+ # Add Auto Language Detection as the first option for the dropdown
52
+ LANGUAGES_WITH_AUTO = {"Auto Language Detection": "auto", **SORTED_LANGUAGES}
53
+
54
  def file_to_base64(filepath: str) -> str:
55
  if not filepath: return None
56
  try:
 
76
  if video_b64 := file_to_base64(video_input): payload["video"] = video_b64
77
  if audio_b64 := file_to_base64(audio_input):
78
  payload["voice"] = audio_b64
79
+ language_code = LANGUAGES_WITH_AUTO.get(language_full_name, "auto")
80
  payload["language"] = language_code
81
+ if language_code == "auto":
82
+ logging.info(f"Audio detected. Using language: Auto Language Detection (auto)")
83
+ else:
84
+ logging.info(f"Audio detected. Using language: {language_full_name} ({language_code})")
85
+
86
  logging.info(f"Sending request to {MODERATION_ENDPOINT} with inputs: {list(payload.keys())}")
87
  latency_ms = None
88
  start_time = time.monotonic()
 
147
  video_input = gr.Video(label="Video Input")
148
  with gr.TabItem("🎤 Audio"):
149
  audio_input = gr.Audio(label="Voice/Audio Input", type="filepath")
150
+ language_input = gr.Dropdown(
151
+ label="Audio Language",
152
+ choices=list(LANGUAGES_WITH_AUTO.keys()),
153
+ value="Auto Language Detection",
154
+ interactive=True
155
+ )
156
  with gr.Row():
157
  clear_button = gr.Button("Clear All")
158
  submit_button = gr.Button("▶️ Moderate Content", variant="primary")