Spaces:
Sleeping
Sleeping
Download orchestrator/gemini.py from mgbam/MCP_Research: direct link, hf CLI and curl.
- Browser
- Download file 791 Bytes
-
https://huggingface.co/spaces/mgbam/MCP_Research/resolve/f648aaaf08e873fd5f2b02d91c1c1b61fea68946/orchestrator/gemini.py
- Command line
-
hf download hf://spaces/mgbam/MCP_Research@f648aaaf08e873fd5f2b02d91c1c1b61fea68946/orchestrator/gemini.py
-
curl -L -o gemini.py https://huggingface.co/spaces/mgbam/MCP_Research/resolve/f648aaaf08e873fd5f2b02d91c1c1b61fea68946/orchestrator/gemini.py
791 Bytes
| import os | |
| import streamlit as st | |
| try: | |
| import google.generativeai as genai | |
| except ImportError: | |
| genai = None | |
| def get_gemini_api_key(): | |
| # Try Streamlit Secrets, then env var | |
| if hasattr(st.secrets, "GEMINI_API_KEY"): | |
| return st.secrets["GEMINI_API_KEY"] | |
| return os.getenv("GEMINI_API_KEY") | |
| def gemini_generate(prompt, model="gemini-1.5-flash"): | |
| api_key = get_gemini_api_key() | |
| if not api_key: | |
| raise RuntimeError("Gemini API key not set!") | |
| if genai is None: | |
| raise ImportError("Please install google-generativeai!") | |
| genai.configure(api_key=api_key) | |
| model_obj = genai.GenerativeModel(model) | |
| response = model_obj.generate_content(prompt) | |
| # Correct line: | |
| return response.text if hasattr(response, "text") else str(response) | |