shukdevdattaEX commited on
Commit
c1f0fa6
·
verified ·
1 Parent(s): 0622d38

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +18 -5
app.py CHANGED
@@ -67,19 +67,28 @@ def chat_with_docs(message, history, api_key):
67
  global chat_engine, conversation_history
68
 
69
  if not api_key:
70
- return history + [("Please enter your OpenAI API key first.", None)]
71
 
72
  if chat_engine is None:
73
- return history + [(message, "Please upload and load documents first before asking questions.")]
 
 
 
74
 
75
  try:
76
  response = chat_engine.chat(message)
77
  conversation_history.append({"role": "user", "content": message})
78
  conversation_history.append({"role": "assistant", "content": response.response})
79
 
80
- return history + [(message, response.response)]
 
 
 
81
  except Exception as e:
82
- return history + [(message, f"Error: {str(e)}")]
 
 
 
83
 
84
  # Function to save conversation
85
  def save_conversation():
@@ -171,7 +180,11 @@ with gr.Blocks(title="Chat with Documents 💬 📚") as demo:
171
 
172
  with gr.Row():
173
  with gr.Column(scale=3):
174
- chatbot = gr.Chatbot(label="Chat", height=400)
 
 
 
 
175
  msg = gr.Textbox(
176
  label="Your Question",
177
  placeholder="Ask a question about your documents..."
 
67
  global chat_engine, conversation_history
68
 
69
  if not api_key:
70
+ return history + [{"role": "assistant", "content": "Please enter your OpenAI API key first."}]
71
 
72
  if chat_engine is None:
73
+ return history + [
74
+ {"role": "user", "content": message},
75
+ {"role": "assistant", "content": "Please upload and load documents first before asking questions."}
76
+ ]
77
 
78
  try:
79
  response = chat_engine.chat(message)
80
  conversation_history.append({"role": "user", "content": message})
81
  conversation_history.append({"role": "assistant", "content": response.response})
82
 
83
+ return history + [
84
+ {"role": "user", "content": message},
85
+ {"role": "assistant", "content": response.response}
86
+ ]
87
  except Exception as e:
88
+ return history + [
89
+ {"role": "user", "content": message},
90
+ {"role": "assistant", "content": f"Error: {str(e)}"}
91
+ ]
92
 
93
  # Function to save conversation
94
  def save_conversation():
 
180
 
181
  with gr.Row():
182
  with gr.Column(scale=3):
183
+ chatbot = gr.Chatbot(
184
+ label="Chat",
185
+ height=400,
186
+ type="messages" # Explicitly set type to messages
187
+ )
188
  msg = gr.Textbox(
189
  label="Your Question",
190
  placeholder="Ask a question about your documents..."