anand004 commited on
Commit
ec8cbb9
·
unverified ·
1 Parent(s): e979e49

update app.py

Browse files
Files changed (1) hide show
  1. app.py +14 -7
app.py CHANGED
@@ -61,12 +61,12 @@ def get_image_description(image):
61
  torch.cuda.empty_cache()
62
  gc.collect()
63
 
 
64
  prompt = "[INST] <image>\nDescribe the image in a sentence [/INST]"
65
- n = len(prompt)
66
 
67
  inputs = processor(prompt, image, return_tensors="pt").to("cuda:0")
68
  output = vision_model.generate(**inputs, max_new_tokens=100)
69
- return processor.decode(output[0][n:], skip_special_tokens=True)
70
 
71
 
72
  CSS = """
@@ -103,9 +103,6 @@ def get_vectordb(text, images, img_doc_files):
103
  descs.append(img_doc_files[i] + "\n" + get_image_description(images[i]))
104
  except:
105
  descs.append("Could not generate image description due to some error")
106
- print(img_doc_files)
107
- print(images[i])
108
- print()
109
  print(descs[-1])
110
  print()
111
 
@@ -454,12 +451,22 @@ with gr.Blocks(css=CSS, theme=gr.themes.Soft(text_size=sizes.text_md)) as demo:
454
  ],
455
  [chatbot, references, ret_images],
456
  )
457
-
458
  msg.submit(
459
  conversation,
460
- [vectordb, msg, num_context, img_context, chatbot, hf_token, model_path],
 
 
 
 
 
 
 
 
 
 
461
  [chatbot, references, ret_images],
462
  )
 
463
  documents.change(
464
  lambda: "<h1 style='text-align: center'>Click the 'Extract' button to extract data from PDFs<h1>",
465
  None,
 
61
  torch.cuda.empty_cache()
62
  gc.collect()
63
 
64
+ # n = len(prompt)
65
  prompt = "[INST] <image>\nDescribe the image in a sentence [/INST]"
 
66
 
67
  inputs = processor(prompt, image, return_tensors="pt").to("cuda:0")
68
  output = vision_model.generate(**inputs, max_new_tokens=100)
69
+ return processor.decode(output[0], skip_special_tokens=True)
70
 
71
 
72
  CSS = """
 
103
  descs.append(img_doc_files[i] + "\n" + get_image_description(images[i]))
104
  except:
105
  descs.append("Could not generate image description due to some error")
 
 
 
106
  print(descs[-1])
107
  print()
108
 
 
451
  ],
452
  [chatbot, references, ret_images],
453
  )
 
454
  msg.submit(
455
  conversation,
456
+ [
457
+ vectordb,
458
+ msg,
459
+ num_context,
460
+ img_context,
461
+ chatbot,
462
+ temp,
463
+ max_tokens,
464
+ hf_token,
465
+ model_path,
466
+ ],
467
  [chatbot, references, ret_images],
468
  )
469
+
470
  documents.change(
471
  lambda: "<h1 style='text-align: center'>Click the 'Extract' button to extract data from PDFs<h1>",
472
  None,