Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
@@ -42,7 +42,12 @@ def initialize_chat(initial_question):
|
|
42 |
chat_history = [(None, initial_question)]
|
43 |
response, follow_up_questions, token_info = generate_response(initial_question, 0)
|
44 |
chat_history.append((None, response))
|
45 |
-
|
|
|
|
|
|
|
|
|
|
|
46 |
|
47 |
def generate_response(prompt, token_count=0):
|
48 |
print(f"Received prompt: {prompt}")
|
@@ -160,15 +165,18 @@ css = """
|
|
160 |
|
161 |
# Initialize the chat history and suggested questionsw
|
162 |
# Initialize the chat history and suggested questions
|
163 |
-
chat_history, follow_up_questions, initial_token_info = initialize_chat("I'm 14 years old female and want to become a graphic designer. I'm living in Uttar Pradesh in India. How can I start?")
|
164 |
|
165 |
|
166 |
# Initial example questions from the initialization
|
167 |
-
|
168 |
-
initial_examples = [[q] for q in formatted_questions]
|
169 |
|
170 |
with gr.Blocks(css=css) as demo:
|
171 |
-
examples_state = gr.State(
|
|
|
|
|
|
|
|
|
172 |
with gr.Row():
|
173 |
with gr.Column(scale=1):
|
174 |
gr.Markdown(
|
@@ -177,22 +185,24 @@ with gr.Blocks(css=css) as demo:
|
|
177 |
In the realm of digital communication, the development of an advanced chatbot that incorporates topic modeling represents a significant leap towards enhancing user interaction and maintaining focus during conversations. This innovative chatbot design is specifically engineered to streamline discussions by guiding users to select from a curated list of suggested questions. This approach is crafted to mitigate the risk of diverging into off-topic dialogues, which are common pitfalls in conventional chatbot systems.
|
178 |
"""
|
179 |
)
|
180 |
-
|
181 |
-
value=
|
182 |
elem_id="token-info"
|
183 |
)
|
184 |
-
|
185 |
-
value=
|
186 |
elem_id="follow-up-questions",
|
187 |
-
label="Follow up
|
188 |
)
|
189 |
initial_question_input = gr.Textbox(
|
190 |
placeholder="Type your initial question here...",
|
191 |
label="Initial Question"
|
192 |
)
|
|
|
|
|
193 |
with gr.Column(scale=1, elem_id="chat-container"):
|
194 |
chatbot = gr.Chatbot(
|
195 |
-
value=
|
196 |
elem_id="chatbot",
|
197 |
bubble_full_width=False,
|
198 |
label="Safe Chatbot v1"
|
@@ -204,22 +214,23 @@ with gr.Blocks(css=css) as demo:
|
|
204 |
|
205 |
btn.click(
|
206 |
fn=process_response,
|
207 |
-
inputs=[txt,
|
208 |
-
outputs=[chatbot,
|
209 |
-
|
210 |
)
|
211 |
examples_component = gr.Examples(
|
212 |
-
|
213 |
-
|
214 |
-
|
215 |
-
|
216 |
-
initial_question_input.submit(
|
217 |
-
fn=initialize_chat,
|
218 |
-
inputs=[initial_question_input],
|
219 |
-
outputs=[chatbot, follow_up_questions_md, token_info]
|
220 |
-
)
|
221 |
|
222 |
chatbot.like(print_like_dislike, None, None)
|
223 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
224 |
if __name__ == "__main__":
|
225 |
demo.launch(share=False)
|
|
|
42 |
chat_history = [(None, initial_question)]
|
43 |
response, follow_up_questions, token_info = generate_response(initial_question, 0)
|
44 |
chat_history.append((None, response))
|
45 |
+
|
46 |
+
# Extract follow-up questions as examples
|
47 |
+
follow_up_questions_formatted = [q.strip() for q in follow_up_questions.split('\n') if q.strip()]
|
48 |
+
examples_state = [[q] for q in follow_up_questions_formatted]
|
49 |
+
|
50 |
+
return chat_history, follow_up_questions, token_info, examples_state
|
51 |
|
52 |
def generate_response(prompt, token_count=0):
|
53 |
print(f"Received prompt: {prompt}")
|
|
|
165 |
|
166 |
# Initialize the chat history and suggested questionsw
|
167 |
# Initialize the chat history and suggested questions
|
168 |
+
#chat_history, follow_up_questions, initial_token_info = initialize_chat("I'm 14 years old female and want to become a graphic designer. I'm living in Uttar Pradesh in India. How can I start?")
|
169 |
|
170 |
|
171 |
# Initial example questions from the initialization
|
172 |
+
|
|
|
173 |
|
174 |
with gr.Blocks(css=css) as demo:
|
175 |
+
examples_state = gr.State([])
|
176 |
+
chat_history = gr.State([])
|
177 |
+
token_info = gr.State("")
|
178 |
+
follow_up_questions_md = gr.State("")
|
179 |
+
|
180 |
with gr.Row():
|
181 |
with gr.Column(scale=1):
|
182 |
gr.Markdown(
|
|
|
185 |
In the realm of digital communication, the development of an advanced chatbot that incorporates topic modeling represents a significant leap towards enhancing user interaction and maintaining focus during conversations. This innovative chatbot design is specifically engineered to streamline discussions by guiding users to select from a curated list of suggested questions. This approach is crafted to mitigate the risk of diverging into off-topic dialogues, which are common pitfalls in conventional chatbot systems.
|
186 |
"""
|
187 |
)
|
188 |
+
token_info_display = gr.Markdown(
|
189 |
+
value="",
|
190 |
elem_id="token-info"
|
191 |
)
|
192 |
+
follow_up_questions_display = gr.Markdown(
|
193 |
+
value="",
|
194 |
elem_id="follow-up-questions",
|
195 |
+
label="Follow up Questions"
|
196 |
)
|
197 |
initial_question_input = gr.Textbox(
|
198 |
placeholder="Type your initial question here...",
|
199 |
label="Initial Question"
|
200 |
)
|
201 |
+
initialize_button = gr.Button("Initialize Chat")
|
202 |
+
|
203 |
with gr.Column(scale=1, elem_id="chat-container"):
|
204 |
chatbot = gr.Chatbot(
|
205 |
+
value=[],
|
206 |
elem_id="chatbot",
|
207 |
bubble_full_width=False,
|
208 |
label="Safe Chatbot v1"
|
|
|
214 |
|
215 |
btn.click(
|
216 |
fn=process_response,
|
217 |
+
inputs=[txt, chat_history, gr.State(0), examples_state],
|
218 |
+
outputs=[chatbot, token_info_display, follow_up_questions_display, examples_state]
|
|
|
219 |
)
|
220 |
examples_component = gr.Examples(
|
221 |
+
examples=examples_state.value,
|
222 |
+
inputs=[txt],
|
223 |
+
label="Questions"
|
224 |
+
)
|
|
|
|
|
|
|
|
|
|
|
225 |
|
226 |
chatbot.like(print_like_dislike, None, None)
|
227 |
|
228 |
+
initialize_button.click(
|
229 |
+
fn=initialize_chat,
|
230 |
+
inputs=[initial_question_input],
|
231 |
+
outputs=[chat_history, follow_up_questions_display, token_info_display, examples_state]
|
232 |
+
)
|
233 |
+
chatbot.set(chat_history)
|
234 |
+
|
235 |
if __name__ == "__main__":
|
236 |
demo.launch(share=False)
|