kevinkyi commited on
Commit
37a74f1
·
verified ·
1 Parent(s): 7b2a8b8

Upload app.py with huggingface_hub

Browse files
Files changed (1) hide show
  1. app.py +6 -7
app.py CHANGED
@@ -27,10 +27,12 @@ def projectile_calc(v0_mps: float, theta_deg: float, y0_m: float, g: float, weig
27
  v0x = v0_mps * math.cos(theta_rad)
28
  v0y = v0_mps * math.sin(theta_rad)
29
 
 
30
  disc = v0y**2 + 2.0 * g * y0_m
31
  t_flight = (v0y + math.sqrt(max(disc, 0.0))) / g
32
  t_flight = max(t_flight, 0.0)
33
 
 
34
  range_m = v0x * t_flight
35
  t_apex = max(v0y / g, 0.0)
36
  y_apex = y0_m + v0y * t_apex - 0.5 * g * t_apex**2
@@ -87,13 +89,10 @@ def llm_one_sentence(structured: Dict[str, Any]) -> str:
87
  "impact_speed_mps": round(o["impact_speed_mps"], 3),
88
  }
89
  }
90
- instruction = (
91
- "Produce EXACTLY one sentence of this form using only the JSON values:\n"
92
- ""If you threw a ball that weighed {weight_kg} kg at v0={v0_mps} m/s, "
93
- "θ={theta_deg}°, from y0={y0_m} m under g={g_mps2} m/s², "
94
- "it would stay in the air for {time_of_flight_s} s, reach {max_height_m} m, "
95
- "travel {range_m} m, and impact at {impact_speed_mps} m/s.""
96
- )
97
  user_prompt = f"JSON:\n{json.dumps(payload, indent=2)}\n\nFollow the instruction exactly."
98
  prompt = f"<|system|>\n{SYSTEM_PROMPT}\n<|user|>\n{instruction}\n\n{user_prompt}\n<|assistant|>"
99
  out = llm(prompt, max_new_tokens=120, do_sample=False, temperature=0.0, return_full_text=False)
 
27
  v0x = v0_mps * math.cos(theta_rad)
28
  v0y = v0_mps * math.sin(theta_rad)
29
 
30
+ # Time of flight (positive root)
31
  disc = v0y**2 + 2.0 * g * y0_m
32
  t_flight = (v0y + math.sqrt(max(disc, 0.0))) / g
33
  t_flight = max(t_flight, 0.0)
34
 
35
+ # Range, apex height, impact speed
36
  range_m = v0x * t_flight
37
  t_apex = max(v0y / g, 0.0)
38
  y_apex = y0_m + v0y * t_apex - 0.5 * g * t_apex**2
 
89
  "impact_speed_mps": round(o["impact_speed_mps"], 3),
90
  }
91
  }
92
+ instruction = dedent(""" Produce EXACTLY one sentence of this form using only the JSON values:
93
+ "If you threw a ball that weighed {weight_kg} kg at v0={v0_mps} m/s, θ={theta_deg}°, from y0={y0_m} m under g={g_mps2} m/s²,
94
+ it would stay in the air for {time_of_flight_s} s, reach {max_height_m} m, travel {range_m} m, and impact at {impact_speed_mps} m/s."
95
+ """)
 
 
 
96
  user_prompt = f"JSON:\n{json.dumps(payload, indent=2)}\n\nFollow the instruction exactly."
97
  prompt = f"<|system|>\n{SYSTEM_PROMPT}\n<|user|>\n{instruction}\n\n{user_prompt}\n<|assistant|>"
98
  out = llm(prompt, max_new_tokens=120, do_sample=False, temperature=0.0, return_full_text=False)