Spaces:
Sleeping
Sleeping
Create app.py
Browse files
app.py
ADDED
@@ -0,0 +1,63 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
import streamlit as st
|
2 |
+
from datetime import date
|
3 |
+
import os
|
4 |
+
from crewai.agent import Agent
|
5 |
+
from pydantic import Field, ValidationError
|
6 |
+
|
7 |
+
# Set OpenAI API Key directly in the code
|
8 |
+
os.environ['OPENAI_API_KEY'] = 'Add your OpenAI API key'
|
9 |
+
# Sentinel2ExportAgent class
|
10 |
+
class Sentinel2ExportAgent(Agent):
|
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.")
|
29 |
+
st.write("Use MindsDB for anomaly detection and data analysis.")
|
30 |
+
|
31 |
+
return "Data stored in PostgreSQL. You can analyze it using MindsDB Anomaly Detection."
|
32 |
+
except Exception as e:
|
33 |
+
return f"Error during the process: {e}"
|
34 |
+
|
35 |
+
# Streamlit app starts here
|
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)
|
42 |
+
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 |
+
# Create the Sentinel2ExportAgent
|
49 |
+
sentinel2_agent = Sentinel2ExportAgent(
|
50 |
+
name="Sentinel2ExportAgent",
|
51 |
+
role="Data Analyst",
|
52 |
+
goal="Export Sentinel-2 imagery from Earth Engine to Google Drive",
|
53 |
+
backstory="The agent assists in data analysis by exporting high-resolution satellite imagery.",
|
54 |
+
project_id=project_id
|
55 |
+
)
|
56 |
+
|
57 |
+
# Fetch and export the image (simulated)
|
58 |
+
result = sentinel2_agent.export_sentinel2_image_to_drive(
|
59 |
+
latitude, longitude, str(start_date), str(end_date), image_name
|
60 |
+
)
|
61 |
+
|
62 |
+
# Display the result
|
63 |
+
st.write(result)
|