Spaces:
Sleeping
Sleeping
faizr206 commited on
Commit ·
77d95dc
1
Parent(s): cb5e24d
gemini backup if openai unavailable
Browse filesFiles changed (3)
- .dockerignoreAdded+7
- .gitignoreAdded+2
- app/main.py+21-9
1234567__pycache__/*.pyc.env.git.gitignore.vscode/notes.txt12.envnotes.txt26 unmodified lines27282930313230313233343536373638394041185 unmodified lines227228229228229230231232233231234235236237238239240241242243244245246893 unmodified lines1140114111421131114311441145114632 unmodified lines1179118011811170118211831184118526 unmodified lines
# We keep the GEMINI_* env vars for compatibility.API_KEY = os.getenv("GEMINI_API_KEY", "")MODEL = os.getenv("GEMINI_MODEL", "gemini-2.0-pro")SMALL_MODEL = os.getenv("GEMINI_SMALL_MODEL")OPENAI_API_KEY = os.getenv("OPENAI_API_KEY") or API_KEYMODEL = os.getenv("GEMINI_MODEL", "gemini-2.5-pro")GEMINI_SMALL_MODEL = os.getenv("GEMINI_SMALL_MODEL")OPENAI_SMALL_MODEL = os.getenv("OPENAI_SMALL_MODEL") or "gpt-4o-mini"OPENAI_API_KEY = os.getenv("OPENAI_API_KEY")USE_OPENAI = os.getenv("USE_OPENAI", "").lower() == "true"PORT = int(os.getenv("PORT", "7860"))
gemini_client = genai.Client(api_key=API_KEY) if API_KEY else Nonegpt_client = OpenAI(api_key=OPENAI_API_KEY) if (OPENAI_API_KEY and OpenAI) else Nonegpt_client = OpenAI(api_key=OPENAI_API_KEY) if (OPENAI_API_KEY and OpenAI and USE_OPENAI) else None
# -------- FastAPI app --------app = FastAPI(title="Manim Render API (error + visual refine)")185 unmodified lines
def gemini_small_call(*, system: str, contents: str) -> str: """Lightweight wrapper for the storyboard assistant (smaller model).""" target_model = SMALL_MODEL or "gpt-4o-mini" """Lightweight wrapper for the storyboard assistant using a smaller model with Gemini fallback.""" storyboard_limiter.acquire() if gpt_client: target_model = OPENAI_SMALL_MODEL return _invoke_gpt_model(target_model, system, contents) return _invoke_gpt_model(target_model, system, contents) if not gemini_client: raise RuntimeError("Gemini client is not configured") fallback_model = GEMINI_SMALL_MODEL or MODEL resp = gemini_client.models.generate_content( model=fallback_model, config=types.GenerateContentConfig(system_instruction=system), contents=contents, ) return getattr(resp, "text", str(resp))
# ---------------- prompts ----------------SYSTEM_PROMPT = """You are a Manim CE (0.19.x) code generator/refiner.893 unmodified lines# ---------------- API ----------------@app.post("/storyboard/chat")def storyboard_chat(inp: StoryboardChatIn): if not gpt_client: if not (gpt_client or gemini_client): raise HTTPException(500, "Storyboard model is not configured") if not inp.message.strip() and not inp.plan: raise HTTPException(400, "Message or plan updates are required.")32 unmodified lines
@app.post("/storyboard/confirm")def storyboard_confirm(inp: StoryboardConfirmIn): if not gpt_client: if not (gpt_client or gemini_client): raise HTTPException(500, "Storyboard model is not configured")
session = _get_or_create_session(inp.session_id, inp.settings or {}).dockerignoreAdded+7
.gitignoreAdded+2
app/main.py+21-9