Add application file
Browse files
app.py
CHANGED
@@ -861,7 +861,7 @@ class AutoRAGChatApp:
|
|
861 |
def process_audio_auto(audio, chat_history):
|
862 |
"""λ
Ήμ μλ£ μ μλμΌλ‘ STT μ²λ¦¬ ν μ§μ μ²λ¦¬"""
|
863 |
if audio is None:
|
864 |
-
return chat_history,
|
865 |
|
866 |
# μ²λ¦¬ μ€ μν λ©μμ§
|
867 |
processing_msg = "μμ± μ²λ¦¬ μ€..."
|
@@ -871,8 +871,7 @@ class AutoRAGChatApp:
|
|
871 |
import scipy.io.wavfile as wav
|
872 |
|
873 |
# μν μ
λ°μ΄νΈ
|
874 |
-
yield chat_history, gr.update(
|
875 |
-
interactive=False), "μμ±μ ν
μ€νΈλ‘ λ³ν μ€..."
|
876 |
|
877 |
# numpy λ°°μ΄μ WAV νμΌλ‘ μ μ₯
|
878 |
with tempfile.NamedTemporaryFile(suffix=".wav", delete=False) as temp_file:
|
@@ -900,7 +899,7 @@ class AutoRAGChatApp:
|
|
900 |
print(f"[STT] {error_msg}")
|
901 |
new_history = list(chat_history)
|
902 |
new_history.append(["μμ± λ©μμ§", error_msg])
|
903 |
-
yield new_history,
|
904 |
return
|
905 |
|
906 |
# μΈμλ ν
μ€νΈ μΆμΆ
|
@@ -910,14 +909,14 @@ class AutoRAGChatApp:
|
|
910 |
print("[STT] μΈμλ ν
μ€νΈ μμ")
|
911 |
new_history = list(chat_history)
|
912 |
new_history.append(["μμ± λ©μμ§", error_msg])
|
913 |
-
yield new_history,
|
914 |
return
|
915 |
|
916 |
print(f"[STT] μΈμλ ν
μ€νΈ: {recognized_text}")
|
917 |
|
918 |
# μν μ
λ°μ΄νΈ
|
919 |
-
yield chat_history, gr.update(
|
920 |
-
|
921 |
|
922 |
# μΈμλ ν
μ€νΈλ‘ 쿼리 μ²λ¦¬ (μμ± λ©μμ§ μ λμ΄ μΆκ°)
|
923 |
query = f"π€ {recognized_text}"
|
@@ -940,13 +939,13 @@ class AutoRAGChatApp:
|
|
940 |
response = f"λ¬Έμλ₯Ό λ‘λν μ μμ΅λλ€. 'documents' ν΄λμ PDF νμΌμ΄ μλμ§ νμΈνμΈμ.\nμ€λ₯ μ 보: {init_result}"
|
941 |
new_history = list(chat_history)
|
942 |
new_history.append([query, response])
|
943 |
-
yield new_history,
|
944 |
return
|
945 |
except Exception as e:
|
946 |
response = f"λ¬Έμ λ‘λ μ€ μ€λ₯ λ°μ: {str(e)}"
|
947 |
new_history = list(chat_history)
|
948 |
new_history.append([query, response])
|
949 |
-
yield new_history,
|
950 |
return
|
951 |
else:
|
952 |
print("μμ± μΏΌλ¦¬ μ²λ¦¬: λ¬Έμκ° μ΄λ―Έ λ‘λλμ΄ μμ΅λλ€.")
|
@@ -973,7 +972,7 @@ class AutoRAGChatApp:
|
|
973 |
new_history.append([query, response]) # 리μ€νΈ νμμΌλ‘ μΆκ°
|
974 |
|
975 |
# μ΅μ’
μν μ
λ°μ΄νΈ
|
976 |
-
yield new_history,
|
977 |
|
978 |
except Exception as e:
|
979 |
error_msg = f"μ€λ₯ λ°μ: {str(e)}"
|
@@ -983,7 +982,7 @@ class AutoRAGChatApp:
|
|
983 |
# λ©μμ§ νμμ λ§κ² μΆκ°
|
984 |
new_history = list(chat_history) # κΈ°μ‘΄ 리μ€νΈλ₯Ό 볡μ¬
|
985 |
new_history.append([query, error_msg]) # 리μ€νΈ νμμΌλ‘ μΆκ°
|
986 |
-
yield new_history,
|
987 |
|
988 |
except Exception as e:
|
989 |
error_msg = f"μμ± μ²λ¦¬ μ€ μ€λ₯ λ°μ: {str(e)}"
|
@@ -992,7 +991,7 @@ class AutoRAGChatApp:
|
|
992 |
traceback.print_exc()
|
993 |
new_history = list(chat_history)
|
994 |
new_history.append(["μμ± λ©μμ§", error_msg])
|
995 |
-
yield new_history,
|
996 |
|
997 |
with gr.Blocks(title="μμ±μΈμ κΈ°λ₯μ΄ μΆκ°λ PDF λ¬Έμ κΈ°λ° RAG μ±λ΄") as app:
|
998 |
gr.Markdown("# μμ±μΈμ κΈ°λ₯μ΄ μΆκ°λ PDF λ¬Έμ κΈ°λ° RAG μ±λ΄")
|
|
|
861 |
def process_audio_auto(audio, chat_history):
|
862 |
"""λ
Ήμ μλ£ μ μλμΌλ‘ STT μ²λ¦¬ ν μ§μ μ²λ¦¬"""
|
863 |
if audio is None:
|
864 |
+
return chat_history, gr.update(interactive=True), "λ
Ήμ ν μλμΌλ‘ μ²λ¦¬λ©λλ€", ""
|
865 |
|
866 |
# μ²λ¦¬ μ€ μν λ©μμ§
|
867 |
processing_msg = "μμ± μ²λ¦¬ μ€..."
|
|
|
871 |
import scipy.io.wavfile as wav
|
872 |
|
873 |
# μν μ
λ°μ΄νΈ
|
874 |
+
yield chat_history, gr.update(interactive=False), processing_msg, "μμ±μ ν
μ€νΈλ‘ λ³ν μ€..."
|
|
|
875 |
|
876 |
# numpy λ°°μ΄μ WAV νμΌλ‘ μ μ₯
|
877 |
with tempfile.NamedTemporaryFile(suffix=".wav", delete=False) as temp_file:
|
|
|
899 |
print(f"[STT] {error_msg}")
|
900 |
new_history = list(chat_history)
|
901 |
new_history.append(["μμ± λ©μμ§", error_msg])
|
902 |
+
yield new_history, gr.update(interactive=True), error_msg, ""
|
903 |
return
|
904 |
|
905 |
# μΈμλ ν
μ€νΈ μΆμΆ
|
|
|
909 |
print("[STT] μΈμλ ν
μ€νΈ μμ")
|
910 |
new_history = list(chat_history)
|
911 |
new_history.append(["μμ± λ©μμ§", error_msg])
|
912 |
+
yield new_history, gr.update(interactive=True), error_msg, ""
|
913 |
return
|
914 |
|
915 |
print(f"[STT] μΈμλ ν
μ€νΈ: {recognized_text}")
|
916 |
|
917 |
# μν μ
λ°μ΄νΈ
|
918 |
+
yield chat_history, gr.update(
|
919 |
+
interactive=False), f"μΈμλ ν
μ€νΈ: {recognized_text}\n\nμλ΅ μμ± μ€...", "μλ΅ μμ± μ€..."
|
920 |
|
921 |
# μΈμλ ν
μ€νΈλ‘ 쿼리 μ²λ¦¬ (μμ± λ©μμ§ μ λμ΄ μΆκ°)
|
922 |
query = f"π€ {recognized_text}"
|
|
|
939 |
response = f"λ¬Έμλ₯Ό λ‘λν μ μμ΅λλ€. 'documents' ν΄λμ PDF νμΌμ΄ μλμ§ νμΈνμΈμ.\nμ€λ₯ μ 보: {init_result}"
|
940 |
new_history = list(chat_history)
|
941 |
new_history.append([query, response])
|
942 |
+
yield new_history, gr.update(interactive=True), response, ""
|
943 |
return
|
944 |
except Exception as e:
|
945 |
response = f"λ¬Έμ λ‘λ μ€ μ€λ₯ λ°μ: {str(e)}"
|
946 |
new_history = list(chat_history)
|
947 |
new_history.append([query, response])
|
948 |
+
yield new_history, gr.update(interactive=True), response, ""
|
949 |
return
|
950 |
else:
|
951 |
print("μμ± μΏΌλ¦¬ μ²λ¦¬: λ¬Έμκ° μ΄λ―Έ λ‘λλμ΄ μμ΅λλ€.")
|
|
|
972 |
new_history.append([query, response]) # 리μ€νΈ νμμΌλ‘ μΆκ°
|
973 |
|
974 |
# μ΅μ’
μν μ
λ°μ΄νΈ
|
975 |
+
yield new_history, gr.update(interactive=True), f"μ²λ¦¬ μλ£: {recognized_text}", ""
|
976 |
|
977 |
except Exception as e:
|
978 |
error_msg = f"μ€λ₯ λ°μ: {str(e)}"
|
|
|
982 |
# λ©μμ§ νμμ λ§κ² μΆκ°
|
983 |
new_history = list(chat_history) # κΈ°μ‘΄ 리μ€νΈλ₯Ό 볡μ¬
|
984 |
new_history.append([query, error_msg]) # 리μ€νΈ νμμΌλ‘ μΆκ°
|
985 |
+
yield new_history, gr.update(interactive=True), error_msg, ""
|
986 |
|
987 |
except Exception as e:
|
988 |
error_msg = f"μμ± μ²λ¦¬ μ€ μ€λ₯ λ°μ: {str(e)}"
|
|
|
991 |
traceback.print_exc()
|
992 |
new_history = list(chat_history)
|
993 |
new_history.append(["μμ± λ©μμ§", error_msg])
|
994 |
+
yield new_history, gr.update(interactive=True), error_msg, ""
|
995 |
|
996 |
with gr.Blocks(title="μμ±μΈμ κΈ°λ₯μ΄ μΆκ°λ PDF λ¬Έμ κΈ°λ° RAG μ±λ΄") as app:
|
997 |
gr.Markdown("# μμ±μΈμ κΈ°λ₯μ΄ μΆκ°λ PDF λ¬Έμ κΈ°λ° RAG μ±λ΄")
|