Spaces:
Sleeping
Sleeping
updated
Browse files
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 |
-
|
94 |
-
|
95 |
-
|
96 |
-
|
97 |
-
|
98 |
-
submit_button = gr.Button("Submit", elem_classes="submit-btn")
|
99 |
-
clear = gr.Button("Clear", elem_classes="clear-btn")
|
100 |
|
101 |
-
|
102 |
-
|
103 |
-
|
104 |
|
105 |
-
|
106 |
-
|
107 |
-
|
108 |
-
|
109 |
-
|
110 |
-
|
111 |
-
|
112 |
-
|
113 |
-
|
114 |
-
|
115 |
-
|
116 |
|
117 |
-
|
118 |
-
|
119 |
-
|
120 |
-
|
121 |
-
|
122 |
-
|
123 |
-
|
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()
|