Che237 commited on
Commit
e08ee7b
·
verified ·
1 Parent(s): d8acf85

Fix cells 6 and 7 - self-contained config loading

Browse files
notebooks/00_environment_setup.ipynb CHANGED
@@ -172,37 +172,7 @@
172
  "id": "14cef3bc",
173
  "metadata": {},
174
  "outputs": [],
175
- "source": [
176
- "import google.generativeai as genai\n",
177
- "\n",
178
- "def test_gemini_connection():\n",
179
- " \"\"\"Test Gemini API connectivity\"\"\"\n",
180
- " if not config.GEMINI_API_KEY:\n",
181
- " return False, \"API key not configured\"\n",
182
- " \n",
183
- " try:\n",
184
- " genai.configure(api_key=config.GEMINI_API_KEY)\n",
185
- " # Use the configured model (gemini-2.5-flash)\n",
186
- " model = genai.GenerativeModel(config.GEMINI_MODEL)\n",
187
- " response = model.generate_content(\"Respond with only: OK\")\n",
188
- " return True, f\"Model: {config.GEMINI_MODEL}, Response: {response.text.strip()}\"\n",
189
- " except Exception as e:\n",
190
- " # Fallback to gemini-1.5-flash if 2.5 not available\n",
191
- " try:\n",
192
- " model = genai.GenerativeModel('gemini-1.5-flash')\n",
193
- " response = model.generate_content(\"Respond with only: OK\")\n",
194
- " return True, f\"Model: gemini-1.5-flash (fallback), Response: {response.text.strip()}\"\n",
195
- " except Exception as e2:\n",
196
- " return False, str(e2)\n",
197
- "\n",
198
- "print(\"Testing Gemini API connection...\")\n",
199
- "success, message = test_gemini_connection()\n",
200
- "\n",
201
- "if success:\n",
202
- " print(f\"\u2713 Gemini API: {message}\")\n",
203
- "else:\n",
204
- " print(f\"\u26a0 Gemini API: Connection failed - {message}\")"
205
- ]
206
  },
207
  {
208
  "cell_type": "markdown",
@@ -218,7 +188,7 @@
218
  "id": "beb1b036",
219
  "metadata": {},
220
  "outputs": [],
221
- "source": "import httpx\n\ndef test_webscraper_connection_sync():\n \"\"\"Test WebScrapper.live API connectivity (sync version)\"\"\"\n try:\n with httpx.Client(timeout=30.0) as client:\n response = client.post(\n config.WEBSCRAPER_API_URL,\n json={\"url\": \"https://example.com\"},\n headers={\n \"Content-Type\": \"application/json\",\n \"X-API-Key\": config.WEBSCRAPER_API_KEY\n }\n )\n if response.status_code == 200:\n return True, \"Connected\"\n else:\n return False, f\"Status {response.status_code}: {response.text[:100]}\"\n except Exception as e:\n return False, str(e)\n\nprint(\"Testing Web Scraper API connection...\")\nsuccess, message = test_webscraper_connection_sync()\n\nif success:\n print(f\"\u2713 WebScraper API: Connected successfully\")\nelse:\n print(f\"\u26a0 WebScraper API: {message}\")\n"
222
  },
223
  {
224
  "cell_type": "markdown",
 
172
  "id": "14cef3bc",
173
  "metadata": {},
174
  "outputs": [],
175
+ "source": "import google.generativeai as genai\nimport json\nimport os\nfrom pathlib import Path\n\n# Load config (self-contained)\nconfig_json_path = Path('notebook_config.json')\nif config_json_path.exists():\n with open(config_json_path, 'r') as f:\n loaded_config = json.load(f)\nelse:\n loaded_config = {}\n\nGEMINI_API_KEY = loaded_config.get('gemini_api_key') or os.getenv('GEMINI_API_KEY', '')\nGEMINI_MODEL = loaded_config.get('gemini_model', 'gemini-2.5-flash')\n\ndef test_gemini_connection():\n if not GEMINI_API_KEY:\n return False, 'API key not configured'\n try:\n genai.configure(api_key=GEMINI_API_KEY)\n model = genai.GenerativeModel(GEMINI_MODEL)\n response = model.generate_content('Respond with only: OK')\n return True, f'Model: {GEMINI_MODEL}, Response: {response.text.strip()}'\n except Exception as e:\n try:\n model = genai.GenerativeModel('gemini-1.5-flash')\n response = model.generate_content('Respond with only: OK')\n return True, f'Model: gemini-1.5-flash (fallback), Response: {response.text.strip()}'\n except Exception as e2:\n return False, str(e2)\n\nprint('Testing Gemini API connection...')\nsuccess, message = test_gemini_connection()\nif success:\n print(f'\u2713 Gemini API: {message}')\nelse:\n print(f'\u26a0 Gemini API: Connection failed - {message}')\n"
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
176
  },
177
  {
178
  "cell_type": "markdown",
 
188
  "id": "beb1b036",
189
  "metadata": {},
190
  "outputs": [],
191
+ "source": "import httpx\nimport json\nimport os\nfrom pathlib import Path\n\n# Load config (self-contained)\nconfig_json_path = Path('notebook_config.json')\nif config_json_path.exists():\n with open(config_json_path, 'r') as f:\n loaded_config = json.load(f)\nelse:\n loaded_config = {}\n\nWEBSCRAPER_API_KEY = loaded_config.get('webscraper_api_key', 'sk-fd14eaa7bceb478db7afc7256e514d2b')\nWEBSCRAPER_API_URL = loaded_config.get('webscraper_api_url', 'http://webscrapper.live/api/scrape')\n\ndef test_webscraper_connection_sync():\n try:\n with httpx.Client(timeout=30.0) as client:\n response = client.post(\n WEBSCRAPER_API_URL,\n json={'url': 'https://example.com'},\n headers={'Content-Type': 'application/json', 'X-API-Key': WEBSCRAPER_API_KEY}\n )\n if response.status_code == 200:\n return True, 'Connected'\n else:\n return False, f'Status {response.status_code}'\n except Exception as e:\n return False, str(e)\n\nprint('Testing Web Scraper API connection...')\nsuccess, message = test_webscraper_connection_sync()\nif success:\n print(f'\u2713 WebScraper API: Connected successfully')\nelse:\n print(f'\u26a0 WebScraper API: {message}')\n"
192
  },
193
  {
194
  "cell_type": "markdown",