Spaces:
Sleeping
Sleeping
Nikhil0987
commited on
Commit
•
56ce0fa
1
Parent(s):
92ab597
Update chat.py
Browse files
chat.py
CHANGED
@@ -1,26 +1,47 @@
|
|
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 |
|
|
|
1 |
+
import streamlit as st
|
2 |
+
import json
|
3 |
+
import google.generativeai as genai
|
4 |
+
|
5 |
+
|
6 |
+
GOOGLE_API_KEY = "AIzaSyCUBaL7TdISL7lRuBy19_X0-OsZfgbIgEc"
|
7 |
+
genai.configure(api_key=GOOGLE_API_KEY)
|
8 |
+
model = genai.GenerativeModel('gemini-pro')
|
9 |
+
|
10 |
+
def add_to_json(goal):
|
11 |
+
try:
|
12 |
+
with open("test.json", "r") as file:
|
13 |
+
data = json.load(file)
|
14 |
+
except FileNotFoundError:
|
15 |
+
data = {"goals": []} # Create the file with an empty 'goals' list if it doesn't exist
|
16 |
+
|
17 |
+
new_item = {"Goal": goal}
|
18 |
+
data["goals"].append(new_item)
|
19 |
+
|
20 |
+
with open("test.json", "w") as file:
|
21 |
+
json.dump(data, file, indent=4)
|
22 |
+
|
23 |
+
|
24 |
+
|
25 |
+
def main():
|
26 |
+
if prompt := st.chat_input("Hi, how can I help you?"):
|
27 |
+
goals_prompt = f"""Act as a personal assistant... {prompt} """
|
28 |
+
completion = model.generate_content(goals_prompt)
|
29 |
+
add_to_json(prompt)
|
30 |
+
|
31 |
+
with st.chat_message("Assistant"):
|
32 |
+
st.write(completion.text)
|
33 |
+
|
34 |
+
|
35 |
+
|
36 |
+
# Display JSON Data
|
37 |
+
if st.button("Show JSON Data"):
|
38 |
+
with open("test.json", "r") as file:
|
39 |
+
data = json.load(file)
|
40 |
+
st.json(data) # Streamlit's way to display JSON
|
41 |
+
|
42 |
+
|
43 |
+
if __name__ == "__main__":
|
44 |
+
main()
|
45 |
|
46 |
|
47 |
|