Spaces:
Running
Running
Commit
·
dec42d4
1
Parent(s):
a6d62e8
Debug
Browse files- app/services/summary_service.py +11 -4
- requirements.txt +1 -1
app/services/summary_service.py
CHANGED
|
@@ -3,21 +3,28 @@ import logging
|
|
| 3 |
|
| 4 |
from app.config import GEMINI_API_KEY
|
| 5 |
|
| 6 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 7 |
from google.api_core.exceptions import GoogleAPIError
|
| 8 |
|
| 9 |
_SUMMARY_MODEL = "gemini-1.5-flash"
|
| 10 |
_gemini_client = None
|
| 11 |
|
| 12 |
-
if
|
|
|
|
|
|
|
|
|
|
|
|
|
| 13 |
try:
|
| 14 |
_gemini_client = genai.Client(api_key=GEMINI_API_KEY)
|
| 15 |
logging.info(f"[summary_service] Initialized google.genai client with model={_SUMMARY_MODEL}")
|
| 16 |
except Exception as e:
|
| 17 |
logging.exception(f"[summary_service] Failed to init google.genai client: {e}")
|
| 18 |
_gemini_client = None
|
| 19 |
-
else:
|
| 20 |
-
logging.warning("[summary_service] GEMINI_API_KEY is not set, summary will be empty")
|
| 21 |
|
| 22 |
|
| 23 |
async def generate_summary(text: str) -> str:
|
|
|
|
| 3 |
|
| 4 |
from app.config import GEMINI_API_KEY
|
| 5 |
|
| 6 |
+
try:
|
| 7 |
+
import google.genai as genai
|
| 8 |
+
except Exception:
|
| 9 |
+
genai = None
|
| 10 |
+
logging.warning("[summary_service] google.genai module not found; summaries disabled")
|
| 11 |
+
|
| 12 |
from google.api_core.exceptions import GoogleAPIError
|
| 13 |
|
| 14 |
_SUMMARY_MODEL = "gemini-1.5-flash"
|
| 15 |
_gemini_client = None
|
| 16 |
|
| 17 |
+
if not genai:
|
| 18 |
+
logging.warning("[summary_service] google.genai not available, summary will be empty")
|
| 19 |
+
elif not GEMINI_API_KEY:
|
| 20 |
+
logging.warning("[summary_service] GEMINI_API_KEY is not set, summary will be empty")
|
| 21 |
+
else:
|
| 22 |
try:
|
| 23 |
_gemini_client = genai.Client(api_key=GEMINI_API_KEY)
|
| 24 |
logging.info(f"[summary_service] Initialized google.genai client with model={_SUMMARY_MODEL}")
|
| 25 |
except Exception as e:
|
| 26 |
logging.exception(f"[summary_service] Failed to init google.genai client: {e}")
|
| 27 |
_gemini_client = None
|
|
|
|
|
|
|
| 28 |
|
| 29 |
|
| 30 |
async def generate_summary(text: str) -> str:
|
requirements.txt
CHANGED
|
@@ -1,4 +1,4 @@
|
|
| 1 |
fastapi
|
| 2 |
uvicorn
|
| 3 |
-
google-
|
| 4 |
firebase-admin
|
|
|
|
| 1 |
fastapi
|
| 2 |
uvicorn
|
| 3 |
+
google-genai
|
| 4 |
firebase-admin
|