Spaces:
YZ03
/
Runtime error

YZ03 commited on
Commit
0ce7032
·
verified ·
1 Parent(s): b1e3f17

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +29 -9
app.py CHANGED
@@ -112,10 +112,29 @@ agent_with_chat_history = RunnableWithMessageHistory(
112
  input_messages_key="query",
113
  history_messages_key="chat_history",
114
  )
 
 
 
 
 
 
 
 
 
 
 
115
  # Gradio chat response function
116
 
117
  def respond(message, history: list[dict]):
118
 
 
 
 
 
 
 
 
 
119
  # Step 1: Embed user message
120
  try:
121
  vectorized_input = embedding_model.embed_query(message)
@@ -139,15 +158,16 @@ def respond(message, history: list[dict]):
139
  matches = pinecone_response.get("matches", [])
140
  context = "\n".join([match['metadata']['text'] for match in matches if 'metadata' in match])
141
  print("From Pinecone:", context)
142
- pinecone_journal_response = index.query(
143
- namespace="Lina",
144
- vector=vectorized_input,
145
- top_k=3,
146
- include_metadata=True
147
- )
148
- journal_matches = pinecone_journal_response.get("matches", [])
149
- journal_context = "\n".join([match['metadata']['text'] for match in journal_matches if 'metadata' in match])
150
- print("From Pinecone:", journal_context)
 
151
  except:
152
  print("Pinecone query failed.")
153
  else:
 
112
  input_messages_key="query",
113
  history_messages_key="chat_history",
114
  )
115
+
116
+ def login(message, history):
117
+ if "Lina" in message.lower():
118
+ username = "Lina"
119
+ return username
120
+ elif "Guest" in message.lower():
121
+ username = "Guest"
122
+ return username
123
+ else:
124
+ return "Please ask about username.", None
125
+
126
  # Gradio chat response function
127
 
128
  def respond(message, history: list[dict]):
129
 
130
+ with gr.Column():
131
+ gr.ChatInterface(
132
+ login,
133
+ examples=["Guest", "Lina"],
134
+ additional_outputs=[code],
135
+ type="messages"
136
+ )
137
+
138
  # Step 1: Embed user message
139
  try:
140
  vectorized_input = embedding_model.embed_query(message)
 
158
  matches = pinecone_response.get("matches", [])
159
  context = "\n".join([match['metadata']['text'] for match in matches if 'metadata' in match])
160
  print("From Pinecone:", context)
161
+ if username == "Lina":
162
+ pinecone_journal_response = index.query(
163
+ namespace=username,
164
+ vector=vectorized_input,
165
+ top_k=3,
166
+ include_metadata=True
167
+ )
168
+ journal_matches = pinecone_journal_response.get("matches", [])
169
+ journal_context = "\n".join([match['metadata']['text'] for match in journal_matches if 'metadata' in match])
170
+ print("From Pinecone:", journal_context)
171
  except:
172
  print("Pinecone query failed.")
173
  else: