soctopus2327 commited on
Commit
afd0e9f
Β·
verified Β·
1 Parent(s): 74f516c

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +42 -0
app.py CHANGED
@@ -150,6 +150,25 @@ def create_music_description(data):
150
 
151
  return description
152
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
153
  # Streamlit UI
154
  st.title("🌿 Eco-Symphony 🎢")
155
  st.write("Enter a city to explore real-time environmental data, generate AI-created music, and see an AI-generated image based on the story.")
@@ -210,3 +229,26 @@ if st.button("Generate Environmental Narrative, Music, and Image"):
210
  st.write("Deforestation Rate:", simulated_inner_data.get("Deforestation Rate", "Data not available"))
211
  st.write("Water Quality:", simulated_inner_data.get("Water Quality", "Data not available"))
212
  st.write("Biodiversity Impact:", simulated_inner_data.get("Biodiversity Impact", "Data not available"))
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
150
 
151
  return description
152
 
153
+ # Function to fetch NGOs using OpenAI
154
+ def fetch_nearby_ngos_with_openai(city: str, interests: list) -> list:
155
+ prompt = (
156
+ f"List NGOs near {city} that focus on {', '.join(interests)}. "
157
+ "Provide the names, locations, and focus areas in JSON format."
158
+ )
159
+ response = openai.ChatCompletion.create(
160
+ model="gpt-3.5-turbo",
161
+ messages=[{"role": "user", "content": prompt}],
162
+ max_tokens=200,
163
+ temperature=0.7
164
+ )
165
+ response_content = response.choices[0].message['content'].strip()
166
+ try:
167
+ return eval(response_content)
168
+ except Exception as e:
169
+ st.error(f"Error fetching NGO data: {e}")
170
+ return []
171
+
172
  # Streamlit UI
173
  st.title("🌿 Eco-Symphony 🎢")
174
  st.write("Enter a city to explore real-time environmental data, generate AI-created music, and see an AI-generated image based on the story.")
 
229
  st.write("Deforestation Rate:", simulated_inner_data.get("Deforestation Rate", "Data not available"))
230
  st.write("Water Quality:", simulated_inner_data.get("Water Quality", "Data not available"))
231
  st.write("Biodiversity Impact:", simulated_inner_data.get("Biodiversity Impact", "Data not available"))
232
+
233
+ # Collect User's Environmental Interests
234
+ st.subheader("🌍 Get Involved!")
235
+ st.write("Choose your areas of interest for saving the environment:")
236
+ interests = st.multiselect(
237
+ "Select Areas of Interest:",
238
+ ["Afforestation", "Water Conservation", "Biodiversity Protection", "Recycling", "Climate Change Awareness"]
239
+ )
240
+
241
+ if st.button("Find Nearby NGOs"):
242
+ if interests:
243
+ ngos = fetch_nearby_ngos_with_openai(city, interests)
244
+ if ngos:
245
+ st.subheader("🌟 NGOs Near You")
246
+ for ngo in ngos:
247
+ st.write(f"**{ngo['name']}**")
248
+ st.write(f"πŸ“ Location: {ngo['location']}")
249
+ st.write(f"🌱 Focus Area: {ngo['focus']}")
250
+ st.write("---")
251
+ else:
252
+ st.write("No NGOs found nearby in your areas of interest.")
253
+ else:
254
+ st.warning("Please select at least one area of interest.")