Spaces:
Sleeping
Sleeping
Download intelligence_utils.py from mrfaraidun/auravision-api: direct link, hf CLI and curl.
- Browser
- Download file 1.48 kB
-
https://huggingface.co/spaces/mrfaraidun/auravision-api/resolve/main/intelligence_utils.py
- Command line
-
hf download hf://spaces/mrfaraidun/auravision-api/intelligence_utils.py
-
curl -L -o intelligence_utils.py https://huggingface.co/spaces/mrfaraidun/auravision-api/resolve/main/intelligence_utils.py
1.48 kB
| import logging, json, google.generativeai as genai | |
| logger = logging.getLogger(__name__) | |
| def probe_available_models(): | |
| try: | |
| models = [m.name for m in genai.list_models()] | |
| for m in ["models/gemini-1.5-flash", "models/gemini-1.5-pro", "models/gemini-pro"]: | |
| if m in models: return m.replace("models/", "") | |
| return models[0].replace("models/", "") if models else "gemini-pro" | |
| except: return "gemini-1.5-flash" | |
| def cleanup_json_response(resp_text): | |
| resp_text = resp_text.strip() | |
| if resp_text.startswith("```"): | |
| resp_text = resp_text.split("```", 2)[1] | |
| if resp_text.startswith("json"): resp_text = resp_text[4:] | |
| resp_text = resp_text.strip() | |
| try: | |
| start_idx = resp_text.index("{") | |
| depth = 0 | |
| for i in range(start_idx, len(resp_text)): | |
| if resp_text[i] == "{": depth += 1 | |
| elif resp_text[i] == "}": | |
| depth -= 1 | |
| if depth == 0: return resp_text[start_idx:i+1] | |
| except: pass | |
| return resp_text | |
| def get_fallback_result(transcript_data): | |
| return { | |
| "metadata": {"title": "Unknown", "detectedMood": "Abstract", "energyLevel": 0.5, "coverArtPrompt": "Moody abstract"}, | |
| "script": [{"text": t["text"], "timestamp": t["start"], "duration": 2.5, | |
| "visuals": {"primaryColor": "#ffffff", "typography": "fade", "position": "center", "energy": 0.5}} | |
| for t in transcript_data] | |
| } | |