Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
@@ -3,11 +3,15 @@ import torch
|
|
3 |
from transformers import AutoProcessor, UdopForConditionalGeneration
|
4 |
# from datasets import load_dataset
|
5 |
|
6 |
-
|
7 |
-
|
|
|
|
|
|
|
|
|
8 |
|
9 |
st.title("CIC Demo (by ITT)")
|
10 |
-
st.write("
|
11 |
|
12 |
# File selection
|
13 |
uploaded_files = st.file_uploader("Upload document(s) [/image(s)]:", type=["docx", "pdf", "pptx", "jpg", "jpeg", "png"], accept_multiple_files=True)
|
@@ -25,10 +29,10 @@ if selected_file is not None and selected_file != "None":
|
|
25 |
testButton = st.button("Test Model")
|
26 |
if testButton and selected_file != "None":
|
27 |
st.write("Testing the model with the selected image...")
|
|
|
|
|
|
|
28 |
elif testButton and selected_file == "None":
|
29 |
-
st.write("Please upload and select an image.")
|
30 |
|
31 |
-
# encoding = processor(image, question, words, boxes=boxes, return_tensors="pt")
|
32 |
|
33 |
-
# predicted_ids = model.generate(**encoding)
|
34 |
-
# print(processor.batch_decode(predicted_ids, skip_special_tokens=True)[0])
|
|
|
3 |
from transformers import AutoProcessor, UdopForConditionalGeneration
|
4 |
# from datasets import load_dataset
|
5 |
|
6 |
+
device = torch.device("cuda" if torch.cuda.is_available() else "cpu")
|
7 |
+
|
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 |
|
16 |
# File selection
|
17 |
uploaded_files = st.file_uploader("Upload document(s) [/image(s)]:", type=["docx", "pdf", "pptx", "jpg", "jpeg", "png"], accept_multiple_files=True)
|
|
|
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 |
|
|
|
38 |
|
|
|
|