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