Komal-patra commited on
Commit
e672180
1 Parent(s): 85bca36

update app.py

Browse files
Files changed (1) hide show
  1. app.py +18 -4
app.py CHANGED
@@ -91,12 +91,23 @@ span.md.svelte-8tpqd2.chatbot.prose p {
91
  }
92
  """
93
 
 
 
 
94
  # Gradio interface setup
95
  with gr.Blocks(css=custom_css) as demo:
96
  with gr.Row():
97
  with gr.Column(scale=1):
98
  gr.Markdown("<h2>My chats</h2>")
99
- chat_topics = gr.Markdown("<!-- Dynamic content -->")
 
 
 
 
 
 
 
 
100
 
101
  with gr.Column(scale=3):
102
  gr.Markdown("<h1>Ask a question about the EU AI Act</h1>")
@@ -119,13 +130,16 @@ with gr.Blocks(css=custom_css) as demo:
119
  previous_message = history[-1][0] # Access the previous user message
120
  bot_message = generate_text(previous_message) # Generate response based on previous message
121
  history[-1][1] = bot_message # Update the last bot message
122
- return history
 
 
 
123
 
124
  submit_button.click(user, [msg, chatbot], [msg, chatbot], queue=False).then(
125
- bot, chatbot, chatbot
126
  )
127
  msg.submit(user, [msg, chatbot], [msg, chatbot], queue=False).then(
128
- bot, chatbot, chatbot
129
  )
130
  clear.click(lambda: None, None, chatbot, queue=False)
131
 
 
91
  }
92
  """
93
 
94
+ # Initialize chat history
95
+ chat_history = []
96
+
97
  # Gradio interface setup
98
  with gr.Blocks(css=custom_css) as demo:
99
  with gr.Row():
100
  with gr.Column(scale=1):
101
  gr.Markdown("<h2>My chats</h2>")
102
+ history = gr.Markdown("<!-- Dynamic content -->")
103
+
104
+ def update_history(history_list):
105
+ history_md = ""
106
+ for i, (user_msg, bot_msg) in enumerate(history_list):
107
+ history_md += f"**Chat {i+1}**\n"
108
+ history_md += f"**You:** {user_msg}\n\n"
109
+ history_md += f"**Bot:** {bot_msg}\n\n"
110
+ return history_md
111
 
112
  with gr.Column(scale=3):
113
  gr.Markdown("<h1>Ask a question about the EU AI Act</h1>")
 
130
  previous_message = history[-1][0] # Access the previous user message
131
  bot_message = generate_text(previous_message) # Generate response based on previous message
132
  history[-1][1] = bot_message # Update the last bot message
133
+
134
+ # Update chat history
135
+ chat_history.append((previous_message, bot_message))
136
+ return history, update_history(chat_history)
137
 
138
  submit_button.click(user, [msg, chatbot], [msg, chatbot], queue=False).then(
139
+ bot, [chatbot, history], [chatbot, history]
140
  )
141
  msg.submit(user, [msg, chatbot], [msg, chatbot], queue=False).then(
142
+ bot, [chatbot, history], [chatbot, history]
143
  )
144
  clear.click(lambda: None, None, chatbot, queue=False)
145