VishalD1234 commited on
Commit
4e9faf8
·
verified ·
1 Parent(s): 856965b

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +61 -36
app.py CHANGED
@@ -6,22 +6,58 @@ from decord import cpu, VideoReader, bridge
6
  from transformers import AutoModelForCausalLM, AutoTokenizer
7
  from transformers import BitsAndBytesConfig
8
 
9
-
10
  MODEL_PATH = "THUDM/cogvlm2-llama3-caption"
11
  DEVICE = 'cuda' if torch.cuda.is_available() else 'cpu'
12
  TORCH_TYPE = torch.bfloat16 if torch.cuda.is_available() and torch.cuda.get_device_capability()[0] >= 8 else torch.float16
13
 
14
 
15
- DELAY_REASONS = {
16
- "Step 1": ["Delay in Bead Insertion","Lack of raw material"],
17
- "Step 2": ["Inner Liner Adjustment by Technician","Person rebuilding defective Tire Sections"],
18
- "Step 3": ["Manual Adjustment in Ply1 apply","Technician repairing defective Tire Sections"],
19
- "Step 4": ["Delay in Bead set","Lack of raw material"],
20
- "Step 5": ["Delay in Turnup","Lack of raw material"],
21
- "Step 6": ["Person Repairing sidewall","Person rebuilding defective Tire Sections"],
22
- "Step 7": ["Delay in sidewall stitching","Lack of raw material"],
23
- "Step 8": ["No person available to load Carcass","No person available to collect tire"]
24
- }
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
25
 
26
  def load_video(video_data, strategy='chat'):
27
  """Loads and processes video data into a format suitable for model input."""
@@ -104,12 +140,11 @@ def predict(prompt, video_data, temperature, model, tokenizer):
104
 
105
  return response
106
 
107
- def get_analysis_prompt(step_number, possible_reasons):
108
  """Constructs the prompt for analyzing delay reasons based on the selected step."""
109
  return f"""You are an AI expert system specialized in analyzing manufacturing processes and identifying production delays in tire manufacturing. Your role is to accurately classify delay reasons based on visual evidence from production line footage.
110
  Task Context:
111
- You are analyzing video footage from Step {step_number} of a tire manufacturing process where a delay has been detected. Your task is to determine the most likely cause of the delay from the following possible reasons:
112
- {', '.join(possible_reasons)}
113
  Required Analysis:
114
  Carefully observe the video for visual cues indicating production interruption.
115
  If no person is visible in any of the frames, the reason probably might be due to his absence.
@@ -123,18 +158,15 @@ Please provide your analysis in the following format:
123
  4. Alternative Analysis: [Brief explanation of why other possible reasons are less likely]
124
  Important: Base your analysis solely on visual evidence from the video. Focus on concrete, observable details rather than assumptions. Clearly state if no person or specific activity is observed."""
125
 
126
-
127
- # Load model globally
128
  model, tokenizer = load_model()
129
 
130
- def inference(video, step_number):
131
- """Analyzes video to predict the most likely cause of delay in the selected manufacturing step."""
132
  try:
133
  if not video:
134
  return "Please upload a video first."
135
 
136
- possible_reasons = DELAY_REASONS[step_number]
137
- prompt = get_analysis_prompt(step_number, possible_reasons)
138
  temperature = 0.8
139
  response = predict(prompt, video, temperature, model, tokenizer)
140
 
@@ -143,38 +175,31 @@ def inference(video, step_number):
143
  return f"An error occurred during analysis: {str(e)}"
144
 
145
  def create_interface():
146
- """Creates the Gradio interface for the Manufacturing Delay Analysis System with examples."""
147
  with gr.Blocks() as demo:
148
  gr.Markdown("""
149
- # Manufacturing Delay Analysis System
150
  Upload a video of the manufacturing step and select the step number.
151
- The system will analyze the video and determine the most likely cause of delay.
152
  """)
153
 
154
  with gr.Row():
155
  with gr.Column():
156
  video = gr.Video(label="Upload Manufacturing Video", sources=["upload"])
157
  step_number = gr.Dropdown(
158
- choices=list(DELAY_REASONS.keys()),
159
  label="Manufacturing Step"
160
  )
161
- analyze_btn = gr.Button("Analyze Delay", variant="primary")
162
 
163
  with gr.Column():
164
  output = gr.Textbox(label="Analysis Result", lines=10)
165
 
166
- # Add examples
167
- examples = [
168
- ["7838_step2_2_eval.mp4", "Step 2"],
169
- ["7838_step6_2_eval.mp4", "Step 6"],
170
- ["7838_step8_1_eval.mp4", "Step 8"],
171
- ["7993_step6_3_eval.mp4", "Step 6"],
172
- ["7993_step8_3_eval.mp4", "Step 8"]
173
-
174
- ]
175
-
176
  gr.Examples(
177
- examples=examples,
 
 
 
178
  inputs=[video, step_number],
179
  cache_examples=False
180
  )
 
6
  from transformers import AutoModelForCausalLM, AutoTokenizer
7
  from transformers import BitsAndBytesConfig
8
 
 
9
  MODEL_PATH = "THUDM/cogvlm2-llama3-caption"
10
  DEVICE = 'cuda' if torch.cuda.is_available() else 'cpu'
