Komal-patra commited on
Commit
29f9dea
1 Parent(s): dc0224a
Files changed (1) hide show
  1. app.py +26 -28
app.py CHANGED
@@ -90,36 +90,34 @@ span.md.svelte-8tpqd2.chatbot.prose p {
90
 
91
  # Gradio interface setup
92
  with gr.Blocks(css=custom_css) as demo:
93
- with gr.Row():
94
- with gr.Column(scale=3, offset=1): # Adjust column to take full width minus some padding
95
- gr.Markdown("<h1>Ask a question about the EU AI Act</h1>")
96
- chatbot = gr.Chatbot()
97
- msg = gr.Textbox(placeholder="Ask your question...", show_label=False) # Add placeholder text
98
- submit_button = gr.Button("Submit", elem_classes="submit-btn")
99
- clear = gr.Button("Clear", elem_classes="clear-btn")
100
 
101
- # Function to handle user input
102
- def user(user_message, history):
103
- return "", history + [[user_message, None]]
104
 
105
- # Function to handle bot response
106
- def bot(history):
107
- if len(history) == 1: # Check if it's the first interaction
108
- bot_message = "Hi there! How can I help you today?"
109
- history[-1][1] = bot_message # Add welcome message to history
110
- else:
111
- history[-1][1] = "" # Clear the last bot message
112
- previous_message = history[-1][0] # Access the previous user message
113
- bot_message = generate_text(previous_message) # Generate response based on previous message
114
- history[-1][1] = bot_message # Update the last bot message
115
- return history
116
 
117
- submit_button.click(user, [msg, chatbot], [msg, chatbot], queue=False).then(
118
- bot, chatbot, chatbot
119
- )
120
- msg.submit(user, [msg, chatbot], [msg, chatbot], queue=False).then(
121
- bot, chatbot, chatbot
122
- )
123
- clear.click(lambda: None, None, chatbot, queue=False)
124
 
125
  demo.launch()
 
90
 
91
  # Gradio interface setup
92
  with gr.Blocks(css=custom_css) as demo:
93
+ gr.Markdown("<h1>Ask a question about the EU AI Act</h1>")
94
+ chatbot = gr.Chatbot()
95
+ msg = gr.Textbox(placeholder="Ask your question...", show_label=False) # Add placeholder text
96
+ submit_button = gr.Button("Submit", elem_classes="submit-btn")
97
+ clear = gr.Button("Clear", elem_classes="clear-btn")
 
 
98
 
99
+ # Function to handle user input
100
+ def user(user_message, history):
101
+ return "", history + [[user_message, None]]
102
 
103
+ # Function to handle bot response
104
+ def bot(history):
105
+ if len(history) == 1: # Check if it's the first interaction
106
+ bot_message = "Hi there! How can I help you today?"
107
+ history[-1][1] = bot_message # Add welcome message to history
108
+ else:
109
+ history[-1][1] = "" # Clear the last bot message
110
+ previous_message = history[-1][0] # Access the previous user message
111
+ bot_message = generate_text(previous_message) # Generate response based on previous message
112
+ history[-1][1] = bot_message # Update the last bot message
113
+ return history
114
 
115
+ submit_button.click(user, [msg, chatbot], [msg, chatbot], queue=False).then(
116
+ bot, chatbot, chatbot
117
+ )
118
+ msg.submit(user, [msg, chatbot], [msg, chatbot], queue=False).then(
119
+ bot, chatbot, chatbot
120
+ )
121
+ clear.click(lambda: None, None, chatbot, queue=False)
122
 
123
  demo.launch()