Юра Цепліцький commited on
Commit
961c967
·
1 Parent(s): 693d949

Edit file uploading

Browse files
__pycache__/main.cpython-312.pyc CHANGED
Binary files a/__pycache__/main.cpython-312.pyc and b/__pycache__/main.cpython-312.pyc differ
 
app.py CHANGED
@@ -2,7 +2,8 @@ import gradio as gr
2
  from main import (
3
  answer_query,
4
  set_keys,
5
- process_file
 
6
  )
7
 
8
  from pydantic import ConfigDict
@@ -18,7 +19,7 @@ setting_keys = gr.Interface(
18
  )
19
 
20
  uploading_files = gr.Interface(
21
- fn=process_file,
22
  inputs=gr.File(
23
  label="Upload a file",
24
  file_count="single",
 
2
  from main import (
3
  answer_query,
4
  set_keys,
5
+ process_file,
6
+ handle_file
7
  )
8
 
9
  from pydantic import ConfigDict
 
19
  )
20
 
21
  uploading_files = gr.Interface(
22
+ fn=handle_file,
23
  inputs=gr.File(
24
  label="Upload a file",
25
  file_count="single",
main.py CHANGED
@@ -1,8 +1,9 @@
1
  from utils.retriever import get_query_engine
2
  from utils.index import create_index
3
- from utils.constant import INDEX_PATH
4
  import os
5
  from pathlib import Path
 
6
 
7
  def set_keys(co_api_key: str, llama_cloud_api_key: str) -> str:
8
  try:
@@ -30,7 +31,21 @@ def process_file(file) -> str:
30
  create_index(filepath, INDEX_PATH)
31
  return "File indexed successfully"
32
  except Exception as e:
33
- return str(e)
 
 
 
 
 
 
 
 
 
 
 
 
 
 
34
 
35
  def answer_query(query: str) -> str:
36
 
 
1
  from utils.retriever import get_query_engine
2
  from utils.index import create_index
3
+ from utils.constant import INDEX_PATH, DATA_PATH
4
  import os
5
  from pathlib import Path
6
+ import shutil
7
 
8
  def set_keys(co_api_key: str, llama_cloud_api_key: str) -> str:
9
  try:
 
31
  create_index(filepath, INDEX_PATH)
32
  return "File indexed successfully"
33
  except Exception as e:
34
+ return str(e)
35
+
36
+ def handle_file(uploaded_file):
37
+ try:
38
+
39
+ temp_file_path = uploaded_file.name
40
+ save_file_path = os.path.join(DATA_PATH, "paper.pdf")
41
+
42
+ shutil.move(temp_file_path, save_file_path)
43
+
44
+ create_index(DATA_PATH, INDEX_PATH)
45
+ return "File uploaded and indexed"
46
+
47
+ except Exception as e:
48
+ return str(e)
49
 
50
  def answer_query(query: str) -> str:
51
 
uploaded_files/paper.pdf ADDED
Binary file (775 kB). View file
 
utils/__pycache__/constant.cpython-312.pyc CHANGED
Binary files a/utils/__pycache__/constant.cpython-312.pyc and b/utils/__pycache__/constant.cpython-312.pyc differ
 
utils/__pycache__/retriever.cpython-312.pyc CHANGED
Binary files a/utils/__pycache__/retriever.cpython-312.pyc and b/utils/__pycache__/retriever.cpython-312.pyc differ
 
utils/__pycache__/settings.cpython-312.pyc CHANGED
Binary files a/utils/__pycache__/settings.cpython-312.pyc and b/utils/__pycache__/settings.cpython-312.pyc differ
 
utils/constant.py CHANGED
@@ -1,4 +1,4 @@
1
- DOC_PATH = "./data"
2
  INDEX_PATH = "./index"
3
 
4
  TOP_K_RETRIEVAL = 10
 
1
+ DATA_PATH = "./data"
2
  INDEX_PATH = "./index"
3
 
4
  TOP_K_RETRIEVAL = 10
utils/index.py CHANGED
@@ -47,7 +47,7 @@ def load_index(path: str):
47
 
48
  if __name__ == "__main__":
49
 
50
- doc_path = DOC_PATH
51
  index_path = INDEX_PATH
52
 
53
  create_index(doc_path, index_path)
 
47
 
48
  if __name__ == "__main__":
49
 
50
+ doc_path = DATA_PATH
51
  index_path = INDEX_PATH
52
 
53
  create_index(doc_path, index_path)