Spaces:
Running
Running
Download gemini_client.py from yoursdvniel/SmartInc-API: direct link, hf CLI and curl.
- Browser
- Download file 493 Bytes
-
https://huggingface.co/spaces/yoursdvniel/SmartInc-API/resolve/main/gemini_client.py
- Command line
-
hf download hf://spaces/yoursdvniel/SmartInc-API/gemini_client.py
-
curl -L -o gemini_client.py https://huggingface.co/spaces/yoursdvniel/SmartInc-API/resolve/main/gemini_client.py
493 Bytes
| import os | |
| from google import genai | |
| client = genai.Client(api_key=os.environ["GEMINI_API_KEY"]) | |
| def ask_gpt(messages): | |
| try: | |
| prompt = "\n".join( | |
| [f"{m['role'].capitalize()}: {m['content']}" for m in messages] | |
| ) | |
| response = client.models.generate_content( | |
| model="gemini-2.5-flash", | |
| contents=prompt, | |
| ) | |
| return (response.text or "").strip() | |
| except Exception as e: | |
| return f"⚠️ Gemini Error: {str(e)}" |