Spaces:
Sleeping
Sleeping
Komal-patra
commited on
Commit
•
bd5560a
1
Parent(s):
b9acf04
update
Browse files
app.py
CHANGED
@@ -85,16 +85,10 @@ span.md.svelte-8tpqd2.chatbot.prose p {{
|
|
85 |
margin-right: 8px;
|
86 |
}}
|
87 |
/* Enable scrolling for the chatbot messages */
|
88 |
-
.chatbot.messages {{
|
89 |
max-height: 500px; /* Adjust as needed */
|
90 |
overflow-y: auto;
|
91 |
}}
|
92 |
-
/* Add transparency to chatbox */
|
93 |
-
.chatbot {{
|
94 |
-
background-color: rgba(255, 255, 255, 0.5); /* 50% transparent white background */
|
95 |
-
border: none;
|
96 |
-
box-shadow: none;
|
97 |
-
}}
|
98 |
"""
|
99 |
|
100 |
# Gradio interface setup
|
@@ -107,13 +101,26 @@ with gr.Blocks(css=custom_css) as demo:
|
|
107 |
|
108 |
# Function to handle user input
|
109 |
def user(user_message, history):
|
110 |
-
|
111 |
-
return [user_message, response]
|
112 |
|
113 |
-
#
|
114 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
115 |
|
116 |
-
|
117 |
-
|
|
|
|
|
|
|
|
|
|
|
118 |
|
119 |
-
demo.launch()
|
|
|
85 |
margin-right: 8px;
|
86 |
}}
|
87 |
/* Enable scrolling for the chatbot messages */
|
88 |
+
.chatbot .messages {{
|
89 |
max-height: 500px; /* Adjust as needed */
|
90 |
overflow-y: auto;
|
91 |
}}
|
|
|
|
|
|
|
|
|
|
|
|
|
92 |
"""
|
93 |
|
94 |
# Gradio interface setup
|
|
|
101 |
|
102 |
# Function to handle user input
|
103 |
def user(user_message, history):
|
104 |
+
return "", history + [[user_message, None]]
|
|
|
105 |
|
106 |
+
# Function to handle bot response
|
107 |
+
def bot(history):
|
108 |
+
if len(history) == 1: # Check if it's the first interaction
|
109 |
+
bot_message = "Hi there! How can I help you today?"
|
110 |
+
history[-1][1] = bot_message # Add welcome message to history
|
111 |
+
else:
|
112 |
+
history[-1][1] = "" # Clear the last bot message
|
113 |
+
previous_message = history[-1][0] # Access the previous user message
|
114 |
+
bot_message = generate_text(previous_message) # Generate response based on previous message
|
115 |
+
history[-1][1] = bot_message # Update the last bot message
|
116 |
+
return history
|
117 |
|
118 |
+
submit_button.click(user, [msg, chatbot], [msg, chatbot], queue=False).then(
|
119 |
+
bot, chatbot, chatbot
|
120 |
+
)
|
121 |
+
msg.submit(user, [msg, chatbot], [msg, chatbot], queue=False).then(
|
122 |
+
bot, chatbot, chatbot
|
123 |
+
)
|
124 |
+
clear.click(lambda: None, None, chatbot, queue=False)
|
125 |
|
126 |
+
demo.launch()
|