|
|
""" |
|
|
Simple test script to verify the Gradio setup |
|
|
Run this before launching the full app to check configuration |
|
|
""" |
|
|
|
|
|
import os |
|
|
import sys |
|
|
from dotenv import load_dotenv |
|
|
|
|
|
print("=" * 60) |
|
|
print("π§ͺ Gradio Setup Verification") |
|
|
print("=" * 60) |
|
|
|
|
|
|
|
|
print("\n1οΈβ£ Checking environment file...") |
|
|
env_path = os.path.join(os.path.dirname(__file__), "rag_agent", ".env") |
|
|
if os.path.exists(env_path): |
|
|
print(f" β
Found .env file at: {env_path}") |
|
|
load_dotenv(env_path) |
|
|
else: |
|
|
print(f" β .env file not found at: {env_path}") |
|
|
sys.exit(1) |
|
|
|
|
|
|
|
|
print("\n2οΈβ£ Checking environment variables...") |
|
|
PROJECT_ID = os.environ.get("GOOGLE_CLOUD_PROJECT") |
|
|
LOCATION = os.environ.get("GOOGLE_CLOUD_LOCATION") |
|
|
|
|
|
if PROJECT_ID: |
|
|
print(f" β
GOOGLE_CLOUD_PROJECT: {PROJECT_ID}") |
|
|
else: |
|
|
print(" β GOOGLE_CLOUD_PROJECT not set") |
|
|
sys.exit(1) |
|
|
|
|
|
if LOCATION: |
|
|
print(f" β
GOOGLE_CLOUD_LOCATION: {LOCATION}") |
|
|
else: |
|
|
print(" β οΈ GOOGLE_CLOUD_LOCATION not set, defaulting to 'us-central1'") |
|
|
LOCATION = "us-central1" |
|
|
|
|
|
|
|
|
print("\n3οΈβ£ Checking required packages...") |
|
|
required_packages = { |
|
|
"gradio": "Gradio UI framework", |
|
|
"vertexai": "Vertex AI SDK", |
|
|
"google.cloud.aiplatform_v1beta1": "AI Platform Client", |
|
|
"dotenv": "Environment loader" |
|
|
} |
|
|
|
|
|
all_packages_ok = True |
|
|
for package, description in required_packages.items(): |
|
|
try: |
|
|
__import__(package.replace("-", "_")) |
|
|
print(f" β
{package}: {description}") |
|
|
except ImportError: |
|
|
print(f" β {package}: NOT INSTALLED - {description}") |
|
|
all_packages_ok = False |
|
|
|
|
|
if not all_packages_ok: |
|
|
print("\n β οΈ Missing packages. Install with:") |
|
|
print(" pip install -r requirements.txt") |
|
|
sys.exit(1) |
|
|
|
|
|
|
|
|
print("\n4οΈβ£ Checking Google Cloud authentication...") |
|
|
try: |
|
|
from google.auth import default |
|
|
credentials, project = default() |
|
|
print(f" β
Authenticated with project: {project}") |
|
|
except Exception as e: |
|
|
print(f" β Authentication error: {e}") |
|
|
print(" Run: gcloud auth application-default login") |
|
|
sys.exit(1) |
|
|
|
|
|
|
|
|
print("\n5οΈβ£ Testing Agent Engine connection...") |
|
|
try: |
|
|
from google.cloud import aiplatform_v1beta1 as aiplatform |
|
|
|
|
|
client = aiplatform.AgentEnginesServiceClient( |
|
|
client_options={"api_endpoint": f"{LOCATION}-aiplatform.googleapis.com"} |
|
|
) |
|
|
parent = f"projects/{PROJECT_ID}/locations/{LOCATION}" |
|
|
request = aiplatform.ListAgentEnginesRequest(parent=parent) |
|
|
|
|
|
agents = list(client.list_agent_engines(request=request)) |
|
|
|
|
|
if agents: |
|
|
print(f" β
Successfully connected! Found {len(agents)} agent(s):") |
|
|
for agent in agents: |
|
|
display_name = agent.display_name or agent.name.split("/")[-1] |
|
|
print(f" β’ {display_name}") |
|
|
else: |
|
|
print(" β οΈ Connected, but no agents found") |
|
|
print(" Deploy an agent with: make deploy") |
|
|
|
|
|
except Exception as e: |
|
|
print(f" β Connection error: {e}") |
|
|
print(" Check your project ID and location") |
|
|
sys.exit(1) |
|
|
|
|
|
|
|
|
print("\n" + "=" * 60) |
|
|
print("β
All checks passed! Ready to launch Gradio app") |
|
|
print("=" * 60) |
|
|
print("\nRun the app with:") |
|
|
print(" python gradio_app_v2.py") |
|
|
print("\nOr:") |
|
|
print(" python run_gradio.py") |
|
|
print() |
|
|
|