Mugundh commited on
Commit
d3cdd11
·
1 Parent(s): 533c554

Added default FIR copy feature

Browse files
Files changed (1) hide show
  1. app.py +28 -23
app.py CHANGED
@@ -31,28 +31,46 @@ def input_image_setup(uploaded_file):
31
  ]
32
  return image_parts
33
  else:
34
- raise FileNotFoundError("No file uploaded")
35
 
36
- ##initialize our streamlit app
37
 
38
- st.set_page_config(page_title="Gemini Image Demo")
39
 
40
  st.header("Criminal Case Filing System OCR")
41
 
42
- uploaded_file = st.file_uploader("Choose an image...", type=["pdf", "jpg", "jpeg", "png"])
 
 
 
43
  image = ""
44
- if uploaded_file is not None:
45
- image = Image.open(uploaded_file)
46
- st.image(image, caption="Uploaded Image.", use_column_width=True)
 
 
 
 
 
 
 
 
 
 
47
 
48
  submit = st.button("Extract data")
49
 
50
  ## If ask button is clicked
51
  if submit:
52
  input_prompt = """
53
- Extract the data of FIR No, Date and Time of FIR, Occurrence of offence, Type of information, Place of occurrence, Complaint / Victim's name
54
- """
55
- image_data = input_image_setup(uploaded_file)
 
 
 
 
 
56
  response = get_gemini_response(input_prompt, image_data, input_prompt)
57
  st.subheader("The Response is")
58
  print("Respons")
@@ -89,16 +107,3 @@ if submit:
89
  file_name="field_data.json",
90
  mime="application/json"
91
  )
92
-
93
- # Assuming your privacy ops portal URL is localhost:3000
94
- portal_url = "http://localhost:3000/new-case?"
95
- print(portal_url) # Print portal URL for debugging
96
-
97
- cleaned_field_data = {key.replace(' ', ''): value.replace(' ', '_') for key, value in field_data.items()}
98
-
99
- # Construct the URL with cleaned_field_data
100
- url_params = "&".join([f"{key}={value}" for key, value in cleaned_field_data.items()])
101
- full_url = portal_url + url_params
102
- st.write("Click on the below link to open the PrivacyOps Portal with the extracted data:")
103
- st.write(full_url)
104
-
 
31
  ]
32
  return image_parts
33
  else:
34
+ return None # Return None if no file uploaded
35
 
36
+ # initialize our streamlit app
37
 
38
+ st.set_page_config(page_title="Crime Lens API")
39
 
40
  st.header("Criminal Case Filing System OCR")
41
 
42
+ # Add option to use default FIR copy
43
+ use_default_copy = st.checkbox("Use Default FIR Copy")
44
+
45
+ uploaded_file = None
46
  image = ""
47
+ if not use_default_copy:
48
+ uploaded_file = st.file_uploader("Choose an image...", type=["pdf", "jpg", "jpeg", "png"])
49
+
50
+ if use_default_copy or uploaded_file is not None:
51
+ if use_default_copy:
52
+
53
+ image_path = "fir-copy.jpg"
54
+ image = Image.open(image_path)
55
+ st.image(image, caption="Using Default FIR Copy", use_column_width=True)
56
+ else:
57
+ # User uploaded their own file
58
+ image = Image.open(uploaded_file)
59
+ st.image(image, caption="Uploaded Image.", use_column_width=True)
60
 
61
  submit = st.button("Extract data")
62
 
63
  ## If ask button is clicked
64
  if submit:
65
  input_prompt = """
66
+ Extract the data of FIR No, Date and Time of FIR, Occurrence of offence, Type of information, Place of occurrence, Complaint / Victim's name
67
+ """
68
+ image_data = input_image_setup(uploaded_file) # Use uploaded file if available, otherwise None
69
+
70
+ if image_data is None: # Check if user selected default copy
71
+ # Use default image path if no file uploaded
72
+ image_data = [{'mime_type': 'image/jpeg', 'data': open('fir-copy.jpg', 'rb').read()}]
73
+
74
  response = get_gemini_response(input_prompt, image_data, input_prompt)
75
  st.subheader("The Response is")
76
  print("Respons")
 
107
  file_name="field_data.json",
108
  mime="application/json"
109
  )