pratikshahp commited on
Commit
572cf00
1 Parent(s): f4d65e2

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +6 -10
app.py CHANGED
@@ -12,21 +12,17 @@ def prettier(results):
12
  location = [round(value, 2) for value in item['box'].values()]
13
  print(f'Detected {label} with confidence {score} at location {location}')
14
 
 
15
 
16
  def input_image_setup(uploaded_file):
17
  if uploaded_file is not None:
18
- #read the file into byte
19
- bytes_data = uploaded_file.getvalue()
20
- image_parts=[
21
- {
22
- "mime_type": uploaded_file.type,
23
- "data": bytes_data
24
- }
25
- ]
26
- return image_parts
27
  else:
28
  raise FileNotFoundError("No file uploaded")
29
 
 
30
  #Streamlit App
31
  st.set_page_config(page_title="Image Detection")
32
  st.header("Object Detection Application")
@@ -46,7 +42,7 @@ if submit:
46
  image_data=input_image_setup(uploaded_file)
47
  st.subheader("The response is..")
48
  #process with model
49
- inputs = processor(images=image_data, return_tensors="pt")
50
  outputs = model(**inputs)
51
 
52
  # model predicts bounding boxes and corresponding COCO classes
 
12
  location = [round(value, 2) for value in item['box'].values()]
13
  print(f'Detected {label} with confidence {score} at location {location}')
14
 
15
+ # Function to process uploaded image and prepare input for model
16
 
17
  def input_image_setup(uploaded_file):
18
  if uploaded_file is not None:
19
+ bytes_data = uploaded_file.getvalue()
20
+ image = Image.open(io.BytesIO(bytes_data)) # Convert bytes data to PIL image
21
+ return image
 
 
 
 
 
 
22
  else:
23
  raise FileNotFoundError("No file uploaded")
24
 
25
+
26
  #Streamlit App
27
  st.set_page_config(page_title="Image Detection")
28
  st.header("Object Detection Application")
 
42
  image_data=input_image_setup(uploaded_file)
43
  st.subheader("The response is..")
44
  #process with model
45
+ inputs = processor(images=image, return_tensors="pt")
46
  outputs = model(**inputs)
47
 
48
  # model predicts bounding boxes and corresponding COCO classes