Spaces:
Build error
Build error
Removed user info add - causing bugs
Browse files
app.py
CHANGED
|
@@ -71,17 +71,18 @@ def get_full_context(input):
|
|
| 71 |
is_first_run = True # Flag to check if it's the first run
|
| 72 |
|
| 73 |
# Here is the langchain
|
| 74 |
-
def predict(history,
|
| 75 |
-
|
|
|
|
| 76 |
if is_first_run:
|
| 77 |
context = get_full_context(input)
|
| 78 |
print(context) # For debugging
|
| 79 |
-
is_first_run = False
|
| 80 |
else:
|
| 81 |
context = ""
|
| 82 |
|
| 83 |
history_langchain_format = []
|
| 84 |
-
history_langchain_format.append(SystemMessage(content=f"{ORIG_SYSTEM_MESSAGE_PROMPT}, here is the user information: {
|
| 85 |
for human, ai in history:
|
| 86 |
history_langchain_format.append(HumanMessage(content=human))
|
| 87 |
history_langchain_format.append(AIMessage(content=ai))
|
|
@@ -109,10 +110,10 @@ def user(user_message, chatbot_history):
|
|
| 109 |
return "", chatbot_history + [[user_message, ""]]
|
| 110 |
|
| 111 |
# Function to handle AI's response
|
| 112 |
-
def bot(chatbot_history
|
| 113 |
-
user_message = chatbot_history[-1][0] #
|
| 114 |
# Call the predict function to get the AI's response
|
| 115 |
-
pairs = predict(chatbot_history,
|
| 116 |
_, ai_response = pairs[-1] # Get the latest response
|
| 117 |
|
| 118 |
response_in_progress = ""
|
|
@@ -135,22 +136,22 @@ def reset_flag():
|
|
| 135 |
global is_first_run
|
| 136 |
is_first_run = True
|
| 137 |
|
| 138 |
-
# Gradio
|
| 139 |
with gr.Blocks() as demo:
|
| 140 |
gr.Markdown("""<h1><center>TROUBLESHOOTING Bot by CIONIC</center></h1>""")
|
| 141 |
-
gr.Markdown("""<p><center>To
|
| 142 |
-
user_info_textbox = gr.Textbox(placeholder="Enter your information here", value="Name: Bob, Phone: iPhone 10, SN: 123456789")
|
| 143 |
chatbot = gr.Chatbot()
|
| 144 |
textbox = gr.Textbox()
|
| 145 |
-
clear_button = gr.ClearButton(components=[chatbot
|
| 146 |
clear_button.click(reset_flag, None, None)
|
| 147 |
|
| 148 |
-
#
|
| 149 |
textbox.submit(user, [textbox, chatbot], [textbox, chatbot], queue=False).then(
|
| 150 |
-
|
| 151 |
)
|
|
|
|
| 152 |
|
| 153 |
-
# Enable queuing
|
| 154 |
demo.queue()
|
| 155 |
demo.launch(debug=True)
|
| 156 |
|
|
|
|
| 71 |
is_first_run = True # Flag to check if it's the first run
|
| 72 |
|
| 73 |
# Here is the langchain
|
| 74 |
+
def predict(history, input):
|
| 75 |
+
|
| 76 |
+
global is_first_run # Use the global flag
|
| 77 |
if is_first_run:
|
| 78 |
context = get_full_context(input)
|
| 79 |
print(context) # For debugging
|
| 80 |
+
is_first_run = False # Set the flag to False after the first run
|
| 81 |
else:
|
| 82 |
context = ""
|
| 83 |
|
| 84 |
history_langchain_format = []
|
| 85 |
+
history_langchain_format.append(SystemMessage(content=f"{ORIG_SYSTEM_MESSAGE_PROMPT}, here is the user information: {user_info_simulated}"))
|
| 86 |
for human, ai in history:
|
| 87 |
history_langchain_format.append(HumanMessage(content=human))
|
| 88 |
history_langchain_format.append(AIMessage(content=ai))
|
|
|
|
| 110 |
return "", chatbot_history + [[user_message, ""]]
|
| 111 |
|
| 112 |
# Function to handle AI's response
|
| 113 |
+
def bot(chatbot_history):
|
| 114 |
+
user_message = chatbot_history[-1][0] #This line is because we cleared the user_message previously in the user function above
|
| 115 |
# Call the predict function to get the AI's response
|
| 116 |
+
pairs = predict(chatbot_history, user_message)
|
| 117 |
_, ai_response = pairs[-1] # Get the latest response
|
| 118 |
|
| 119 |
response_in_progress = ""
|
|
|
|
| 136 |
global is_first_run
|
| 137 |
is_first_run = True
|
| 138 |
|
| 139 |
+
# The Gradio App interface
|
| 140 |
with gr.Blocks() as demo:
|
| 141 |
gr.Markdown("""<h1><center>TROUBLESHOOTING Bot by CIONIC</center></h1>""")
|
| 142 |
+
gr.Markdown("""<p><center>To open a new case, press the clear button.</center></p>""")
|
|
|
|
| 143 |
chatbot = gr.Chatbot()
|
| 144 |
textbox = gr.Textbox()
|
| 145 |
+
clear_button = gr.ClearButton(components=[chatbot])
|
| 146 |
clear_button.click(reset_flag, None, None)
|
| 147 |
|
| 148 |
+
# Chain user and bot functions with `.then()`
|
| 149 |
textbox.submit(user, [textbox, chatbot], [textbox, chatbot], queue=False).then(
|
| 150 |
+
bot, chatbot, chatbot,
|
| 151 |
)
|
| 152 |
+
chatbot.like(vote, None, None)
|
| 153 |
|
| 154 |
+
# Enable queuing
|
| 155 |
demo.queue()
|
| 156 |
demo.launch(debug=True)
|
| 157 |
|