Spaces:
Sleeping
Sleeping
Update app.py
Browse files
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 |
-
#
|
| 16 |
-
|
| 17 |
-
|
| 18 |
-
|
| 19 |
-
#
|
| 20 |
-
|
| 21 |
-
|
| 22 |
-
|
| 23 |
-
|
| 24 |
-
|
| 25 |
-
|
| 26 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
| 27 |
|
| 28 |
# Model Testing
|
| 29 |
-
|
| 30 |
-
|
| 31 |
-
|
| 32 |
-
|
| 33 |
-
|
| 34 |
-
|
| 35 |
-
|
| 36 |
-
|
| 37 |
-
|
| 38 |
-
|
| 39 |
-
|
| 40 |
-
|
| 41 |
-
|
| 42 |
-
|
| 43 |
-
|
| 44 |
-
|
| 45 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 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 |
|