vsagar100 commited on
Commit
83b4b70
·
verified ·
1 Parent(s): 38463c8

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +63 -63
app.py CHANGED
@@ -34,66 +34,66 @@ GITHUB_REPO_URL = st.text_input("Enter the GitHub repository URL:")
34
  GITHUB_BRANCH = st.text_input("Enter the branch or tag to download (default: main):", "main")
35
 
36
  # Check if the GitHub token is provided as a secret in Streamlit
37
- #if "GITHUB_TOKEN" not in st.secrets:
38
- # st.error("GitHub token is not available. Please set it in the secrets.")
39
- #else:
40
- GITHUB_TOKEN = "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"# st.secrets["GITHUB_TOKEN"]
41
-
42
- # Add a button for fine-tuning the model
43
- if st.button("Fine-Tune Model"):
44
- with st.spinner("Fine-tuning the model with provided dataset..."):
45
- code_reviewer = CodeReviewer()
46
- code_reviewer.fine_tune_model(training_dataset)
47
- st.success("Model fine-tuned successfully.")
48
-
49
- if st.button("Review Code") and GITHUB_REPO_URL:
50
- # Directory structure setup
51
- download_directory = "downloaded_repo"
52
- output_directory = "output_reviews"
53
-
54
- # Ensure the directories exist
55
- os.makedirs(download_directory, exist_ok=True)
56
- os.makedirs(output_directory, exist_ok=True)
57
-
58
- # Initialize the code reviewer and review manager
59
- with st.spinner("Initializing CodeReviewer and ReviewManager..."):
60
- code_reviewer = CodeReviewer()
61
- review_manager = ReviewManager(reviewer=code_reviewer)
62
-
63
- try:
64
- # Download GitHub repository
65
- with st.spinner("Downloading GitHub repository..."):
66
- review_manager.download_repo(GITHUB_REPO_URL, GITHUB_BRANCH, GITHUB_TOKEN, download_directory)
67
- st.success("Repository downloaded successfully.")
68
-
69
- # Find all YAML files in the downloaded repository
70
- with st.spinner("Searching for YAML files in the downloaded repository..."):
71
- yaml_files = glob.glob(os.path.join(download_directory, "**", "*.yml"), recursive=True)
72
- yaml_files += glob.glob(os.path.join(download_directory, "**", "*.yaml"), recursive=True)
73
- st.info(f"Found {len(yaml_files)} YAML files for review.")
74
-
75
- # Process files and generate reviews
76
- with st.spinner("Processing files for review..."):
77
- reviews = review_manager.process_files(yaml_files)
78
- st.success("Files processed successfully.")
79
-
80
- # Save reviews to JSON
81
- output_json_path = os.path.join(output_directory, "code_review_results.json")
82
- review_manager.save_reviews_to_json(reviews, output_json_path)
83
-
84
- # Display review results
85
- st.success(f"Reviews saved to {output_json_path}")
86
- for review in reviews:
87
- st.subheader(f"Review for {review['filename']}")
88
- st.text(review['review'])
89
-
90
- # Display JSON output on the UI
91
- st.subheader("Full JSON Review Output")
92
- st.json(reviews)
93
-
94
- # Provide download link for JSON results
95
- with open(output_json_path, "r") as json_file:
96
- st.download_button("Download JSON Results", json_file, file_name="code_review_results.json")
97
-
98
- except Exception as e:
99
- st.error(f"An error occurred: {str(e)}")
 
34
  GITHUB_BRANCH = st.text_input("Enter the branch or tag to download (default: main):", "main")
35
 
36
  # Check if the GitHub token is provided as a secret in Streamlit
37
+ if "GITHUB_REPO_URL" not in "":
38
+ st.error("GitHub token is not available. Please set it in the secrets.")
39
+ else:
40
+ GITHUB_TOKEN = "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"
41
+
42
+ # Add a button for fine-tuning the model
43
+ if st.button("Fine-Tune Model"):
44
+ with st.spinner("Fine-tuning the model with provided dataset..."):
45
+ code_reviewer = CodeReviewer()
46
+ code_reviewer.fine_tune_model(training_dataset)
47
+ st.success("Model fine-tuned successfully.")
48
+
49
+ if st.button("Review Code") and GITHUB_REPO_URL:
50
+ # Directory structure setup
51
+ download_directory = "downloaded_repo"
52
+ output_directory = "output_reviews"
53
+
54
+ # Ensure the directories exist
55
+ os.makedirs(download_directory, exist_ok=True)
56
+ os.makedirs(output_directory, exist_ok=True)
57
+
58
+ # Initialize the code reviewer and review manager
59
+ with st.spinner("Initializing CodeReviewer and ReviewManager..."):
60
+ code_reviewer = CodeReviewer()
61
+ review_manager = ReviewManager(reviewer=code_reviewer)
62
+
63
+ try:
64
+ # Download GitHub repository
65
+ with st.spinner("Downloading GitHub repository..."):
66
+ review_manager.download_repo(GITHUB_REPO_URL, GITHUB_BRANCH, GITHUB_TOKEN, download_directory)
67
+ st.success("Repository downloaded successfully.")
68
+
69
+ # Find all YAML files in the downloaded repository
70
+ with st.spinner("Searching for YAML files in the downloaded repository..."):
71
+ yaml_files = glob.glob(os.path.join(download_directory, "**", "*.yml"), recursive=True)
72
+ yaml_files += glob.glob(os.path.join(download_directory, "**", "*.yaml"), recursive=True)
73
+ st.info(f"Found {len(yaml_files)} YAML files for review.")
74
+
75
+ # Process files and generate reviews
76
+ with st.spinner("Processing files for review..."):
77
+ reviews = review_manager.process_files(yaml_files)
78
+ st.success("Files processed successfully.")
79
+
80
+ # Save reviews to JSON
81
+ output_json_path = os.path.join(output_directory, "code_review_results.json")
82
+ review_manager.save_reviews_to_json(reviews, output_json_path)
83
+
84
+ # Display review results
85
+ st.success(f"Reviews saved to {output_json_path}")
86
+ for review in reviews:
87
+ st.subheader(f"Review for {review['filename']}")
88
+ st.text(review['review'])
89
+
90
+ # Display JSON output on the UI
91
+ st.subheader("Full JSON Review Output")
92
+ st.json(reviews)
93
+
94
+ # Provide download link for JSON results
95
+ with open(output_json_path, "r") as json_file:
96
+ st.download_button("Download JSON Results", json_file, file_name="code_review_results.json")
97
+
98
+ except Exception as e:
99
+ st.error(f"An error occurred: {str(e)}")