FrAnKu34t23 commited on
Commit
e9a167b
·
verified ·
1 Parent(s): 899b2a9

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +7 -5
app.py CHANGED
@@ -166,18 +166,20 @@ def analyze_with_cpu_model(raw_outputs):
166
 
167
  # === MAIN GENERATION FUNCTION ===
168
  def generate_prediction_ensemble(scenario_text, max_len, temperature):
169
- # Hardcoded testing mode
 
 
 
 
170
  raw_outputs = [
171
- '''Model 1:
172
- Based on the situation, predict potential hazards and injuries. During routine maintenance, a hydraulic press malfunctioned due to worn seals. The operator's hand was caught when the press unexpectedly activated.
173
- {"Cause of Accident": "Shock caused by Misjudgment, Hazardous Situation", "Degree of Injury": "High", "Hazards": ["Caught in or between caused by Pinch Point Action", "ELEVATED WORK PLATFORM", "POWERED INDUSTRIAL VEHICLE"]}'''
174
  ]
175
 
176
  cause, injury = analyze_with_cpu_model(raw_outputs)
177
  raw_output_text = "\n\n".join([f"Model {i+1}:\n{resp}" for i, resp in enumerate(raw_outputs)])
178
  return cause, injury, raw_output_text
179
 
180
-
181
  # === FULL GRADIO INTERFACE ===
182
  def create_interface():
183
  with gr.Blocks(title="Multi-Model Safety Risk Predictor") as interface:
 
166
 
167
  # === MAIN GENERATION FUNCTION ===
168
  def generate_prediction_ensemble(scenario_text, max_len, temperature):
169
+ if not scenario_text.strip():
170
+ return "Please enter a scenario", "", ""
171
+
172
+ prompt = format_input(scenario_text)
173
+
174
  raw_outputs = [
175
+ generate_single_model_output(model, tokenizer, prompt, max_length=max_len, temperature=temperature)
176
+ for model, tokenizer in zip(models, tokenizers)
 
177
  ]
178
 
179
  cause, injury = analyze_with_cpu_model(raw_outputs)
180
  raw_output_text = "\n\n".join([f"Model {i+1}:\n{resp}" for i, resp in enumerate(raw_outputs)])
181
  return cause, injury, raw_output_text
182
 
 
183
  # === FULL GRADIO INTERFACE ===
184
  def create_interface():
185
  with gr.Blocks(title="Multi-Model Safety Risk Predictor") as interface: