Spaces:
Build error
Build error
| import streamlit as st | |
| import json | |
| import google.generativeai as genai | |
| def add_to_json(goal): # Renamed 'new_goal' to 'goal' for clarity | |
| with open("test.json", "r") as file: | |
| data = json.load(file) | |
| new_item = { | |
| "goal": goal, | |
| # "reminder": new_reminder # Remove if not used | |
| } | |
| data["goals"].append(new_item) | |
| with open("test.json", "w") as file: | |
| json.dump(data, file, indent=4) | |
| GOOGLE_API_KEY = "AIzaSyCUBaL7TdISL7lRuBy19_X0-OsZfgbIgEc" | |
| genai.configure(api_key=GOOGLE_API_KEY) | |
| model = genai.GenerativeModel('gemini-pro') | |
| def main(): # Wrap main logic in a function | |
| if prompt := st.chat_input("Hi, how can I help you?"): | |
| goal = prompt # Capture the user's goal | |
| goals_prompt = f"""Act as a personal assistant. Understand user intent from the point of view for asking a few questions. Ask to know more details about {goal} :- {goal}""" | |
| completion = model.generate_content(goals_prompt) | |
| with st.chat_message("Assistant"): | |
| st.write(completion.text) | |
| add_to_json(goal) # Save the goal to JSON | |
| if __name__ == "__main__": | |
| main() | |