This directory contains simple examples showing how to use GeoSpy as a library.
-
Install the required dependencies:
pip install -r requirements.txt
-
Set your Gemini API key:
export GEMINI_API_KEY="your-api-key-here"
On Windows:
set GEMINI_API_KEY=your-api-key-here
GeoSpy returns a JSON object that you can use in your application. Here's how to use it:
from geospyer import GeoSpy
# Initialize
geospy = GeoSpy() # Uses GEMINI_API_KEY from environment
# Analyze an image and get the result JSON
result = geospy.locate(image_path="your_image.jpg")
# The result is a JSON object you can work with
if "error" in result:
# Handle errors
print(f"Error: {result['error']}")
else:
# Work with the data
locations = result.get("locations", [])
if locations:
top_location = locations[0]
print(f"Location: {top_location.get('city')}, {top_location.get('country')}")The result object contains these main sections:
interpretation: Analysis of the imagelocations: Array of possible locations, ordered by confidence
Example of accessing location data:
# Get coordinates for Google Maps
if "locations" in result and result["locations"]:
location = result["locations"][0]
if "coordinates" in location:
lat = location["coordinates"].get("latitude")
lng = location["coordinates"].get("longitude")
maps_url = f"https://www.google.com/maps?q={lat},{lng}"You can easily save the results to a JSON file:
import json
with open("result.json", "w") as f:
json.dump(result, f, indent=2)python library_usage.pyThis will analyze an image and save the results to geospy_result.json without printing to the console.
The library_usage.py file shows the simplest way to use GeoSpy:
from geospyer import GeoSpy
# Initialize
geospy = GeoSpy() # Uses GEMINI_API_KEY from environment
# Analyze an image
result = geospy.locate(image_path="your_image.jpg")
# Print results
print(result)Run the example with:
python library_usage.pyThe simple_api.py file shows a minimal Flask API:
from flask import Flask, request, jsonify
from geospyer import GeoSpy
app = Flask(__name__)
geospy = GeoSpy()
@app.route('/analyze', methods=['POST'])
def analyze():
data = request.json
image_url = data['image_url']
result = geospy.locate(image_path=image_url)
return jsonify(result)
if __name__ == '__main__':
app.run(debug=True, port=5000)Run it with:
python simple_api.pyTest it with:
curl -X POST http://localhost:5000/analyze \
-H "Content-Type: application/json" \
-d '{"image_url": "https://example.com/image.jpg"}'To use GeoSpy in your own projects:
-
Install the package:
pip install geospyer
-
Import and initialize:
from geospyer import GeoSpy # Initialize with API key geospy = GeoSpy(api_key="your-api-key-here") # Or use from environment variable # geospy = GeoSpy()
-
Analyze images:
results = geospy.locate( image_path="path/to/image.jpg", context_info="Optional context", location_guess="Optional guess" )