MalikShehram commited on
Commit
9715ab4
Β·
verified Β·
1 Parent(s): bea0568

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +36 -27
app.py CHANGED
@@ -28,7 +28,6 @@ class CodeCopilot:
28
  }
29
 
30
  try:
31
- # Correct API endpoint based on Blackbox documentation
32
  response = requests.post(
33
  "https://developer.blackbox.ai/api/v1/chat/completions",
34
  headers=headers,
@@ -71,10 +70,8 @@ class CodeCopilot:
71
 
72
  def process_input(self, user_input):
73
  """Process user input and generate response"""
74
- # Analyze patterns
75
  patterns = self.analyze_code_patterns(user_input)
76
 
77
- # Create context-aware prompt
78
  context = "\nPrevious conversation:\n" + "\n".join(
79
  [f"User: {h[0]}\nAI: {h[1]}" for h in self.chat_history[-self.context_window:]])
80
 
@@ -86,11 +83,9 @@ class CodeCopilot:
86
  {user_input}
87
  """
88
 
89
- # Get response
90
  response = self.get_blackbox_response(prompt)
91
  suggestions = self.generate_suggestions(patterns)
92
 
93
- # Update chat history
94
  self.chat_history.append((user_input, response))
95
 
96
  return response, patterns, suggestions
@@ -99,30 +94,45 @@ class CodeCopilot:
99
  copilot = CodeCopilot()
100
 
101
  # Gradio interface
102
- with gr.Blocks(theme=gr.themes.Soft(), title="AI Code Copilot") as demo:
103
- gr.Markdown("""<h1 style="text-align: center">πŸ€– AI Code Copilot</h1>""")
104
-
 
 
 
 
 
 
 
 
 
105
  with gr.Row():
106
- with gr.Column(scale=3):
107
  input_text = gr.Textbox(
108
- label="Your Code or Question",
109
- placeholder="Paste your code or ask a question...",
110
- lines=7
 
111
  )
112
- submit_btn = gr.Button("Generate", variant="primary")
113
-
114
- with gr.Column(scale=7):
115
- with gr.Tab("Assistant Response"):
116
- output_text = gr.Markdown()
117
- with gr.Tab("Suggestions"):
118
- suggestions = gr.Markdown()
119
- with gr.Tab("Pattern Analysis"):
120
- pattern_display = gr.Dataframe(
121
- headers=["Pattern", "Count"],
122
- datatype=["str", "number"],
123
- interactive=False
124
- )
125
-
 
 
 
 
 
126
  def process_input(user_input):
127
  response, patterns, sugg = copilot.process_input(user_input)
128
  pattern_df = pd.DataFrame({
@@ -136,7 +146,6 @@ with gr.Blocks(theme=gr.themes.Soft(), title="AI Code Copilot") as demo:
136
  inputs=input_text,
137
  outputs=[output_text, suggestions, pattern_display]
138
  )
139
-
140
  input_text.submit(
141
  fn=process_input,
142
  inputs=input_text,
 
28
  }
29
 
30
  try:
 
31
  response = requests.post(
32
  "https://developer.blackbox.ai/api/v1/chat/completions",
33
  headers=headers,
 
70
 
71
  def process_input(self, user_input):
72
  """Process user input and generate response"""
 
73
  patterns = self.analyze_code_patterns(user_input)
74
 
 
75
  context = "\nPrevious conversation:\n" + "\n".join(
76
  [f"User: {h[0]}\nAI: {h[1]}" for h in self.chat_history[-self.context_window:]])
77
 
 
83
  {user_input}
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
 
91
  return response, patterns, suggestions
 
94
  copilot = CodeCopilot()
95
 
96
  # Gradio interface
97
+ with gr.Blocks(theme=gr.themes.Soft(), title="πŸ€– AI Code Copilot") as demo:
98
+ # Header
99
+ gr.Markdown(
100
+ """
101
+ <div style='text-align: center; margin-bottom: 1rem;'>
102
+ <h1>πŸ€– AI Code Copilot</h1>
103
+ <p>Your interactive assistant for code suggestions and analysis</p>
104
+ </div>
105
+ """
106
+ )
107
+
108
+ # Main layout: input on the left, outputs on the right
109
  with gr.Row():
110
+ with gr.Column(scale=3, min_width=300):
111
  input_text = gr.Textbox(
112
+ label="Enter your code or question",
113
+ placeholder="Paste code snippets or ask a coding question...",
114
+ lines=10,
115
+ interactive=True
116
  )
117
+ submit_btn = gr.Button("πŸš€ Generate", variant="primary")
118
+
119
+ with gr.Column(scale=5, min_width=500):
120
+ # Display response
121
+ gr.Markdown("**Assistant Response:**")
122
+ output_text = gr.Markdown()
123
+ # Display suggestions
124
+ gr.Markdown("**Suggestions:**")
125
+ suggestions = gr.Markdown()
126
+ # Display pattern analysis
127
+ gr.Markdown("**Pattern Analysis:**")
128
+ pattern_display = gr.Dataframe(
129
+ headers=["Pattern", "Count"],
130
+ datatype=["str", "number"],
131
+ interactive=False,
132
+ label="Detected code patterns"
133
+ )
134
+
135
+ # Processing function for both button and enter
136
  def process_input(user_input):
137
  response, patterns, sugg = copilot.process_input(user_input)
138
  pattern_df = pd.DataFrame({
 
146
  inputs=input_text,
147
  outputs=[output_text, suggestions, pattern_display]
148
  )
 
149
  input_text.submit(
150
  fn=process_input,
151
  inputs=input_text,