SivaMallikarjun commited on
Commit
258e3c1
·
verified ·
1 Parent(s): 39eaf50

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +30 -41
app.py CHANGED
@@ -1,12 +1,9 @@
1
  import gradio as gr
2
  import cv2
3
- # import pytesseract
4
  import numpy as np
5
  import datetime
6
  import random
7
  from fpdf import FPDF
8
- import os
9
- import threading
10
  import time
11
 
12
  # Quantum Simulation Logic
@@ -21,19 +18,15 @@ class QuantumSim:
21
  def evaluate_transaction(self):
22
  return random.choice(list(self.states.items()))
23
 
24
- # Computer Vision & OCR Agent
25
  class CVProcessor:
26
  def extract_vehicle_number(self, image_np):
27
- if image_np is None:
28
- return "No image provided"
29
- gray = cv2.cvtColor(image_np, cv2.COLOR_BGR2GRAY)
30
- text = pytesseract.image_to_string(gray)
31
- return text.strip() or "Not detected"
32
 
33
  def detect_damage_severity(self, image_np):
34
  if image_np is None:
35
  return "No image provided"
36
- # Simulate damage level detection
37
  damage_score = np.random.randint(1, 10)
38
  if damage_score > 7:
39
  return "Severe"
@@ -42,11 +35,6 @@ class CVProcessor:
42
  else:
43
  return "Minor"
44
 
45
- class CVProcessor:
46
- def extract_vehicle_number(self, image):
47
- # Bypass OCR for now
48
- return "DL3CAB1234" # Dummy number
49
-
50
  def detect_person_injury(self, image_np):
51
  if image_np is None:
52
  return "No image provided"
@@ -62,11 +50,11 @@ class InsuranceAgent:
62
 
63
  def simulate_live_camera_feed(self):
64
  print("[Agent] Watching live feed... analyzing frame by frame.")
65
- for i in range(3): # Simulate 3 frames for brevity
66
  dummy_frame = np.ones((480, 640, 3), dtype=np.uint8) * np.random.randint(0, 255)
67
  report = self.process_frame(dummy_frame)
68
  self.reports.append(report)
69
- time.sleep(2) # Simulate a delay between frames
70
 
71
  def process_frame(self, frame):
72
  vehicle_number = self.cv.extract_vehicle_number(frame)
@@ -89,6 +77,7 @@ class InsuranceAgent:
89
 
90
  self.generate_pdf_report(response)
91
  self.notify_services(response)
 
92
  return response
93
 
94
  def generate_pdf_report(self, data):
@@ -108,27 +97,27 @@ class InsuranceAgent:
108
  if data["IRDA Notified"] == "Yes":
109
  print("[IRDA] Fraud suspected. Penalty log initiated.")
110
 
111
- # Gradio UI for No-Ops Simulation
112
- if __name__ == "__main__":
113
- agent = InsuranceAgent()
114
-
115
- def start_agent_simulation():
116
- agent.reports = [] # Clear previous reports
117
- agent.simulate_live_camera_feed()
118
- all_reports_text = ""
119
- for i, report in enumerate(agent.reports):
120
- all_reports_text += f"--- Report {i+1} ---\n"
121
- for key, value in report.items():
122
- all_reports_text += f"{key}: {value}\n"
123
- all_reports_text += "\n"
124
- return all_reports_text
125
-
126
- with gr.Blocks() as iface:
127
- gr.Markdown("# No-Ops AI Agent for Road Accident Management")
128
- with gr.Column():
129
- start_button = gr.Button("Start Agent Simulation")
130
- report_output = gr.Textbox(label="Agent Activity and Reports")
131
-
132
- start_button.click(start_agent_simulation, outputs=report_output)
133
-
134
- iface.launch()
 
1
  import gradio as gr
2
  import cv2
 
3
  import numpy as np
4
  import datetime
5
  import random
6
  from fpdf import FPDF
 
 
7
  import time
8
 
9
  # Quantum Simulation Logic
 
18
  def evaluate_transaction(self):
19
  return random.choice(list(self.states.items()))
20
 
21
+ # Computer Vision & Damage/Injury Detection
22
  class CVProcessor:
23
  def extract_vehicle_number(self, image_np):
24
+ # Bypass OCR
25
+ return "DL3CAB1234" # Dummy number
 
 
 
26
 
27
  def detect_damage_severity(self, image_np):
28
  if image_np is None:
29
  return "No image provided"
 
30
  damage_score = np.random.randint(1, 10)
31
  if damage_score > 7:
32
  return "Severe"
 
35
  else:
36
  return "Minor"
37
 
 
 
 
 
 
38
  def detect_person_injury(self, image_np):
39
  if image_np is None:
40
  return "No image provided"
 
50
 
51
  def simulate_live_camera_feed(self):
52
  print("[Agent] Watching live feed... analyzing frame by frame.")
53
+ for i in range(3): # Simulate 3 frames
54
  dummy_frame = np.ones((480, 640, 3), dtype=np.uint8) * np.random.randint(0, 255)
55
  report = self.process_frame(dummy_frame)
56
  self.reports.append(report)
57
+ time.sleep(2)
58
 
59
  def process_frame(self, frame):
60
  vehicle_number = self.cv.extract_vehicle_number(frame)
 
77
 
78
  self.generate_pdf_report(response)
79
  self.notify_services(response)
80
+ print("[Debug] Frame Processed:", response)
81
  return response
82
 
83
  def generate_pdf_report(self, data):
 
97
  if data["IRDA Notified"] == "Yes":
98
  print("[IRDA] Fraud suspected. Penalty log initiated.")
99
 
100
+ # Gradio UI
101
+ agent = InsuranceAgent()
102
+
103
+ def start_agent_simulation():
104
+ print("[Debug] Starting simulation...")
105
+ agent.reports = []
106
+ agent.simulate_live_camera_feed()
107
+ all_reports_text = ""
108
+ for i, report in enumerate(agent.reports):
109
+ all_reports_text += f"--- Report {i+1} ---\n"
110
+ for key, value in report.items():
111
+ all_reports_text += f"{key}: {value}\n"
112
+ all_reports_text += "\n"
113
+ return all_reports_text
114
+
115
+ with gr.Blocks() as iface:
116
+ gr.Markdown("# No-Ops AI Agent for Road Accident Management")
117
+ with gr.Column():
118
+ start_button = gr.Button("Start Agent Simulation")
119
+ report_output = gr.Textbox(label="Agent Activity and Reports", lines=20)
120
+
121
+ start_button.click(start_agent_simulation, outputs=report_output)
122
+
123
+ iface.launch()