MalikShehram commited on
Commit
1330579
Β·
verified Β·
1 Parent(s): e1805f0

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +21 -8
app.py CHANGED
@@ -57,17 +57,30 @@ class CodeCopilot:
57
  }
58
  return patterns
59
 
60
- def generate_suggestions(self, patterns):
61
- """Generate suggestions based on detected patterns"""
62
  suggestions = []
 
63
  if patterns['function_def'] > 3:
64
- suggestions.append("πŸ” Consider breaking down into smaller functions or using a class structure.")
 
65
  if patterns['loop'] > 2:
66
- suggestions.append("πŸ”„ You might benefit from list comprehensions or map/filter functions.")
 
 
 
 
67
  if patterns['conditional'] > 3:
68
- suggestions.append("βš– Complex conditionals might be simplified using polymorphism or strategy pattern.")
69
- return "\n".join(suggestions) if suggestions else "No specific suggestions at this time."
70
-
 
 
 
 
 
 
 
71
  def process_input(self, user_input):
72
  """Process user input and generate response"""
73
  patterns = self.analyze_code_patterns(user_input)
@@ -84,7 +97,7 @@ class CodeCopilot:
84
  """
85
 
86
  response = self.get_blackbox_response(prompt)
87
- suggestions = self.generate_suggestions(patterns)
88
 
89
  self.chat_history.append((user_input, response))
90
 
 
57
  }
58
  return patterns
59
 
60
+ def generate_suggestions(self, text, patterns):
61
+ """Generate suggestions based on detected patterns and actual code"""
62
  suggestions = []
63
+
64
  if patterns['function_def'] > 3:
65
+ suggestions.append("πŸ” Your code has many functions. Consider breaking down responsibilities or using classes to organize them.")
66
+
67
  if patterns['loop'] > 2:
68
+ if 'range' in text:
69
+ suggestions.append("πŸ” Detected multiple loops using `range`. You can optimize using Python's `enumerate()` or list comprehensions.")
70
+ else:
71
+ suggestions.append("πŸ”„ You might benefit from list comprehensions or using `map`/`filter` functions.")
72
+
73
  if patterns['conditional'] > 3:
74
+ if 'elif' in text:
75
+ suggestions.append("βš– Your code has multiple conditional branches. Consider using a dictionary-based dispatch or polymorphism.")
76
+ else:
77
+ suggestions.append("🧠 Simplify conditionals with clearer boolean logic or helper functions.")
78
+
79
+ if not suggestions:
80
+ suggestions.append("βœ… Your code looks clean! No major structural improvements detected.")
81
+
82
+ return "\n".join(suggestions)
83
+
84
  def process_input(self, user_input):
85
  """Process user input and generate response"""
86
  patterns = self.analyze_code_patterns(user_input)
 
97
  """
98
 
99
  response = self.get_blackbox_response(prompt)
100
+ suggestions = self.generate_suggestions(user_input, patterns)
101
 
102
  self.chat_history.append((user_input, response))
103