Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
@@ -156,6 +156,31 @@ def fetch_endangered_species(city: str) -> dict:
|
|
156 |
st.error(f"Error parsing endangered species data: {e}")
|
157 |
return {}
|
158 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
159 |
# Streamlit UI
|
160 |
st.title("🌿 Eco-Symphony 🎶")
|
161 |
st.write("Enter a city to explore real-time environmental data, complete daily challenges, and unlock hidden content!")
|
|
|
156 |
st.error(f"Error parsing endangered species data: {e}")
|
157 |
return {}
|
158 |
|
159 |
+
# Function to fetch NGOs using OpenAI
|
160 |
+
def fetch_nearby_ngos_with_openai(city: str, interests: list) -> list:
|
161 |
+
prompt = (
|
162 |
+
f"List NGOs near {city} that focus on {', '.join(interests)}. "
|
163 |
+
"Provide the names, locations, and focus areas in JSON format as a list of dictionaries."
|
164 |
+
)
|
165 |
+
response = openai.ChatCompletion.create(
|
166 |
+
model="gpt-3.5-turbo",
|
167 |
+
messages=[{"role": "user", "content": prompt}],
|
168 |
+
max_tokens=200,
|
169 |
+
temperature=0.7
|
170 |
+
)
|
171 |
+
response_content = response.choices[0].message['content'].strip()
|
172 |
+
|
173 |
+
try:
|
174 |
+
ngo_list = eval(response_content)
|
175 |
+
if isinstance(ngo_list, list) and all(isinstance(ngo, dict) for ngo in ngo_list):
|
176 |
+
return ngo_list
|
177 |
+
else:
|
178 |
+
st.error("Unexpected response format. Could not parse NGO data.")
|
179 |
+
return []
|
180 |
+
except Exception as e:
|
181 |
+
st.error(f"Error fetching NGO data: {e}")
|
182 |
+
return []
|
183 |
+
|
184 |
# Streamlit UI
|
185 |
st.title("🌿 Eco-Symphony 🎶")
|
186 |
st.write("Enter a city to explore real-time environmental data, complete daily challenges, and unlock hidden content!")
|