rianders commited on
Commit
db8c25e
·
verified ·
1 Parent(s): 6f1643e

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +49 -6
app.py CHANGED
@@ -4,6 +4,8 @@ from dotenv import load_dotenv
4
  import os
5
  import requests
6
  import hashlib
 
 
7
  from crewai import Agent, Task, Crew
8
  from langchain.tools import tool
9
 
@@ -16,6 +18,41 @@ GITHUB_ACCESS_TOKEN = userdata.get('GITHUB_ACCESS_TOKEN')
16
  # Initialize the OpenAI client
17
  openai_client = OpenAI(api_key=os.getenv('OPENAI_API_KEY'))
18
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
19
  # Define the custom tool for GitHub interaction
20
  @tool
21
  def github_streamlit_expert() -> str:
@@ -96,10 +133,16 @@ if st.button("Ask"):
96
  for chat in chat_history:
97
  st.text(chat)
98
 
99
- # Manual update button
100
- if st.button('Check for Streamlit Updates Now'):
101
- result = crew.kickoff() # Trigger the Crew to perform the update task
102
- st.write(result)
103
- else:
104
- st.write('Click the button above to check for updates.')
 
 
 
 
 
 
105
 
 
4
  import os
5
  import requests
6
  import hashlib
7
+ from git import Repo, exc
8
+
9
  from crewai import Agent, Task, Crew
10
  from langchain.tools import tool
11
 
 
18
  # Initialize the OpenAI client
19
  openai_client = OpenAI(api_key=os.getenv('OPENAI_API_KEY'))
20
 
21
+ def check_for_updates(repo_path, remote_name='origin', branch='main'):
22
+ """
23
+ Check for updates in the specified Git repository using GitPython.
24
+ Input: repo_path - Path to the local git repository.
25
+ Output: A string indicating if updates are available or not.
26
+ """
27
+ try:
28
+ # Open the existing repository
29
+ repo = Repo(repo_path)
30
+ if repo.bare:
31
+ raise Exception("Repository is bare.")
32
+
33
+ # Fetch updates from the remote repository
34
+ remote = repo.remotes[remote_name]
35
+ fetch_info = remote.fetch()
36
+
37
+ # Compare local and remote branches
38
+ local_commit = repo.heads[branch].commit
39
+ remote_commit = repo.refs[f'refs/remotes/{remote_name}/{branch}'].commit
40
+
41
+ if local_commit.hexsha != remote_commit.hexsha:
42
+ return "Updates are available."
43
+ else:
44
+ return "No updates available."
45
+
46
+ except exc.InvalidGitRepositoryError:
47
+ return "Invalid Git repository."
48
+ except Exception as e:
49
+ return f"Error: {str(e)}"
50
+
51
+ # Example usage
52
+ # repo_path = "/path/to/your/streamlit-repo"
53
+ # print(check_for_updates(repo_path))
54
+
55
+
56
  # Define the custom tool for GitHub interaction
57
  @tool
58
  def github_streamlit_expert() -> str:
 
133
  for chat in chat_history:
134
  st.text(chat)
135
 
136
+ # Button to check for updates in the Streamlit GitHub repository
137
+ if st.button('Check for Streamlit GitHub Updates'):
138
+ repo_path = "/path/to/your/streamlit-repo" # Path to your local Streamlit repository
139
+ update_status = check_for_updates(repo_path)
140
+ st.write(update_status)
141
+
142
+ if "Updates are available" in update_status:
143
+ pass
144
+ # Optionally, trigger further actions like updating the local repo or analyzing changes
145
+ # For example:
146
+ # response = analyze_new_changes(repo_path)
147
+ # st.write(response)
148