SamiKoen commited on
Commit
00c226f
·
verified ·
1 Parent(s): b8ed688

Upload app.py

Browse files
Files changed (1) hide show
  1. app.py +10 -13
app.py CHANGED
@@ -843,21 +843,18 @@ with gr.Blocks(css=custom_css, theme="soft", title="Trek Asistanı") as demo:
843
  elem_id="msg-input"
844
  )
845
 
846
- # Session state için gizli bileşen
847
- session_state = gr.State({})
848
 
849
- def respond(message, chat_history, session_state):
850
  if not message.strip():
851
- return "", chat_history, session_state
852
 
853
- # Session ID oluştur veya mevcut olanı kullan
854
- if not session_state or 'session_id' not in session_state:
855
- # Browser fingerprint benzeri benzersiz ID oluştur
856
- session_id = str(uuid.uuid4())[:8] + hashlib.md5(str(time.time()).encode()).hexdigest()[:8]
857
- session_state = {'session_id': session_id}
858
 
859
  # Session ID'yi chatbot_fn'e geç
860
- chatbot_fn._current_session_id = session_state['session_id']
861
 
862
  # Chat history'yi chatbot_fn için uygun formata çevir
863
  formatted_history = []
@@ -882,7 +879,7 @@ with gr.Blocks(css=custom_css, theme="soft", title="Trek Asistanı") as demo:
882
 
883
  # Profile kaydetme chatbot_fn içinde yapılıyor, burada duplikasyon yok
884
 
885
- return "", chat_history, session_state
886
 
887
  except Exception as e:
888
  error_msg = f"Üzgünüm, bir hata oluştu: {str(e)}"
@@ -890,9 +887,9 @@ with gr.Blocks(css=custom_css, theme="soft", title="Trek Asistanı") as demo:
890
  if chat_history is None:
891
  chat_history = []
892
  chat_history.append((message, error_msg))
893
- return "", chat_history, session_state
894
 
895
- msg.submit(respond, [msg, chatbot, session_state], [msg, chatbot, session_state])
896
 
897
  if __name__ == "__main__":
898
  demo.launch(debug=True)
 
843
  elem_id="msg-input"
844
  )
845
 
846
+ # Session state kaldırıldı - basit yöntem kullanılıyor
 
847
 
848
+ def respond(message, chat_history):
849
  if not message.strip():
850
+ return "", chat_history
851
 
852
+ # Basit session ID sistemi - her kullanıcı için sabit ID
853
+ if not hasattr(respond, '_user_session_id'):
854
+ respond._user_session_id = str(uuid.uuid4())[:12] # Oturum boyunca sabit ID
 
 
855
 
856
  # Session ID'yi chatbot_fn'e geç
857
+ chatbot_fn._current_session_id = respond._user_session_id
858
 
859
  # Chat history'yi chatbot_fn için uygun formata çevir
860
  formatted_history = []
 
879
 
880
  # Profile kaydetme chatbot_fn içinde yapılıyor, burada duplikasyon yok
881
 
882
+ return "", chat_history
883
 
884
  except Exception as e:
885
  error_msg = f"Üzgünüm, bir hata oluştu: {str(e)}"
 
887
  if chat_history is None:
888
  chat_history = []
889
  chat_history.append((message, error_msg))
890
+ return "", chat_history
891
 
892
+ msg.submit(respond, [msg, chatbot], [msg, chatbot])
893
 
894
  if __name__ == "__main__":
895
  demo.launch(debug=True)