Spaces:
Sleeping
Sleeping
arjunanand13
commited on
Update app.py
Browse files
app.py
CHANGED
@@ -5,7 +5,6 @@ import torch
|
|
5 |
from decord import cpu, VideoReader, bridge
|
6 |
from transformers import AutoModelForCausalLM, AutoTokenizer
|
7 |
from transformers import BitsAndBytesConfig
|
8 |
-
import json
|
9 |
|
10 |
# Model Configuration
|
11 |
MODEL_PATH = "THUDM/cogvlm2-llama3-caption"
|
@@ -100,20 +99,26 @@ def predict(prompt, video_data, temperature, model, tokenizer):
|
|
100 |
return response
|
101 |
|
102 |
def get_analysis_prompt(step_number, possible_reasons):
|
103 |
-
return f"""
|
104 |
-
|
105 |
-
|
|
|
106 |
{', '.join(possible_reasons)}
|
107 |
|
108 |
-
|
109 |
-
|
110 |
-
|
111 |
-
|
112 |
-
3. Brief explanation of why other reasons are less likely
|
113 |
|
114 |
-
|
|
|
|
|
|
|
|
|
115 |
|
116 |
-
|
|
|
|
|
117 |
if not video:
|
118 |
return "Please upload a video first."
|
119 |
|
@@ -136,13 +141,15 @@ def inference(video, step_number, selected_reason):
|
|
136 |
except Exception as e:
|
137 |
return f"An error occurred: {str(e)}"
|
138 |
|
139 |
-
def update_reasons(step):
|
140 |
-
"""Update the dropdown choices based on the selected step"""
|
141 |
-
return gr.Dropdown(choices=DELAY_REASONS[step])
|
142 |
-
|
143 |
# Gradio Interface
|
144 |
def create_interface():
|
145 |
with gr.Blocks() as demo:
|
|
|
|
|
|
|
|
|
|
|
|
|
146 |
with gr.Row():
|
147 |
with gr.Column():
|
148 |
video = gr.Video(label="Upload Manufacturing Video", sources=["upload"])
|
@@ -151,27 +158,15 @@ def create_interface():
|
|
151 |
label="Manufacturing Step",
|
152 |
value="Step 1"
|
153 |
)
|
154 |
-
reason = gr.Dropdown(
|
155 |
-
choices=DELAY_REASONS["Step 1"],
|
156 |
-
label="Select Delay Reason",
|
157 |
-
value=DELAY_REASONS["Step 1"][0]
|
158 |
-
)
|
159 |
analyze_btn = gr.Button("Analyze Delay", variant="primary")
|
160 |
|
161 |
with gr.Column():
|
162 |
output = gr.Textbox(label="Analysis Result", lines=10)
|
163 |
|
164 |
-
# Update reasons when step changes
|
165 |
-
step_number.change(
|
166 |
-
fn=update_reasons,
|
167 |
-
inputs=[step_number],
|
168 |
-
outputs=[reason]
|
169 |
-
)
|
170 |
-
|
171 |
# Trigger analysis when button is clicked
|
172 |
analyze_btn.click(
|
173 |
fn=inference,
|
174 |
-
inputs=[video, step_number
|
175 |
outputs=[output]
|
176 |
)
|
177 |
|
|
|
5 |
from decord import cpu, VideoReader, bridge
|
6 |
from transformers import AutoModelForCausalLM, AutoTokenizer
|
7 |
from transformers import BitsAndBytesConfig
|
|
|
8 |
|
9 |
# Model Configuration
|
10 |
MODEL_PATH = "THUDM/cogvlm2-llama3-caption"
|
|
|
99 |
return response
|
100 |
|
101 |
def get_analysis_prompt(step_number, possible_reasons):
|
102 |
+
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.
|
103 |
+
|
104 |
+
Task Context:
|
105 |
+
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:
|
106 |
{', '.join(possible_reasons)}
|
107 |
|
108 |
+
Required Analysis:
|
109 |
+
1. Carefully observe the video for visual cues indicating production interruption
|
110 |
+
2. Compare observed evidence against each possible delay reason
|
111 |
+
3. Select the most likely reason based on visual evidence
|
|
|
112 |
|
113 |
+
Please provide your analysis in the following format:
|
114 |
+
1. Selected Reason: [State the most likely reason from the given options]
|
115 |
+
2. Visual Evidence: [Describe specific visual cues that support your selection]
|
116 |
+
3. Reasoning: [Explain why this reason best matches the observed evidence]
|
117 |
+
4. Alternative Analysis: [Brief explanation of why other possible reasons are less likely]
|
118 |
|
119 |
+
Important: Base your analysis solely on visual evidence from the video. Focus on concrete, observable details rather than assumptions."""
|
120 |
+
|
121 |
+
def inference(video, step_number):
|
122 |
if not video:
|
123 |
return "Please upload a video first."
|
124 |
|
|
|
141 |
except Exception as e:
|
142 |
return f"An error occurred: {str(e)}"
|
143 |
|
|
|
|
|
|
|
|
|
144 |
# Gradio Interface
|
145 |
def create_interface():
|
146 |
with gr.Blocks() as demo:
|
147 |
+
gr.Markdown("""
|
148 |
+
# Manufacturing Delay Analysis System
|
149 |
+
Upload a video of the manufacturing step and select the step number.
|
150 |
+
The system will analyze the video and determine the most likely cause of delay.
|
151 |
+
""")
|
152 |
+
|
153 |
with gr.Row():
|
154 |
with gr.Column():
|
155 |
video = gr.Video(label="Upload Manufacturing Video", sources=["upload"])
|
|
|
158 |
label="Manufacturing Step",
|
159 |
value="Step 1"
|
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 |
# Trigger analysis when button is clicked
|
167 |
analyze_btn.click(
|
168 |
fn=inference,
|
169 |
+
inputs=[video, step_number],
|
170 |
outputs=[output]
|
171 |
)
|
172 |
|