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

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +54 -54
app.py CHANGED
@@ -41,59 +41,59 @@ GITHUB_TOKEN = "github_pat_11AF2YOZI0T6NzY3glKc04_40PRSN3Tl0dDhmrEdFZIbNMReQKktV
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)}")
 
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)}")