pvanand commited on
Commit
fe8c198
·
verified ·
1 Parent(s): c182518

Update main.py

Browse files
Files changed (1) hide show
  1. main.py +15 -13
main.py CHANGED
@@ -142,21 +142,23 @@ prompt = ChatPromptTemplate.from_messages([
142
  ])
143
 
144
  def get_collection_files(collection_id: str, user_id: str) -> str:
145
- """Get list of files in the specified collection"""
146
  try:
147
- # Get the full collection name
148
- collection_name = f"{user_id}_{collection_id}"
149
-
150
- # Open the table and convert to pandas
151
- table = db.open_table(collection_name)
152
- df = table.to_pandas()
153
- logging.info(f"fetched chunks {str(df.head())}")
154
-
155
- # Get unique file names
156
- unique_files = df['file_name'].unique()
157
 
158
- # Join the file names into a string
159
- return ", ".join(unique_files)
 
 
 
160
  except Exception as e:
161
  logging.error(f"Error getting collection files: {str(e)}")
162
  return f"Error getting files: {str(e)}"
 
142
  ])
143
 
144
  def get_collection_files(collection_id: str, user_id: str) -> str:
145
+ """Get list of files in the specified collection using the external API"""
146
  try:
147
+ url = f"https://pvanand-documind-api-v2.hf.space/rag/get_collection_files"
148
+ params = {
149
+ "collection_id": collection_id,
150
+ "user_id": user_id
151
+ }
152
+ headers = {
153
+ 'accept': 'application/json'
154
+ }
155
+ response = requests.post(url, params=params, headers=headers, data='')
 
156
 
157
+ if response.status_code == 200:
158
+ return response.text
159
+ else:
160
+ logging.error(f"Error from API: {response.text}")
161
+ return f"Error getting files: {response.text}"
162
  except Exception as e:
163
  logging.error(f"Error getting collection files: {str(e)}")
164
  return f"Error getting files: {str(e)}"