PierreBrunelle commited on
Commit
dba0e44
·
verified ·
1 Parent(s): f618a2b

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +10 -14
app.py CHANGED
@@ -43,23 +43,20 @@ def validate_token(token):
43
  except Exception:
44
  return False
45
 
46
- def get_user_dir(username):
47
- return f'chatbot_demo_{username}'
48
-
49
  def process_files(token, pdf_files, chunk_limit, chunk_separator):
50
- username = validate_token(token)
51
- if not username:
52
  return "Invalid token. Please enter a valid Hugging Face token."
53
 
54
  user_dir = get_user_dir(username)
55
 
56
  # Initialize Pixeltable
57
- pxt.drop_dir('user_dir', force=True)
58
- pxt.create_dir('user_dir')
59
 
60
  # Create a table to store the uploaded PDF documents
61
  t = pxt.create_table(
62
- f'{user_dir}.documents',
63
  {'document': pxt.DocumentType(nullable=True),
64
  'question': pxt.StringType(nullable=True)}
65
  )
@@ -69,7 +66,7 @@ def process_files(token, pdf_files, chunk_limit, chunk_separator):
69
 
70
  # Create a view that splits the documents into smaller chunks
71
  chunks_t = pxt.create_view(
72
- f'{user_dir}.chunks',
73
  t,
74
  iterator=DocumentSplitter.create(
75
  document=t.document,
@@ -124,13 +121,12 @@ def process_files(token, pdf_files, chunk_limit, chunk_separator):
124
  return "Files processed successfully. You can start the discussion."
125
 
126
  def get_answer(token, msg):
127
- username = validate_token(token)
128
- if not username:
129
  return "Invalid token. Please enter a valid Hugging Face token."
130
 
131
- user_dir = get_user_dir(username)
132
- t = pxt.get_table(f'{user_dir}.documents')
133
- chunks_t = pxt.get_table(f'{user_dir}.chunks')
134
 
135
  # Insert the question into the table
136
  t.insert([{'question': msg}])
 
43
  except Exception:
44
  return False
45
 
 
 
 
46
  def process_files(token, pdf_files, chunk_limit, chunk_separator):
47
+ if not validate_token(token):
48
+
49
  return "Invalid token. Please enter a valid Hugging Face token."
50
 
51
  user_dir = get_user_dir(username)
52
 
53
  # Initialize Pixeltable
54
+ pxt.drop_dir('chatbot_demo', force=True)
55
+ pxt.create_dir('chatbot_demo')
56
 
57
  # Create a table to store the uploaded PDF documents
58
  t = pxt.create_table(
59
+ 'chatbot_demo.documents',
60
  {'document': pxt.DocumentType(nullable=True),
61
  'question': pxt.StringType(nullable=True)}
62
  )
 
66
 
67
  # Create a view that splits the documents into smaller chunks
68
  chunks_t = pxt.create_view(
69
+ 'chatbot_demo.chunks',
70
  t,
71
  iterator=DocumentSplitter.create(
72
  document=t.document,
 
121
  return "Files processed successfully. You can start the discussion."
122
 
123
  def get_answer(token, msg):
124
+ if not validate_token(token):
125
+
126
  return "Invalid token. Please enter a valid Hugging Face token."
127
 
128
+ t = pxt.get_table('chatbot_demo.documents')
129
+ chunks_t = pxt.get_table('chatbot_demo.chunks')
 
130
 
131
  # Insert the question into the table
132
  t.insert([{'question': msg}])