kadalicious22 commited on
Commit
88e811f
·
verified ·
1 Parent(s): 22ad9e2

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +13 -4
app.py CHANGED
@@ -108,10 +108,19 @@ def dental_chat(message, history):
108
 
109
  except Exception as e:
110
  print(f"Error: {str(e)}")
 
 
 
 
 
 
 
 
 
111
  if history and history[-1]["content"] == "":
112
- history[-1]["content"] = f"Maaf, terjadi kesalahan: {str(e)}. Silakan coba lagi."
113
  else:
114
- history.append({"role": "assistant", "content": f"Maaf, terjadi kesalahan: {str(e)}. Silakan coba lagi."})
115
  yield "", history
116
 
117
  css = """
@@ -219,8 +228,8 @@ with gr.Blocks(title="DentoAI", css=css) as demo:
219
  )
220
 
221
  with gr.Row():
222
- submit_btn = gr.Button("Send", variant="primary")
223
- clear_btn = gr.Button("Clear Chat", variant="secondary")
224
 
225
  msg.submit(dental_chat, [msg, chatbot], [msg, chatbot])
226
  submit_btn.click(dental_chat, [msg, chatbot], [msg, chatbot])
 
108
 
109
  except Exception as e:
110
  print(f"Error: {str(e)}")
111
+ error_str = str(e).lower()
112
+ if "429" in error_str or "rate limit" in error_str or "quota" in error_str or "too many" in error_str:
113
+ pesan = "⚠️ Layanan sedang sibuk atau kuota habis. Silakan coba beberapa saat lagi."
114
+ elif "401" in error_str or "unauthorized" in error_str or "api key" in error_str:
115
+ pesan = "🔑 API Key tidak valid atau sudah kadaluarsa. Hubungi administrator."
116
+ elif "timeout" in error_str or "connection" in error_str:
117
+ pesan = "🌐 Koneksi bermasalah. Periksa internet dan coba lagi."
118
+ else:
119
+ pesan = "❌ Terjadi kesalahan. Silakan coba lagi."
120
  if history and history[-1]["content"] == "":
121
+ history[-1]["content"] = pesan
122
  else:
123
+ history.append({"role": "assistant", "content": pesan})
124
  yield "", history
125
 
126
  css = """
 
228
  )
229
 
230
  with gr.Row():
231
+ submit_btn = gr.Button("Kirim 📨", variant="primary")
232
+ clear_btn = gr.Button("Hapus Chat 🗑️", variant="secondary")
233
 
234
  msg.submit(dental_chat, [msg, chatbot], [msg, chatbot])
235
  submit_btn.click(dental_chat, [msg, chatbot], [msg, chatbot])