Spaces:
Paused
Paused
app
Browse files
app.py
CHANGED
@@ -1187,6 +1187,7 @@ class AutoRAGChatApp:
|
|
1187 |
|
1188 |
# μμ± μΈμ μ²λ¦¬ ν¨μ
|
1189 |
# app.py λ΄ process_audio ν¨μ 보κ°
|
|
|
1190 |
def process_audio(audio):
|
1191 |
logger.info("μμ± μΈμ μ²λ¦¬ μμ...")
|
1192 |
try:
|
@@ -1202,8 +1203,6 @@ class AutoRAGChatApp:
|
|
1202 |
# μ€λμ€ λ°μ΄ν°λ₯Ό μμ νμΌλ‘ μ μ₯
|
1203 |
sr, y = audio
|
1204 |
logger.info(f"μ€λμ€ λ
Ήμ λ°μ΄ν° μμ : μνλ μ΄νΈ={sr}Hz, κΈΈμ΄={len(y)}μν")
|
1205 |
-
|
1206 |
-
# μμ±μ΄ λ무 μ§§μ κ²½μ° μ²΄ν¬ (1μ΄ λ―Έλ§)
|
1207 |
if len(y) / sr < 1.0:
|
1208 |
return "λ
Ήμλ μμ±μ΄ λ무 μ§§μ΅λλ€. λ€μ μλν΄μ£ΌμΈμ."
|
1209 |
|
@@ -1212,12 +1211,9 @@ class AutoRAGChatApp:
|
|
1212 |
sf.write(temp_path, y, sr, format="WAV")
|
1213 |
logger.info(f"μμ WAV νμΌ μ μ₯λ¨: {temp_path}")
|
1214 |
|
1215 |
-
# μμ± μΈμ μ€ν
|
1216 |
# μμ± μΈμ μ€ν
|
1217 |
stt_client = ClovaSTT()
|
1218 |
-
|
1219 |
-
audio_bytes = f.read()
|
1220 |
-
result = stt_client.recognize(audio_bytes)
|
1221 |
|
1222 |
# μμ νμΌ μμ
|
1223 |
try:
|
@@ -1226,7 +1222,6 @@ class AutoRAGChatApp:
|
|
1226 |
except Exception as e:
|
1227 |
logger.warning(f"μμ νμΌ μμ μ€ν¨: {e}")
|
1228 |
|
1229 |
-
# κ²°κ³Ό μ²λ¦¬
|
1230 |
if result["success"]:
|
1231 |
recognized_text = result["text"]
|
1232 |
logger.info(f"μμ±μΈμ μ±κ³΅: {recognized_text}")
|
@@ -1243,15 +1238,44 @@ class AutoRAGChatApp:
|
|
1243 |
logger.error(f"μμ± μ²λ¦¬ μ€ μ€λ₯ λ°μ: {e}", exc_info=True)
|
1244 |
return f"μμ± μ²λ¦¬ μ€ μ€λ₯ λ°μ: {str(e)}"
|
1245 |
|
1246 |
-
#
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1247 |
def update_ui_after_refresh(result):
|
1248 |
return (
|
1249 |
result, # μν λ©μμ§
|
1250 |
-
|
1251 |
-
f"μμ€ν
μν: {'μ΄κΈ°νλ¨' if
|
1252 |
-
|
1253 |
)
|
1254 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1255 |
# μμ± μΈμ κ²°κ³Όλ₯Ό μ§λ¬Έ μμμ μ
λ°μ΄νΈ
|
1256 |
audio_input.stop_recording(
|
1257 |
fn=process_audio,
|
@@ -1303,6 +1327,9 @@ class AutoRAGChatApp:
|
|
1303 |
except Exception as e:
|
1304 |
logger.error(f"Gradio μ± μ€ν μ€ μ€λ₯ λ°μ: {e}", exc_info=True)
|
1305 |
print(f"Gradio μ± μ€ν μ€ μ€λ₯ λ°μ: {e}")
|
|
|
|
|
|
|
1306 |
def _get_status_message(self) -> str:
|
1307 |
"""
|
1308 |
νμ¬ μ²λ¦¬ μν λ©μμ§ μμ±
|
|
|
1187 |
|
1188 |
# μμ± μΈμ μ²λ¦¬ ν¨μ
|
1189 |
# app.py λ΄ process_audio ν¨μ 보κ°
|
1190 |
+
# Gradio μ± λ΄μ μλ μμ± μΈμ μ²λ¦¬ ν¨μ (μλ³Έ)
|
1191 |
def process_audio(audio):
|
1192 |
logger.info("μμ± μΈμ μ²λ¦¬ μμ...")
|
1193 |
try:
|
|
|
1203 |
# μ€λμ€ λ°μ΄ν°λ₯Ό μμ νμΌλ‘ μ μ₯
|
1204 |
sr, y = audio
|
1205 |
logger.info(f"μ€λμ€ λ
Ήμ λ°μ΄ν° μμ : μνλ μ΄νΈ={sr}Hz, κΈΈμ΄={len(y)}μν")
|
|
|
|
|
1206 |
if len(y) / sr < 1.0:
|
1207 |
return "λ
Ήμλ μμ±μ΄ λ무 μ§§μ΅λλ€. λ€μ μλν΄μ£ΌμΈμ."
|
1208 |
|
|
|
1211 |
sf.write(temp_path, y, sr, format="WAV")
|
1212 |
logger.info(f"μμ WAV νμΌ μ μ₯λ¨: {temp_path}")
|
1213 |
|
|
|
1214 |
# μμ± μΈμ μ€ν
|
1215 |
stt_client = ClovaSTT()
|
1216 |
+
result = stt_client.recognize_file(temp_path)
|
|
|
|
|
1217 |
|
1218 |
# μμ νμΌ μμ
|
1219 |
try:
|
|
|
1222 |
except Exception as e:
|
1223 |
logger.warning(f"μμ νμΌ μμ μ€ν¨: {e}")
|
1224 |
|
|
|
1225 |
if result["success"]:
|
1226 |
recognized_text = result["text"]
|
1227 |
logger.info(f"μμ±μΈμ μ±κ³΅: {recognized_text}")
|
|
|
1238 |
logger.error(f"μμ± μ²λ¦¬ μ€ μ€λ₯ λ°μ: {e}", exc_info=True)
|
1239 |
return f"μμ± μ²λ¦¬ μ€ μ€λ₯ λ°μ: {str(e)}"
|
1240 |
|
1241 |
+
# μλ‘ μΆκ°ν process_audio_and_submit ν¨μ
|
1242 |
+
def process_audio_and_submit(audio, chat_history):
|
1243 |
+
"""
|
1244 |
+
λ
Ήμ μ μ§ μ μμ± μΈμ ν μλμΌλ‘ μ§λ¬Έμ μ²λ¦¬νλ ν¨μ.
|
1245 |
+
μ
λ ₯:
|
1246 |
+
- audio: λ
Ήμ λ°μ΄ν° (gr.Audioμ κ°)
|
1247 |
+
- chat_history: νμ¬ λν κΈ°λ‘ (gr.Chatbotμ κ°)
|
1248 |
+
μΆλ ₯:
|
1249 |
+
- query_box: λΉ λ¬Έμμ΄ (μ§λ¬Έ μ
λ ₯λ μ΄κΈ°ν)
|
1250 |
+
- chatbot: μ
λ°μ΄νΈλ λν κΈ°λ‘
|
1251 |
+
"""
|
1252 |
+
recognized_text = process_audio(audio)
|
1253 |
+
|
1254 |
+
# μμ± μΈμ κ²°κ³Όκ° μ€λ₯ λ©μμ§μΈ κ²½μ° κ·Έλλ‘ λ°ν
|
1255 |
+
if not recognized_text or recognized_text.startswith("μμ± μΈμ μ€ν¨") or recognized_text.startswith(
|
1256 |
+
"μμ± μ²λ¦¬ μ€ μ€λ₯"):
|
1257 |
+
return recognized_text, chat_history
|
1258 |
+
|
1259 |
+
# μΈμλ ν
μ€νΈλ₯Ό μ¬μ©νμ¬ μ§λ¬Έ μ²λ¦¬
|
1260 |
+
return app_instance.process_query(recognized_text, chat_history)
|
1261 |
+
|
1262 |
+
# κΈ°μ‘΄ update_ui_after_refresh ν¨μ μμ (self λμ app_instance μ¬μ©)
|
1263 |
def update_ui_after_refresh(result):
|
1264 |
return (
|
1265 |
result, # μν λ©μμ§
|
1266 |
+
app_instance._get_status_message(), # μν λ°μ€ μ
λ°μ΄νΈ
|
1267 |
+
f"μμ€ν
μν: {'μ΄κΈ°νλ¨' if app_instance.is_initialized else 'μ΄κΈ°νλμ§ μμ'}", # μν μ 보 μ
λ°μ΄νΈ
|
1268 |
+
app_instance._get_cache_info() # μΊμ μ 보 μ
λ°μ΄νΈ
|
1269 |
)
|
1270 |
|
1271 |
+
# --- Gradio μ΄λ²€νΈ νΈλ€λ¬ μ€μ ---
|
1272 |
+
# μ: audio_input μ»΄ν¬λνΈμ stop_recording μ΄λ²€νΈλ₯Ό μλμ κ°μ΄ μμ
|
1273 |
+
audio_input.stop_recording(
|
1274 |
+
fn=process_audio_and_submit,
|
1275 |
+
inputs=[audio_input, chatbot],
|
1276 |
+
outputs=[query_box, chatbot]
|
1277 |
+
)
|
1278 |
+
|
1279 |
# μμ± μΈμ κ²°κ³Όλ₯Ό μ§λ¬Έ μμμ μ
λ°μ΄νΈ
|
1280 |
audio_input.stop_recording(
|
1281 |
fn=process_audio,
|
|
|
1327 |
except Exception as e:
|
1328 |
logger.error(f"Gradio μ± μ€ν μ€ μ€λ₯ λ°μ: {e}", exc_info=True)
|
1329 |
print(f"Gradio μ± μ€ν μ€ μ€λ₯ λ°μ: {e}")
|
1330 |
+
|
1331 |
+
|
1332 |
+
|
1333 |
def _get_status_message(self) -> str:
|
1334 |
"""
|
1335 |
νμ¬ μ²λ¦¬ μν λ©μμ§ μμ±
|