runsdata commited on
Commit
16a48b6
·
1 Parent(s): 5b6ed4a

Added user information input

Browse files
Files changed (1) hide show
  1. app.py +11 -12
app.py CHANGED
@@ -71,18 +71,17 @@ 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, 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))
@@ -136,22 +135,22 @@ def reset_flag():
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 start a new case, press clear.</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
 
 
71
  is_first_run = True # Flag to check if it's the first run
72
 
73
  # Here is the langchain
74
+ def predict(history, user_info, input):
75
+ global is_first_run
 
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: {user_info}"))
85
  for human, ai in history:
86
  history_langchain_format.append(HumanMessage(content=human))
87
  history_langchain_format.append(AIMessage(content=ai))
 
135
  global is_first_run
136
  is_first_run = True
137
 
138
+ # Gradio Interface
139
  with gr.Blocks() as demo:
140
  gr.Markdown("""<h1><center>TROUBLESHOOTING Bot by CIONIC</center></h1>""")
141
+ gr.Markdown("""<p><center>To start a new case, enter your information and press clear.</center></p>""")
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, user_info_textbox])
146
  clear_button.click(reset_flag, None, None)
147
 
148
+ # Submit user and bot functions
149
  textbox.submit(user, [textbox, chatbot], [textbox, chatbot], queue=False).then(
150
+ lambda args: bot(chatbot, user_info_textbox.value), chatbot, chatbot,
151
  )
 
152
 
153
+ # Enable queuing and launch the app
154
  demo.queue()
155
  demo.launch(debug=True)
156