kh-CHEUNG commited on
Commit
db0d96f
·
verified ·
1 Parent(s): fa27310

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +13 -7
app.py CHANGED
@@ -8,8 +8,6 @@ device = torch.device("cuda" if torch.cuda.is_available() else "cpu")
8
  processor = AutoProcessor.from_pretrained("microsoft/udop-large", apply_ocr=True)
9
  model = UdopForConditionalGeneration.from_pretrained("microsoft/udop-large")
10
 
11
- question = "Question answering. How many unsafe practice of Lifting Operation"
12
-
13
  st.title("CIC Demo (by ITT)")
14
  st.write("Upload and Select a document (/an image) to test the model.")
15
 
@@ -21,17 +19,25 @@ selected_file = st.selectbox("Select a document (/an image):", uploaded_files, f
21
  if selected_file is not None and selected_file != "None":
22
  file_extension = selected_file.name.split(".")[-1]
23
  if file_extension in ["jpg", "jpeg", "png"]:
24
- st.image(selected_file, caption="Selected Image")
25
  else:
26
  st.write("Selected file: ", selected_file.name)
27
 
28
- # Model testing button
 
29
  testButton = st.button("Test Model")
 
 
 
 
 
30
  if testButton and selected_file != "None":
31
  st.write("Testing the model with the selected image...")
32
- encoding = processor(image, question, words, boxes=boxes, return_tensors="pt")
33
- predicted_ids = model.generate(**encoding)
34
- print(processor.batch_decode(predicted_ids, skip_special_tokens=True)[0])
 
 
35
  elif testButton and selected_file == "None":
36
  st.write("Please upload and select a document (/an image).")
37
 
 
8
  processor = AutoProcessor.from_pretrained("microsoft/udop-large", apply_ocr=True)
9
  model = UdopForConditionalGeneration.from_pretrained("microsoft/udop-large")
10
 
 
 
11
  st.title("CIC Demo (by ITT)")
12
  st.write("Upload and Select a document (/an image) to test the model.")
13
 
 
19
  if selected_file is not None and selected_file != "None":
20
  file_extension = selected_file.name.split(".")[-1]
21
  if file_extension in ["jpg", "jpeg", "png"]:
22
+ image = st.image(selected_file, caption="Selected Image")
23
  else:
24
  st.write("Selected file: ", selected_file.name)
25
 
26
+ # Model Testing
27
+ ## Test button
28
  testButton = st.button("Test Model")
29
+
30
+ ## Question (/Prompt)
31
+ question = "Question answering. How many unsafe practice of Lifting Operation?"
32
+
33
+ ## Perform Model Testing when Image is uploaded and selected as well as Test button is pressed
34
  if testButton and selected_file != "None":
35
  st.write("Testing the model with the selected image...")
36
+ # encoding = processor(image, question, words, boxes=boxes, return_tensors="pt")
37
+ model_encoding = processor(iamges=image, text=question, return_tensors="pt")
38
+ model_output = model.generate(**model_encoding)
39
+ output_text = processor.batch_decode(model_output, skip_special_tokens=True)[0]
40
+ st.write(output_text)
41
  elif testButton and selected_file == "None":
42
  st.write("Please upload and select a document (/an image).")
43