Spaces:
Build error
Build error
File size: 1,511 Bytes
8a1a76f ccd6ee3 4ce5796 f42fd59 ccd6ee3 83154c3 ccd6ee3 40197f2 ccd6ee3 83154c3 4ce5796 83154c3 40197f2 0262447 9b1f668 4ce5796 ccd6ee3 8a1a76f ccd6ee3 9b1f668 40197f2 4ce5796 8a1a76f 4ce5796 9b1f668 c3aaa36 4ce5796 |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 |
import streamlit as st
import json
import google.generativeai as genai
def add_to_json(goal):
"""
Adds a new goal to the "test.json" file, ensuring the JSON structure is correct.
Args:
goal (str): The goal text to be added.
"""
try:
with open("test.json", "r") as file:
data = json.load(file)
except FileNotFoundError:
data = {"goals": []} # Create the file with an empty 'goals' list if it doesn't exist
new_item = {"Goal": goal}
data["goals"].append(new_item)
with open("test.json", "w") as file:
json.dump(data, file, indent=4)
add_to_json(goal)
GOOGLE_API_KEY = "AIzaSyCUBaL7TdISL7lRuBy19_X0-OsZfgbIgEc"
genai.configure(api_key=GOOGLE_API_KEY)
model = genai.GenerativeModel('gemini-pro')
def main():
"""
Main application logic. Handles user input, interaction with generative AI, data saving, and JSON display.
"""
prompt = st.chat_input("Hi, how can I help you?")
if prompt:
goal = prompt
goals_prompt = f"""Act as a personal assistant... {goal} """
completion = model.generate_content(goals_prompt)
with st.chat_message("Assistant"):
st.write(completion.text)
# Display JSON Data
if st.button("Show JSON Data"):
with open("test.json", "r") as file:
data = json.load(file)
st.json(data) # Streamlit's way to display JSON
if __name__ == "__main__":
main()
|