omersaidd commited on
Commit
b931afd
·
verified ·
1 Parent(s): df9ed6d

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +32 -7
app.py CHANGED
@@ -23,11 +23,21 @@ def chat_with_dify(message, history):
23
  user_message = {"role": "user", "content": message}
24
  conversation_history.append(user_message)
25
 
 
 
 
 
 
 
 
 
26
  # API isteği için veriyi hazırla
27
  data = {
28
  "inputs": {},
29
  "query": message,
30
- "user": "gradio-user"
 
 
31
  }
32
 
33
  # API isteği yap
@@ -67,11 +77,10 @@ def chat_with_dify(message, history):
67
 
68
  # Gradio arayüzünü oluştur
69
  with gr.Blocks(css="footer {visibility: hidden}") as demo:
70
- # Logo ve başlık yan yana olacak şekilde HTML formatında
71
  gr.HTML("""
72
- <div style="display: flex; align-items: center; gap: 20px;">
73
  <h1 style="margin: 0;">Etikos AI Hukuk Asistanı</h1>
74
- <img src="logo.png" height="50" />
75
  </div>
76
  """)
77
 
@@ -79,7 +88,14 @@ with gr.Blocks(css="footer {visibility: hidden}") as demo:
79
 
80
  chatbot = gr.Chatbot(height=400)
81
  msg = gr.Textbox(placeholder="Mesajınızı buraya yazın...", show_label=False)
82
- clear = gr.Button("Sohbeti Temizle")
 
 
 
 
 
 
 
83
 
84
  def user(message, history):
85
  # Kullanıcı mesajını geçmişe ekle ve dön
@@ -97,14 +113,23 @@ with gr.Blocks(css="footer {visibility: hidden}") as demo:
97
  def clear_conversation():
98
  global conversation_history
99
  conversation_history = []
100
- return None
 
 
 
 
 
 
 
 
101
 
102
  # Sohbet akışını ayarla
103
  msg.submit(user, [msg, chatbot], [msg, chatbot], queue=False).then(
104
  bot, chatbot, chatbot
105
  )
106
 
107
- clear.click(clear_conversation, None, chatbot)
 
108
 
109
  # Uygulamayı başlat
110
  demo.launch()
 
23
  user_message = {"role": "user", "content": message}
24
  conversation_history.append(user_message)
25
 
26
+ # Geçmiş mesajları API için hazırla
27
+ messages = []
28
+ for msg in conversation_history:
29
+ messages.append({
30
+ "role": msg["role"],
31
+ "content": msg["content"]
32
+ })
33
+
34
  # API isteği için veriyi hazırla
35
  data = {
36
  "inputs": {},
37
  "query": message,
38
+ "user": "gradio-user",
39
+ "conversation_id": None, # Yeni konuşma başlatır
40
+ "messages": messages # Tüm geçmiş mesajları gönder
41
  }
42
 
43
  # API isteği yap
 
77
 
78
  # Gradio arayüzünü oluştur
79
  with gr.Blocks(css="footer {visibility: hidden}") as demo:
80
+ # Sadece başlık göster, logo yok
81
  gr.HTML("""
82
+ <div style="display: flex; align-items: center;">
83
  <h1 style="margin: 0;">Etikos AI Hukuk Asistanı</h1>
 
84
  </div>
85
  """)
86
 
 
88
 
89
  chatbot = gr.Chatbot(height=400)
90
  msg = gr.Textbox(placeholder="Mesajınızı buraya yazın...", show_label=False)
91
+
92
+ # Konuşma geçmişini ve geçmiş sohbetleri görüntülemek için
93
+ with gr.Row():
94
+ clear = gr.Button("Sohbeti Temizle")
95
+ show_memory = gr.Button("Konuşma Geçmişini Göster")
96
+
97
+ # Geçmiş mesajları göstermek için bir metin kutusu
98
+ memory_display = gr.Textbox(label="Konuşma Geçmişi", interactive=False, visible=False, lines=10)
99
 
100
  def user(message, history):
101
  # Kullanıcı mesajını geçmişe ekle ve dön
 
113
  def clear_conversation():
114
  global conversation_history
115
  conversation_history = []
116
+ return None, gr.update(visible=False, value="")
117
+
118
+ def display_memory():
119
+ memory_text = ""
120
+ for i, msg in enumerate(conversation_history):
121
+ role = "Kullanıcı" if msg["role"] == "user" else "AI"
122
+ memory_text += f"{role}: {msg['content']}\n\n"
123
+
124
+ return gr.update(visible=True, value=memory_text)
125
 
126
  # Sohbet akışını ayarla
127
  msg.submit(user, [msg, chatbot], [msg, chatbot], queue=False).then(
128
  bot, chatbot, chatbot
129
  )
130
 
131
+ clear.click(clear_conversation, None, [chatbot, memory_display])
132
+ show_memory.click(display_memory, None, memory_display)
133
 
134
  # Uygulamayı başlat
135
  demo.launch()