File size: 1,221 Bytes
56ce0fa
 
 
 
b9d8725
551670d
 
 
56ce0fa
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
c910970
 
 
 
9e04f95
 
 
 
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
import streamlit as st 
import json
import google.generativeai as genai

def Chat():
    GOOGLE_API_KEY = "AIzaSyCUBaL7TdISL7lRuBy19_X0-OsZfgbIgEc"
    genai.configure(api_key=GOOGLE_API_KEY)
    model = genai.GenerativeModel('gemini-pro')

def add_to_json(goal):
    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)
        


def main():
    if prompt := st.chat_input("Hi, how can I help you?"):
        goals_prompt = f"""Act as a personal assistant... {prompt} """  
        completion = model.generate_content(goals_prompt)
        add_to_json(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()