Spaces:
Running
Running
| import time | |
| from backend.gaming.game_context_prompts import DQI_SCORING_PROMPTS, PROBABILITY_SIM_PROMPTS | |
| from backend.voice.tts import TTSPipeline | |
| from backend.ws.agent_ws import ws_manager | |
| tts = TTSPipeline() | |
| async def score_decision_quality(frame_sequence: list, audio_chunk: bytes, game_context: str) -> dict: | |
| if game_context not in DQI_SCORING_PROMPTS: | |
| return {"dqi_score": 50, "decision_type": "unknown", "reasoning": "Unsupported game", "timestamp": time.time()} | |
| # In full production, we'd build a prompt and pass images/bytes to gemini_flash_vision_analyze: | |
| # prompt = DQI_SCORING_PROMPTS[game_context]["dqi_prompt"] | |
| # analysis = await gemini_flash_vision_analyze(frames=frame_sequence, audio_context=audio_chunk, prompt=prompt) | |
| analysis = { | |
| "score": 75, | |
| "decision_type": "engage", | |
| "reasoning": "Decent crosshair placement, but rotated a bit late." | |
| } | |
| return { | |
| "dqi_score": analysis["score"], | |
| "decision_type": analysis["decision_type"], | |
| "reasoning": analysis["reasoning"], | |
| "timestamp": time.time() | |
| } | |
| async def simulate_engagement_probability(game_state: dict, game_context: str) -> dict: | |
| if game_context not in PROBABILITY_SIM_PROMPTS: | |
| return {"win_probability_pct": 50, "key_factors": []} | |
| # In full production, build and pass the sim prompt: | |
| # sim_prompt = PROBABILITY_SIM_PROMPTS[game_context].format(**game_state) | |
| # result = await gemini_flash_analyze(sim_prompt) | |
| result = { | |
| "probability": 65, | |
| "factors": ["health deficit", "good utility available"] | |
| } | |
| return { | |
| "win_probability_pct": result["probability"], | |
| "key_factors": result["factors"] | |
| } | |
| async def deliver_coaching_callout(text: str, active_persona: str): | |
| audio_bytes = await tts.synthesize(text, personality=active_persona, context="coaching") | |
| # Push to WS for playback | |
| await ws_manager.broadcast({ | |
| "type": "audio", | |
| "payload": { | |
| "audio_data": audio_bytes.hex(), | |
| "mime_type": "audio/wav", | |
| "persona": active_persona | |
| } | |
| }) | |