kh-CHEUNG commited on
Commit
8836465
·
verified ·
1 Parent(s): a50b559

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +40 -29
app.py CHANGED
@@ -12,36 +12,47 @@ model = UdopForConditionalGeneration.from_pretrained("microsoft/udop-large")
12
  st.title("CIC Demo (by ITT)")
13
  st.write("Upload and Select a document (/an image) to test the model.")
14
 
15
- # File selection
16
- uploaded_files = st.file_uploader("Upload document(s) [/image(s)]:", type=["docx", "pdf", "pptx", "jpg", "jpeg", "png"], accept_multiple_files=True)
17
- selected_file = st.selectbox("Select a document (/an image):", uploaded_files, format_func=lambda file: file.name if file else "None")
18
-
19
- # Display selected file
20
- if selected_file is not None and selected_file != "None":
21
- file_extension = selected_file.name.split(".")[-1]
22
- if file_extension in ["jpg", "jpeg", "png"]:
23
- image = Image.open(selected_file).convert("RGB")
24
- st.image(selected_file, caption="Selected Image")
25
- else:
26
- st.write("Selected file: ", selected_file.name)
 
 
 
 
27
 
28
  # Model Testing
29
- ## Test button
30
- testButton = st.button("Test Model")
31
-
32
- ## Question (/Prompt)
33
- # question = "Question answering. How many unsafe practice of Lifting Operation?"
34
- question = "Question answering. Is is a scene of Lifting Operation?"
35
-
36
- ## Perform Model Testing when Image is uploaded and selected as well as Test button is pressed
37
- if testButton and selected_file != "None":
38
- st.write("Testing the model with the selected image...")
39
- # encoding = processor(image, question, words, boxes=boxes, return_tensors="pt")
40
- model_encoding = processor(images=image, text=question, return_tensors="pt")
41
- model_output = model.generate(**model_encoding)
42
- output_text = processor.batch_decode(model_output, skip_special_tokens=True)[0]
43
- st.write(output_text)
44
- elif testButton and selected_file == "None":
45
- st.write("Please upload and select a document (/an image).")
 
 
 
 
 
 
 
46
 
47
 
 
12
  st.title("CIC Demo (by ITT)")
13
  st.write("Upload and Select a document (/an image) to test the model.")
14
 
15
+ #2 column layout
16
+ col1, col2 = st.columns(2)
17
+
18
+ with col1:
19
+ # File selection
20
+ uploaded_files = st.file_uploader("Upload document(s) [/image(s)]:", type=["docx", "pdf", "pptx", "jpg", "jpeg", "png"], accept_multiple_files=True)
21
+ selected_file = st.selectbox("Select a document (/an image):", uploaded_files, format_func=lambda file: file.name if file else "None")
22
+
23
+ # Display selected file
24
+ if selected_file is not None and selected_file != "None":
25
+ file_extension = selected_file.name.split(".")[-1]
26
+ if file_extension in ["jpg", "jpeg", "png"]:
27
+ image = Image.open(selected_file).convert("RGB")
28
+ st.image(selected_file, caption="Selected Image")
29
+ else:
30
+ st.write("Selected file: ", selected_file.name)
31
 
32
  # Model Testing
33
+ with col2:
34
+ ## Question (/Prompt)
35
+ # question = "Question answering. How many unsafe practice of Lifting Operation?"
36
+ default_question = "Is this a Lifting Operation scene?"
37
+ task_type = st.selectbox("Question Type:", ("Question Answering", "Classification"))
38
+ question_text = st.text_input("Prompt:", placeholder=default_question)
39
+ if question_text is not None:
40
+ question = task_type + ". " + question_text
41
+ else
42
+ question = task_type + ". " + default_question
43
+
44
+ ## Test button
45
+ testButton = st.button("Test Model")
46
+
47
+ ## Perform Model Testing when Image is uploaded and selected as well as Test button is pressed
48
+ if testButton and selected_file != "None":
49
+ st.write("Testing the model with the selected image...")
50
+ # encoding = processor(image, question, words, boxes=boxes, return_tensors="pt")
51
+ model_encoding = processor(images=image, text=question, return_tensors="pt")
52
+ model_output = model.generate(**model_encoding)
53
+ output_text = processor.batch_decode(model_output, skip_special_tokens=True)[0]
54
+ st.write(output_text)
55
+ elif testButton and selected_file == "None":
56
+ st.write("Please upload and select a document (/an image).")
57
 
58