abinivas8 commited on
Commit
e3ed8fd
·
verified ·
1 Parent(s): b9b2c9c

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +25 -12
app.py CHANGED
@@ -48,7 +48,7 @@ class GitHubAnalysisResponse(BaseModel):
48
  # GitHub Repository Analyzer
49
  class RepoProductivityAnalyzer:
50
  def __init__(self, github_token: str):
51
- if not github_token or github_token == "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":
52
  raise ValueError("Please provide a valid GitHub token")
53
 
54
  self.token = github_token
@@ -204,38 +204,51 @@ async def predict_productivity(request: ProductivityRequest):
204
  @app.post("/analyze-github", response_model=GitHubAnalysisResponse)
205
  async def analyze_github_repo(request: GitHubAnalysisRequest):
206
  try:
 
 
 
 
207
  analyzer = RepoProductivityAnalyzer(request.github_token)
208
  metrics = analyzer.get_metrics(request.repo_url)
209
 
210
  if "error" in metrics:
211
  raise HTTPException(status_code=400, detail=metrics["error"])
212
 
 
 
 
 
 
213
  # Transform to ML features
214
  ml_features = {
215
- 'daily_coding_hours': min(metrics['commits_per_day'] * 2, 8),
216
- 'commits_per_day': max(int(metrics['commits_per_day']), 0),
217
- 'pull_requests_per_week': max(int(metrics['prs_per_week']), 0),
218
- 'issues_closed_per_week': max(int(metrics['issues_per_week']), 0),
219
  'active_repos': 1,
220
- 'code_reviews_per_week': max(int(metrics['prs_per_week']), 0)
221
  }
222
 
223
  prediction = predict_productivity_core(**ml_features)
224
 
225
  productivity_indicators = {
226
- 'high_commit_frequency': metrics['commits_per_day'] > 1,
227
- 'active_pr_process': metrics['prs_per_week'] > 2,
228
- 'good_issue_resolution': metrics['issues_per_week'] > 1,
229
  'overall_productivity': prediction > 0.7
230
  }
231
 
232
  return GitHubAnalysisResponse(
233
- repo_metrics=metrics, ml_features=ml_features,
234
- predicted_score=prediction, productivity_indicators=productivity_indicators,
 
 
235
  status="success"
236
  )
 
 
237
  except Exception as e:
238
- raise HTTPException(status_code=500, detail=str(e))
239
 
240
  # Gradio Interface Functions
241
  def gradio_predict(daily_coding_hours, commits_per_day, pull_requests_per_week,
 
48
  # GitHub Repository Analyzer
49
  class RepoProductivityAnalyzer:
50
  def __init__(self, github_token: str):
51
+ if not github_token or github_token == "YOUR_TOKEN_HERE":
52
  raise ValueError("Please provide a valid GitHub token")
53
 
54
  self.token = github_token
 
204
  @app.post("/analyze-github", response_model=GitHubAnalysisResponse)
205
  async def analyze_github_repo(request: GitHubAnalysisRequest):
206
  try:
207
+ # Validate inputs
208
+ if not request.repo_url or not request.github_token:
209
+ raise HTTPException(status_code=422, detail="repo_url and github_token are required")
210
+
211
  analyzer = RepoProductivityAnalyzer(request.github_token)
212
  metrics = analyzer.get_metrics(request.repo_url)
213
 
214
  if "error" in metrics:
215
  raise HTTPException(status_code=400, detail=metrics["error"])
216
 
217
+ # Ensure all required metrics exist with defaults
218
+ commits_per_day = float(metrics.get('commits_per_day', 0))
219
+ prs_per_week = float(metrics.get('prs_per_week', 0))
220
+ issues_per_week = float(metrics.get('issues_per_week', 0))
221
+
222
  # Transform to ML features
223
  ml_features = {
224
+ 'daily_coding_hours': min(commits_per_day * 2, 8),
225
+ 'commits_per_day': max(int(commits_per_day), 0),
226
+ 'pull_requests_per_week': max(int(prs_per_week), 0),
227
+ 'issues_closed_per_week': max(int(issues_per_week), 0),
228
  'active_repos': 1,
229
+ 'code_reviews_per_week': max(int(prs_per_week), 0)
230
  }
231
 
232
  prediction = predict_productivity_core(**ml_features)
233
 
234
  productivity_indicators = {
235
+ 'high_commit_frequency': commits_per_day > 1,
236
+ 'active_pr_process': prs_per_week > 2,
237
+ 'good_issue_resolution': issues_per_week > 1,
238
  'overall_productivity': prediction > 0.7
239
  }
240
 
241
  return GitHubAnalysisResponse(
242
+ repo_metrics=metrics,
243
+ ml_features=ml_features,
244
+ predicted_score=float(prediction),
245
+ productivity_indicators=productivity_indicators,
246
  status="success"
247
  )
248
+ except HTTPException:
249
+ raise
250
  except Exception as e:
251
+ raise HTTPException(status_code=500, detail=f"Analysis failed: {str(e)}")
252
 
253
  # Gradio Interface Functions
254
  def gradio_predict(daily_coding_hours, commits_per_day, pull_requests_per_week,