tcy6 commited on
Commit
1bc6d88
1 Parent(s): 43b7834

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +6 -7
app.py CHANGED
@@ -19,6 +19,8 @@ import json
19
  cache_dir = '/data/KB'
20
  os.makedirs(cache_dir, exist_ok=True)
21
 
 
 
22
  @spaces.GPU
23
  def weighted_mean_pooling(hidden, attention_mask):
24
  attention_mask_ = attention_mask * attention_mask.cumsum(dim=1)
@@ -64,15 +66,12 @@ def calculate_md5_from_binary(binary_data):
64
  return hash_md5.hexdigest()
65
 
66
  @spaces.GPU
67
- def add_pdf_gradio(pdf_file_binary, progress=gr.Progress()):
68
  global model, tokenizer
69
  model.eval()
70
-
71
- print(f"type pdf_file_binary: {type(pdf_file_binary)}")
72
- print(f"len(pdf_file_binary): {len(pdf_file_binary)}")
73
- print(f"type pdf_file_binary[0]: {type(pdf_file_binary[0])}")
74
 
75
- knowledge_base_name = calculate_md5_from_binary(pdf_file_binary)
76
 
77
  this_cache_dir = os.path.join(cache_dir, knowledge_base_name)
78
  os.makedirs(this_cache_dir, exist_ok=True)
@@ -261,7 +260,7 @@ with gr.Blocks() as app:
261
  gr.Markdown("- Currently online demo support PDF document with less than 50 pages due to GPU time limit. Deploy on your own machine for longer PDFs and books.")
262
 
263
  with gr.Row():
264
- file_input = gr.File(file_types=["pdf"], file_count="multiple", type="binary", label="Step 1: Upload PDF")
265
  file_result = gr.Text(label="Knowledge Base ID (remember it, it is re-usable!)")
266
  process_button = gr.Button("Process PDF (Don't click until PDF upload success)")
267
 
 
19
  cache_dir = '/data/KB'
20
  os.makedirs(cache_dir, exist_ok=True)
21
 
22
+
23
+
24
  @spaces.GPU
25
  def weighted_mean_pooling(hidden, attention_mask):
26
  attention_mask_ = attention_mask * attention_mask.cumsum(dim=1)
 
66
  return hash_md5.hexdigest()
67
 
68
  @spaces.GPU
69
+ def add_pdf_gradio(pdf_file_path, progress=gr.Progress()):
70
  global model, tokenizer
71
  model.eval()
72
+ print(f"pdf_file_path: {pdf_file_path}")
 
 
 
73
 
74
+ knowledge_base_name = calculate_md5_from_binary(pdf_file_path)
75
 
76
  this_cache_dir = os.path.join(cache_dir, knowledge_base_name)
77
  os.makedirs(this_cache_dir, exist_ok=True)
 
260
  gr.Markdown("- Currently online demo support PDF document with less than 50 pages due to GPU time limit. Deploy on your own machine for longer PDFs and books.")
261
 
262
  with gr.Row():
263
+ file_input = gr.File(file_types=["pdf"], label="Step 1: Upload PDF")
264
  file_result = gr.Text(label="Knowledge Base ID (remember it, it is re-usable!)")
265
  process_button = gr.Button("Process PDF (Don't click until PDF upload success)")
266