11
  TORCH_TYPE = torch.bfloat16 if torch.cuda.is_available() and torch.cuda.get_device_capability()[0] >= 8 else torch.float16
12
 
13
 
14
+ def get_step_info(step_name):
15
+ """Returns detailed information about a manufacturing step."""
16
+ step_details = {
17
+ "Step 1": {
18
+ "Name": "Bead Insertion",
19
+ "Standard Time": "4 seconds",
20
+ "Analysis": "Observe the bead placement process. If the insertion exceeds 4 seconds, identify potential issues such as missing beads, technician errors, or machinery malfunction."
21
+ },
22
+ "Step 2": {
23
+ "Name": "Inner Liner Apply",
24
+ "Standard Time": "4 seconds",
25
+ "Analysis": "Check for manual intervention during the inner layer application. If adjustment is required, it may indicate improper alignment or issues with the layer material."
26
+ },
27
+ "Step 3": {
28
+ "Name": "Ply1 Apply",
29
+ "Standard Time": "4 seconds",
30
+ "Analysis": "Determine if the technician is manually adjusting the first ply. Manual intervention might suggest improper ply placement or machine misalignment."
31
+ },
32
+ "Step 4": {
33
+ "Name": "Bead Set",
34
+ "Standard Time": "8 seconds",
35
+ "Analysis": "Observe the bead setting process. Delays may result from bead misalignment, machine pauses, or lack of technician involvement."
36
+ },
37
+ "Step 5": {
38
+ "Name": "Turnup",
39
+ "Standard Time": "4 seconds",
40
+ "Analysis": "Examine the turnup step for any technician involvement or pauses in machine operation. Reasons for delays might include material misalignment or equipment issues."
41
+ },
42
+ "Step 6": {
43
+ "Name": "Sidewall Apply",
44
+ "Standard Time": "14 seconds",
45
+ "Analysis": "If a technician is repairing the sidewall, this may indicate material damage or improper initial application. Look for signs of excessive manual handling."
46
+ },
47
+ "Step 7": {
48
+ "Name": "Sidewall Stitching",
49
+ "Standard Time": "5 seconds",
50
+ "Analysis": "Observe the stitching process. Delays could occur due to machine speed inconsistencies or technician intervention for correction."
51
+ },
52
+ "Step 8": {
53
+ "Name": "Carcass Unload",
54
+ "Standard Time": "7 seconds",
55
+ "Analysis": "Ensure a technician is present for the carcass unload. If absent, note their return time and identify potential reasons for their absence."
56
+ }
57
+ }
58
+
59
+ return step_details.get(step_name, {"Error": "Invalid step name. Please provide a valid step number."})
60
+
61
 
62
  def load_video(video_data, strategy='chat'):
63
  """Loads and processes video data into a format suitable for model input."""
 
140
 
141
  return response
142
 
143
+ def get_analysis_prompt(step_name):
144
  """Constructs the prompt for analyzing delay reasons based on the selected step."""
145
  return f"""You are an AI expert system specialized in analyzing manufacturing processes and identifying production delays in tire manufacturing. Your role is to accurately classify delay reasons based on visual evidence from production line footage.
146
  Task Context:
147
+ You are analyzing video footage from Step {step_name} of a tire manufacturing process where a delay has been detected.
 
148
  Required Analysis:
149
  Carefully observe the video for visual cues indicating production interruption.
150
  If no person is visible in any of the frames, the reason probably might be due to his absence.
 
158
  4. Alternative Analysis: [Brief explanation of why other possible reasons are less likely]
159
  Important: Base your analysis solely on visual evidence from the video. Focus on concrete, observable details rather than assumptions. Clearly state if no person or specific activity is observed."""
160
 
 
 
161
  model, tokenizer = load_model()
162
 
163
+ def inference(video, step_name):
164
+ """Analyzes video to predict possible issues based on the manufacturing step."""
165
  try:
166
  if not video:
167
  return "Please upload a video first."
168
 
169
+ prompt = get_analysis_prompt(step_number)
 
170
  temperature = 0.8
171
  response = predict(prompt, video, temperature, model, tokenizer)
172
 
 
175
  return f"An error occurred during analysis: {str(e)}"
176
 
177
  def create_interface():
178
+ """Creates the Gradio interface for the Manufacturing Analysis System."""
179
  with gr.Blocks() as demo:
180
  gr.Markdown("""
181
+ # Manufacturing Analysis System
182
  Upload a video of the manufacturing step and select the step number.
183
+ The system will analyze the video and provide observations.
184
  """)
185
 
186
  with gr.Row():
187
  with gr.Column():
188
  video = gr.Video(label="Upload Manufacturing Video", sources=["upload"])
189
  step_number = gr.Dropdown(
190
+ choices=[f"Step {i}" for i in range(1, 9)],
191
  label="Manufacturing Step"
192
  )
193
+ analyze_btn = gr.Button("Analyze", variant="primary")
194
 
195
  with gr.Column():
196
  output = gr.Textbox(label="Analysis Result", lines=10)
197
 
 
 
 
 
 
 
 
 
 
 
198
  gr.Examples(
199
+ examples=[
200
+ ["7838_step2_2_eval.mp4", "Step 2"],
201
+ ["7838_step6_2_eval.mp4", "Step 6"]
202
+ ],
203
  inputs=[video, step_number],
204
  cache_examples=False
205
  )