Spaces:
Sleeping
Sleeping
FauziIsyrinApridal
commited on
Commit
·
2a886a9
1
Parent(s):
b8830a8
..
Browse files- app/chat.py +13 -27
app/chat.py
CHANGED
@@ -10,9 +10,7 @@ from dotenv import load_dotenv
|
|
10 |
|
11 |
load_dotenv()
|
12 |
|
13 |
-
|
14 |
-
# Simpan Feedback ke Supabase
|
15 |
-
# -------------------------------
|
16 |
def save_feedback_to_supabase(feedback_text):
|
17 |
try:
|
18 |
data = {"message": feedback_text}
|
@@ -22,9 +20,7 @@ def save_feedback_to_supabase(feedback_text):
|
|
22 |
st.error(f"Gagal menyimpan feedback: {e}")
|
23 |
return False
|
24 |
|
25 |
-
|
26 |
-
# Inisialisasi State
|
27 |
-
# -------------------------------
|
28 |
def initialize_session_state():
|
29 |
if 'history' not in st.session_state:
|
30 |
st.session_state['history'] = []
|
@@ -43,9 +39,6 @@ def initialize_session_state():
|
|
43 |
if 'tts_output' not in st.session_state:
|
44 |
st.session_state['tts_output'] = ""
|
45 |
|
46 |
-
# -------------------------------
|
47 |
-
# Fungsi TTS
|
48 |
-
# -------------------------------
|
49 |
def text_to_speech(text):
|
50 |
tts = gtts.gTTS(text, lang="id")
|
51 |
audio_bytes = BytesIO()
|
@@ -59,17 +52,12 @@ def text_to_speech(text):
|
|
59 |
"""
|
60 |
return audio_player
|
61 |
|
62 |
-
# -------------------------------
|
63 |
-
# Fungsi Chatbot
|
64 |
-
# -------------------------------
|
65 |
def conversation_chat(query, chain, history):
|
66 |
result = chain({"question": query, "chat_history": history})
|
67 |
history.append((query, result["answer"]))
|
68 |
return result["answer"]
|
69 |
|
70 |
-
|
71 |
-
# Tampilan & Logika Chat
|
72 |
-
# -------------------------------
|
73 |
def display_chat_history(chain):
|
74 |
reply_container = st.container()
|
75 |
|
@@ -134,15 +122,13 @@ def display_chat_history(chain):
|
|
134 |
st.session_state['tts_output'] = ""
|
135 |
del st.session_state['tts_played']
|
136 |
|
137 |
-
|
138 |
-
#
|
139 |
-
#
|
140 |
-
|
141 |
-
|
142 |
-
|
143 |
-
|
144 |
-
|
145 |
-
|
146 |
-
|
147 |
-
if success:
|
148 |
-
st.success("✅ Terima kasih atas feedback-nya!")
|
|
|
10 |
|
11 |
load_dotenv()
|
12 |
|
13 |
+
|
|
|
|
|
14 |
def save_feedback_to_supabase(feedback_text):
|
15 |
try:
|
16 |
data = {"message": feedback_text}
|
|
|
20 |
st.error(f"Gagal menyimpan feedback: {e}")
|
21 |
return False
|
22 |
|
23 |
+
|
|
|
|
|
24 |
def initialize_session_state():
|
25 |
if 'history' not in st.session_state:
|
26 |
st.session_state['history'] = []
|
|
|
39 |
if 'tts_output' not in st.session_state:
|
40 |
st.session_state['tts_output'] = ""
|
41 |
|
|
|
|
|
|
|
42 |
def text_to_speech(text):
|
43 |
tts = gtts.gTTS(text, lang="id")
|
44 |
audio_bytes = BytesIO()
|
|
|
52 |
"""
|
53 |
return audio_player
|
54 |
|
|
|
|
|
|
|
55 |
def conversation_chat(query, chain, history):
|
56 |
result = chain({"question": query, "chat_history": history})
|
57 |
history.append((query, result["answer"]))
|
58 |
return result["answer"]
|
59 |
|
60 |
+
|
|
|
|
|
61 |
def display_chat_history(chain):
|
62 |
reply_container = st.container()
|
63 |
|
|
|
122 |
st.session_state['tts_output'] = ""
|
123 |
del st.session_state['tts_played']
|
124 |
|
125 |
+
|
126 |
+
# with st.sidebar:
|
127 |
+
# with st.form("sidebar_feedback_form"):
|
128 |
+
# feedback_text = st.text_area("Masukkan feedback Anda di sini:")
|
129 |
+
# submitted = st.form_submit_button("Kirim")
|
130 |
+
|
131 |
+
# if submitted and feedback_text.strip():
|
132 |
+
# success = save_feedback_to_supabase(feedback_text)
|
133 |
+
# if success:
|
134 |
+
# st.success("✅ Terima kasih atas feedback-nya!")
|
|
|
|