Spaces:
Sleeping
Sleeping
Change deployment from Streamlit to Hugging Face Spaces- Update README.md with Hugging Face Spaces deployment instructions- Add requirements.txt for Hugging Face Spaces- Minor adjustments to app.py for compatibility
Browse files
README.md
CHANGED
|
@@ -9,4 +9,39 @@ app_file: app.py
|
|
| 9 |
pinned: false
|
| 10 |
---
|
| 11 |
|
| 12 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 9 |
pinned: false
|
| 10 |
---
|
| 11 |
|
| 12 |
+
# Data Fetcher AI Agent
|
| 13 |
+
|
| 14 |
+
This Streamlit app simulates fetching Sentinel-2 satellite imagery data and storing it in a PostgreSQL database. It's designed to demonstrate the process of data collection and storage for further analysis using tools like MindsDB for anomaly detection.
|
| 15 |
+
|
| 16 |
+
## Features
|
| 17 |
+
|
| 18 |
+
- Input your OpenAI API key securely
|
| 19 |
+
- Input geographical coordinates (latitude and longitude)
|
| 20 |
+
- Specify date range for data collection
|
| 21 |
+
- Simulate data storage in PostgreSQL
|
| 22 |
+
- Prepare data for analysis with MindsDB
|
| 23 |
+
|
| 24 |
+
## How to Use
|
| 25 |
+
|
| 26 |
+
1. Enter your OpenAI API key in the sidebar (this is required to run the app)
|
| 27 |
+
2. Enter your Earth Engine Project ID (or use the default)
|
| 28 |
+
3. Input the latitude and longitude of your area of interest
|
| 29 |
+
4. Select the start and end dates for your data collection period
|
| 30 |
+
5. Provide a name for your image
|
| 31 |
+
6. Click "Fetch Sentinel-2 Image" to simulate the data collection and storage process
|
| 32 |
+
|
| 33 |
+
## Security Note
|
| 34 |
+
|
| 35 |
+
Your API key is not stored and is only used for the current session. It's securely handled and not displayed after entry.
|
| 36 |
+
|
| 37 |
+
## Note
|
| 38 |
+
|
| 39 |
+
This app is a simulation and does not actually connect to Earth Engine or store data in PostgreSQL. It's designed to demonstrate the user interface and workflow of such a system.
|
| 40 |
+
|
| 41 |
+
## Future Improvements
|
| 42 |
+
|
| 43 |
+
- Implement actual connection to Earth Engine
|
| 44 |
+
- Set up real-time data storage in PostgreSQL
|
| 45 |
+
- Integrate MindsDB for anomaly detection and data analysis
|
| 46 |
+
|
| 47 |
+
Feel free to contribute to this project or use it as a starting point for your own data analysis workflows!
|
app.py
CHANGED
|
@@ -1,28 +1,17 @@
|
|
| 1 |
import streamlit as st
|
| 2 |
from datetime import date
|
| 3 |
import os
|
| 4 |
-
from
|
| 5 |
-
from pydantic import Field, ValidationError
|
| 6 |
|
| 7 |
-
|
| 8 |
-
|
| 9 |
-
|
| 10 |
-
|
|
|
|
| 11 |
project_id: str = Field(..., description="Project ID for Earth Engine")
|
| 12 |
|
| 13 |
-
def __init__(self, name, role, goal, backstory, project_id):
|
| 14 |
-
try:
|
| 15 |
-
super().__init__(name=name, role=role, goal=goal, backstory=backstory, project_id=project_id)
|
| 16 |
-
except ValidationError as e:
|
| 17 |
-
st.error(f"Validation Error: {e}")
|
| 18 |
-
return
|
| 19 |
-
|
| 20 |
-
self.project_id = project_id
|
| 21 |
-
st.write("Earth Engine Authentication skipped. Data will be stored in PostgreSQL.")
|
| 22 |
-
|
| 23 |
def export_sentinel2_image_to_drive(self, latitude, longitude, start_date, end_date, image_name):
|
| 24 |
try:
|
| 25 |
-
# Instead of fetching from Earth Engine, we'll display the message
|
| 26 |
st.write(f"Image '{image_name}' with data for the region around Latitude: {latitude}, Longitude: {longitude} "
|
| 27 |
f"for the period from {start_date} to {end_date} has been stored in PostgreSQL.")
|
| 28 |
st.write("The data is now available in PostgreSQL for further analysis.")
|
|
@@ -36,6 +25,7 @@ class Sentinel2ExportAgent(Agent):
|
|
| 36 |
st.title("Data Fetcher AI Agent")
|
| 37 |
|
| 38 |
# Sidebar inputs
|
|
|
|
| 39 |
project_id = st.sidebar.text_input("Enter your Earth Engine Project ID", "genai-agent-hack-2024")
|
| 40 |
latitude = st.sidebar.number_input("Latitude", min_value=-90.0, max_value=90.0, value=37.7749, step=0.01)
|
| 41 |
longitude = st.sidebar.number_input("Longitude", min_value=-180.0, max_value=180.0, value=-122.4194, step=0.01)
|
|
@@ -43,21 +33,36 @@ start_date = st.sidebar.date_input("Start Date", value=date(2021, 6, 1))
|
|
| 43 |
end_date = st.sidebar.date_input("End Date", value=date(2021, 6, 30))
|
| 44 |
image_name = st.sidebar.text_input("Image Name", "sentinel2_image")
|
| 45 |
|
|
|
|
|
|
|
|
|
|
|
|
|
| 46 |
# Run the data fetch when button is clicked
|
| 47 |
if st.sidebar.button("Fetch Sentinel-2 Image"):
|
| 48 |
-
|
| 49 |
-
|
| 50 |
-
|
| 51 |
-
|
| 52 |
-
|
| 53 |
-
|
| 54 |
-
|
| 55 |
-
|
| 56 |
-
|
| 57 |
-
|
| 58 |
-
|
| 59 |
-
|
| 60 |
-
|
| 61 |
-
|
| 62 |
-
|
| 63 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
import streamlit as st
|
| 2 |
from datetime import date
|
| 3 |
import os
|
| 4 |
+
from pydantic import BaseModel, Field, ValidationError
|
|
|
|
| 5 |
|
| 6 |
+
class Sentinel2ExportAgent(BaseModel):
|
| 7 |
+
name: str
|
| 8 |
+
role: str
|
| 9 |
+
goal: str
|
| 10 |
+
backstory: str
|
| 11 |
project_id: str = Field(..., description="Project ID for Earth Engine")
|
| 12 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 13 |
def export_sentinel2_image_to_drive(self, latitude, longitude, start_date, end_date, image_name):
|
| 14 |
try:
|
|
|
|
| 15 |
st.write(f"Image '{image_name}' with data for the region around Latitude: {latitude}, Longitude: {longitude} "
|
| 16 |
f"for the period from {start_date} to {end_date} has been stored in PostgreSQL.")
|
| 17 |
st.write("The data is now available in PostgreSQL for further analysis.")
|
|
|
|
| 25 |
st.title("Data Fetcher AI Agent")
|
| 26 |
|
| 27 |
# Sidebar inputs
|
| 28 |
+
api_key = st.sidebar.text_input("Enter your OpenAI API Key", type="password")
|
| 29 |
project_id = st.sidebar.text_input("Enter your Earth Engine Project ID", "genai-agent-hack-2024")
|
| 30 |
latitude = st.sidebar.number_input("Latitude", min_value=-90.0, max_value=90.0, value=37.7749, step=0.01)
|
| 31 |
longitude = st.sidebar.number_input("Longitude", min_value=-180.0, max_value=180.0, value=-122.4194, step=0.01)
|
|
|
|
| 33 |
end_date = st.sidebar.date_input("End Date", value=date(2021, 6, 30))
|
| 34 |
image_name = st.sidebar.text_input("Image Name", "sentinel2_image")
|
| 35 |
|
| 36 |
+
# Function to set the API key
|
| 37 |
+
def set_api_key(key):
|
| 38 |
+
os.environ['OPENAI_API_KEY'] = key
|
| 39 |
+
|
| 40 |
# Run the data fetch when button is clicked
|
| 41 |
if st.sidebar.button("Fetch Sentinel-2 Image"):
|
| 42 |
+
if not api_key:
|
| 43 |
+
st.error("Please enter your OpenAI API Key.")
|
| 44 |
+
else:
|
| 45 |
+
set_api_key(api_key)
|
| 46 |
+
try:
|
| 47 |
+
# Create the Sentinel2ExportAgent
|
| 48 |
+
sentinel2_agent = Sentinel2ExportAgent(
|
| 49 |
+
name="Sentinel2ExportAgent",
|
| 50 |
+
role="Data Analyst",
|
| 51 |
+
goal="Export Sentinel-2 imagery from Earth Engine to Google Drive",
|
| 52 |
+
backstory="The agent assists in data analysis by exporting high-resolution satellite imagery.",
|
| 53 |
+
project_id=project_id
|
| 54 |
+
)
|
| 55 |
+
|
| 56 |
+
# Fetch and export the image (simulated)
|
| 57 |
+
result = sentinel2_agent.export_sentinel2_image_to_drive(
|
| 58 |
+
latitude, longitude, str(start_date), str(end_date), image_name
|
| 59 |
+
)
|
| 60 |
+
|
| 61 |
+
# Display the result
|
| 62 |
+
st.write(result)
|
| 63 |
+
except ValidationError as e:
|
| 64 |
+
st.error(f"Validation Error: {e}")
|
| 65 |
+
|
| 66 |
+
# Add a note about API key security
|
| 67 |
+
st.sidebar.markdown("---")
|
| 68 |
+
st.sidebar.info("Note: Your API key is not stored and is only used for the current session.")
|