shukdevdatta123 commited on
Commit
9d8fac7
·
verified ·
1 Parent(s): f236a43

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +53 -48
app.py CHANGED
@@ -78,10 +78,9 @@ def prompt(inputs):
78
  - Any visible brand logos or distinguishing marks (e.g., Tesla logo)
79
  - Details of any visible damage (e.g., scratches, dents)
80
  - Vehicle’s region or country (based on the license plate or other clues)
81
- If some details are unclear or not visible, return `None` for those fields. Do not guess or provide inaccurate information."""
82
- ),
83
  HumanMessage(
84
- content=[
85
  {"type": "text", "text": "Analyze the vehicle in the image and extract as many details as possible, including type, license plate, make, model, year, condition, damage, etc."},
86
  {"type": "text", "text": instructions}, # include any other format instructions here
87
  {"type": "image_url", "image_url": {"url": f"data:image/jpeg;base64,{inputs['image']}", "detail": "low"}}
@@ -101,48 +100,54 @@ def MLLM_response(inputs):
101
  pipeline = image_encoding | prompt | MLLM_response | parser
102
 
103
  # Streamlit Interface for uploading images and showing results
104
- st.header("Upload a Vehicle Image for Information Extraction")
105
-
106
- uploaded_image = st.file_uploader("Choose a JPEG image", type="jpeg")
107
-
108
- if uploaded_image is not None:
109
- # Display the uploaded image
110
- image = PILImage.open(uploaded_image)
111
- st.image(image, caption="Uploaded Image", use_column_width=True)
112
-
113
- # Convert the uploaded image to base64
114
- image_path = "/tmp/uploaded_image.jpeg"
115
- with open(image_path, "wb") as f:
116
- f.write(uploaded_image.getbuffer())
117
-
118
- # Process the image through the pipeline
119
- output = pipeline.invoke({"image_path": image_path})
120
-
121
- # Show the results in a user-friendly format
122
- st.subheader("Extracted Vehicle Information")
123
- st.json(output)
124
-
125
- # Optionally, display more vehicle images from the folder
126
- img_dir = "/content/images"
127
- image_paths = glob.glob(os.path.join(img_dir, "*.jpeg"))
128
- display_image_grid(image_paths)
129
-
130
- # You can also allow users to upload and process a batch of images
131
- st.sidebar.header("Batch Image Upload")
132
-
133
- batch_images = st.sidebar.file_uploader("Upload Images", type="jpeg", accept_multiple_files=True)
134
-
135
- if batch_images:
136
- batch_input = [{"image_path": f"/tmp/{file.name}"} for file in batch_images]
137
- for file in batch_images:
138
- with open(f"/tmp/{file.name}", "wb") as f:
139
- f.write(file.getbuffer())
140
-
141
- # Process the batch and display the results in a DataFrame
142
- batch_output = pipeline.batch(batch_input)
143
- df = pd.DataFrame(batch_output)
144
- st.dataframe(df)
145
-
146
- # Show images in a grid
147
- image_paths = [f"/tmp/{file.name}" for file in batch_images]
148
- display_image_grid(image_paths)
 
 
 
 
 
 
 
78
  - Any visible brand logos or distinguishing marks (e.g., Tesla logo)
79
  - Details of any visible damage (e.g., scratches, dents)
80
  - Vehicle’s region or country (based on the license plate or other clues)
81
+ If some details are unclear or not visible, return `None` for those fields. Do not guess or provide inaccurate information."""),
 
82
  HumanMessage(
83
+ content=[
84
  {"type": "text", "text": "Analyze the vehicle in the image and extract as many details as possible, including type, license plate, make, model, year, condition, damage, etc."},
85
  {"type": "text", "text": instructions}, # include any other format instructions here
86
  {"type": "image_url", "image_url": {"url": f"data:image/jpeg;base64,{inputs['image']}", "detail": "low"}}
 
100
  pipeline = image_encoding | prompt | MLLM_response | parser
101
 
102
  # Streamlit Interface for uploading images and showing results
103
+ st.header("Upload Vehicle Images for Information Extraction")
104
+
105
+ # Option to select either single or batch image upload
106
+ upload_option = st.radio("Select Upload Type", ["Single Image Upload", "Batch Images Upload"])
107
+
108
+ # Single Image Upload
109
+ if upload_option == "Single Image Upload":
110
+ st.subheader("Upload a Single Vehicle Image")
111
+ uploaded_image = st.file_uploader("Choose a JPEG image", type="jpeg")
112
+
113
+ if uploaded_image is not None:
114
+ # Display the uploaded image
115
+ image = PILImage.open(uploaded_image)
116
+ st.image(image, caption="Uploaded Image", use_column_width=True)
117
+
118
+ # Convert the uploaded image to base64
119
+ image_path = "/tmp/uploaded_image.jpeg"
120
+ with open(image_path, "wb") as f:
121
+ f.write(uploaded_image.getbuffer())
122
+
123
+ # Process the image through the pipeline
124
+ output = pipeline.invoke({"image_path": image_path})
125
+
126
+ # Show the results in a user-friendly format
127
+ st.subheader("Extracted Vehicle Information")
128
+ st.json(output)
129
+
130
+ # Optionally, display more vehicle images from the folder
131
+ img_dir = "/content/images"
132
+ image_paths = glob.glob(os.path.join(img_dir, "*.jpeg"))
133
+ display_image_grid(image_paths)
134
+
135
+ # Batch Images Upload
136
+ elif upload_option == "Batch Images Upload":
137
+ st.sidebar.header("Batch Image Upload")
138
+ batch_images = st.sidebar.file_uploader("Upload Images", type="jpeg", accept_multiple_files=True)
139
+
140
+ if batch_images:
141
+ batch_input = [{"image_path": f"/tmp/{file.name}"} for file in batch_images]
142
+ for file in batch_images:
143
+ with open(f"/tmp/{file.name}", "wb") as f:
144
+ f.write(file.getbuffer())
145
+
146
+ # Process the batch and display the results in a DataFrame
147
+ batch_output = pipeline.batch(batch_input)
148
+ df = pd.DataFrame(batch_output)
149
+ st.dataframe(df)
150
+
151
+ # Show images in a grid
152
+ image_paths = [f"/tmp/{file.name}" for file in batch_images]
153
+ display_image_grid(image_paths)