Spaces:
Sleeping
Sleeping
VishalD1234
commited on
Update app.py
Browse files
app.py
CHANGED
@@ -6,76 +6,23 @@ from decord import cpu, VideoReader, bridge
|
|
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 |
DELAY_REASONS = {
|
14 |
-
"Step 1": ["Delay in Bead Insertion",
|
15 |
-
"Step 2": ["Inner Liner Adjustment by Technician",
|
16 |
-
"Step 3": ["Manual Adjustment in Ply1 apply",
|
17 |
-
"Step 4": ["Delay in Bead set",
|
18 |
-
"Step 5": ["Delay in Turnup",
|
19 |
-
"Step 6": ["Person Repairing sidewall",
|
20 |
-
"Step 7": ["Delay in sidewall stitching",
|
21 |
-
"Step 8": ["No person available to load Carcass",
|
22 |
}
|
23 |
|
24 |
-
def analyze_video_step(step_name, observed_time, issues=""):
|
25 |
-
"""
|
26 |
-
Analyzes a video step based on its name and observed time.
|
27 |
-
|
28 |
-
Parameters:
|
29 |
-
step_name (str): The name of the step.
|
30 |
-
observed_time (int): Observed time taken for the step (in seconds).
|
31 |
-
issues (str): Any specific issues noted during the analysis.
|
32 |
-
|
33 |
-
Returns:
|
34 |
-
str: Analysis result for the provided step.
|
35 |
-
"""
|
36 |
-
match step_name:
|
37 |
-
case "Bead Insertion":
|
38 |
-
standard_time = 4
|
39 |
-
analysis = "Missing beads, technician errors, or machinery malfunction.Technician is unavailable at the time of bead insertion."
|
40 |
-
case "Inner Liner Apply":
|
41 |
-
standard_time = 4
|
42 |
-
analysis = "Manual intervention or alignment issues.If technician is manually repairing inner liner."
|
43 |
-
case "Ply1 Apply":
|
44 |
-
standard_time = 4
|
45 |
-
analysis = "Manual adjustment suggesting improper placement or misalignment."
|
46 |
-
case "Bead Set":
|
47 |
-
standard_time = 8
|
48 |
-
analysis = "Bead misalignment, machine pauses, or technician involvement."
|
49 |
-
case "Turnup":
|
50 |
-
standard_time = 4
|
51 |
-
analysis = "Material misalignment or equipment issues."
|
52 |
-
case "Sidewall Apply":
|
53 |
-
standard_time = 14
|
54 |
-
analysis = "Material damage or improper application.Technician repairing sidewall."
|
55 |
-
case "Sidewall Stitching":
|
56 |
-
standard_time = 5
|
57 |
-
analysis = "Machine speed inconsistencies or manual correction."
|
58 |
-
case "Carcass Unload":
|
59 |
-
standard_time = 7
|
60 |
-
analysis = "Absence of technician or delayed involvement.Technician not available to collect tire or load carcass"
|
61 |
-
case _:
|
62 |
-
return "Invalid step name. Please provide a valid step name."
|
63 |
-
|
64 |
-
if observed_time > standard_time:
|
65 |
-
return (
|
66 |
-
f"Step: {step_name}\n"
|
67 |
-
f"Standard Time: {standard_time} seconds\n"
|
68 |
-
f"Observed Time: {observed_time} seconds\n"
|
69 |
-
f"Analysis: Delay detected. Potential issues: {analysis} {issues}"
|
70 |
-
)
|
71 |
-
else:
|
72 |
-
return (
|
73 |
-
f"Step: {step_name}\n"
|
74 |
-
f"Standard Time: {standard_time} seconds\n"
|
75 |
-
f"Observed Time: {observed_time} seconds\n"
|
76 |
-
"Analysis: Step completed within standard time."
|
77 |
-
)
|
78 |
-
|
79 |
def load_video(video_data, strategy='chat'):
|
80 |
"""Loads and processes video data into a format suitable for model input."""
|
81 |
bridge.set_bridge('torch')
|
@@ -176,10 +123,12 @@ Please provide your analysis in the following format:
|
|
176 |
4. Alternative Analysis: [Brief explanation of why other possible reasons are less likely]
|
177 |
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."""
|
178 |
|
|
|
|
|
179 |
model, tokenizer = load_model()
|
180 |
|
181 |
-
def inference(video, step_number
|
182 |
-
"""Analyzes video
|
183 |
try:
|
184 |
if not video:
|
185 |
return "Please upload a video first."
|
@@ -187,10 +136,9 @@ def inference(video, step_number, observed_time, issues=""):
|
|
187 |
possible_reasons = DELAY_REASONS[step_number]
|
188 |
prompt = get_analysis_prompt(step_number, possible_reasons)
|
189 |
temperature = 0.8
|
190 |
-
|
191 |
-
step_analysis = analyze_video_step(step_number, observed_time, issues)
|
192 |
|
193 |
-
return
|
194 |
except Exception as e:
|
195 |
return f"An error occurred during analysis: {str(e)}"
|
196 |
|
@@ -240,6 +188,5 @@ def create_interface():
|
|
240 |
return demo
|
241 |
|
242 |
if __name__ == "__main__":
|
243 |
-
model, tokenizer = load_model()
|
244 |
demo = create_interface()
|
245 |
demo.queue().launch(share=True)
|
|
|
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."""
|
28 |
bridge.set_bridge('torch')
|
|
|
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."
|
|
|
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 |
|
141 |
+
return response
|
142 |
except Exception as e:
|
143 |
return f"An error occurred during analysis: {str(e)}"
|
144 |
|
|
|
188 |
return demo
|
189 |
|
190 |
if __name__ == "__main__":
|
|
|
191 |
demo = create_interface()
|
192 |
demo.queue().launch(share=True)
|