Spaces:
Sleeping
Sleeping
Add OpenAI compatibility fallback
Browse files24 unmodified lines25262728293024 unmodified lines3. Set `MINDVIS_REPO=/app/mindVisualizer`.4. Set `CORS_ORIGINS=https://pixedar.github.io,http://localhost:3000`.5. In the GitHub Pages build, set `NEXT_PUBLIC_MINDVIS_API_URL=https://your-backend-url`.Current Space:24 unmodified lines2526272829303124 unmodified lines3. Set `MINDVIS_REPO=/app/mindVisualizer`.4. Set `CORS_ORIGINS=https://pixedar.github.io,http://localhost:3000`.5. In the GitHub Pages build, set `NEXT_PUBLIC_MINDVIS_API_URL=https://your-backend-url`.6. Optional: set `OPENAI_API_KEY` as a Space secret and `OPENAI_MODEL` as a Space variable.Current Space:
128 unmodified lines12913013113213313413513613728 unmodified lines166167168128 unmodified linestext = ""if req.callLlm and os.environ.get("OPENAI_API_KEY"):from src.roi_flow import ROIFlowLLMtext = ROIFlowLLM(debug=False).interpret_roi_flow(context)if not text:analysis = analyzer.analyze_flow_pattern(delta)28 unmodified linesdef normalized(points: np.ndarray, amin: np.ndarray, span: np.ndarray) -> np.ndarray:return (points.astype(np.float32) - amin[None, :]) / span[None, :]128 unmodified lines12913013113213313413528 unmodified lines164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209128 unmodified linestext = ""if req.callLlm and os.environ.get("OPENAI_API_KEY"):text = call_openai_interpreter(context)if not text:analysis = analyzer.analyze_flow_pattern(delta)28 unmodified linesdef normalized(points: np.ndarray, amin: np.ndarray, span: np.ndarray) -> np.ndarray:return (points.astype(np.float32) - amin[None, :]) / span[None, :]def call_openai_interpreter(context: str) -> str:from openai import OpenAImodel = os.environ.get("OPENAI_MODEL", "gpt-4o-mini")instructions = ("You are a neuroscientist interpreting brain state dynamics from a ""manifold flow simulation. The user traced a path through a learned ""neural manifold. You are given how each ROI's contribution changed ""along this path.\n\n""The delta values do not mean simple activation. They measure how each ""ROI's contribution to the overall brain state shifted. Positive means ""the region became a stronger contributor; negative means it became a ""weaker contributor.\n\n""Do not list every ROI. Synthesize the spatial pattern, directionality, ""and network shift into one coherent interpretation. Keep the response ""to 2 concise paragraphs.")try:client = OpenAI(timeout=60.0)if hasattr(client, "responses"):response = client.responses.create(model=model,instructions=instructions,input=context,max_output_tokens=900,)return (response.output_text or "").strip()response = client.chat.completions.create(model=model,messages=[{"role": "system", "content": instructions},{"role": "user", "content": context},],max_tokens=900,temperature=0.3,)return (response.choices[0].message.content or "").strip()except Exception as exc:return f"[GPT ERROR] {exc}"
README.md+1
app.py+44-3