acecalisto3 commited on
Commit
e663d46
·
verified ·
1 Parent(s): 795007f

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +56 -72
app.py CHANGED
@@ -69,7 +69,6 @@ class MyChatbot(gr.Chatbot):
69
  }
70
  ]
71
 
72
- # Update the Blocks implementation
73
  with gr.Blocks() as demo:
74
  with gr.Row():
75
  github_api_token = gr.Textbox(label="GitHub API Token", type="password")
@@ -108,36 +107,40 @@ with gr.Blocks() as demo:
108
  # Create state for storing conversation history
109
  state = gr.State([])
110
 
111
- def user(user_message, history):
112
- """Handle user messages"""
113
- return "", history + [[user_message, None]]
 
 
114
 
115
- def bot(history, system_msg, max_tokens, temp, top_p, api_token, username, repo, model, severity, lang):
116
- """Generate bot response"""
117
- if len(history) == 0:
118
- return history
119
-
120
- user_message = history[-1][0]
121
- response = respond(
122
- command=user_message,
123
- history=history[:-1],
124
- system_message=system_msg,
125
- max_tokens=max_tokens,
126
- temperature=temp,
127
- top_p=top_p,
128
- github_api_token=api_token,
129
- github_username=username,
130
- github_repository=repo,
131
- selected_model=model,
132
- severity=severity,
133
- programming_language=lang
134
- )
135
-
136
- history[-1][1] = response['assistant_response']
137
- return history
138
-
139
- # Connect the components
140
- msg.submit(
 
 
141
  user,
142
  [msg, chatbot],
143
  [msg, chatbot]
@@ -159,56 +162,37 @@ with gr.Blocks() as demo:
159
  [chatbot]
160
  )
161
 
162
- # Add a button to fetch GitHub issues
163
- fetch_issues_button = gr.Button(label="Fetch Issues")
164
-
165
- def fetch_issues(api_token, username, repo):
166
- """Fetch GitHub issues and update the chatbot"""
167
- issues = fetch_github_issues(api_token, username, repo)
168
- chatbot.issues = issues
169
- return gr.Dropdown(choices=[f"{i+1}. {issue['title']}" for i, issue in enumerate(issues)])
170
-
171
- fetch_issues_button.click(
172
- fetch_issues,
173
- inputs=[github_api_token, github_username, github_repository],
174
- outputs=[issue_dropdown]
 
 
 
 
 
 
 
 
175
  )
176
 
177
- # Add a dropdown to select an issue
178
- issue_dropdown = gr.Dropdown(label="Select Issue", choices=[], interactive=True)
179
-
180
- def select_issue(selected, chatbot):
181
- """Handle issue selection"""
182
- if selected:
183
- issue_num = int(selected.split('.')[0]) - 1
184
- chatbot.current_issue = chatbot.issues[issue_num]
185
- return chatbot.postprocess({
186
- 'command': str(issue_num + 1),
187
- 'github_api_token': github_api_token.value,
188
- 'github_username': github_username.value,
189
- 'github_repository': github_repository.value,
190
- 'selected_model': model_dropdown.value,
191
- 'severity': severity_dropdown.value,
192
- 'programming_language': programming_language_textbox.value
193
- })
194
- return []
195
-
196
  issue_dropdown.change(
197
  select_issue,
198
  inputs=[issue_dropdown, chatbot],
199
  outputs=[chatbot]
200
  )
201
 
202
- # Add a button to resolve an issue
203
- resolve_issue_button = gr.Button(label="Resolve Issue")
204
-
205
- def resolve_selected_issue(api_token, username, repo, resolution):
206
- """Resolve the currently selected issue"""
207
- if chatbot.current_issue:
208
- issue_number = chatbot.issues.index(chatbot.current_issue)
209
- return resolve_issue(api_token, username, repo, issue_number, resolution)
210
- return "No issue selected"
211
-
212
  resolve_issue_button.click(
213
  resolve_selected_issue,
214
  inputs=[
 
69
  }
70
  ]
71
 
 
72
  with gr.Blocks() as demo:
73
  with gr.Row():
74
  github_api_token = gr.Textbox(label="GitHub API Token", type="password")
 
107
  # Create state for storing conversation history
108
  state = gr.State([])
109
 
110
+ # Add buttons with correct syntax
111
+ fetch_issues_button = gr.Button("Fetch Issues")
112
+ resolve_issue_button = gr.Button("Resolve Issue")
113
+ clear_button = gr.Button("Clear Chat")
114
+ submit_button = gr.Button("Submit Message")
115
 
116
+ # Add a dropdown to select an issue
117
+ issue_dropdown = gr.Dropdown(
118
+ choices=[],
119
+ label="Select Issue",
120
+ interactive=True
121
+ )
122
+
123
+ def clear_chat():
124
+ return [], []
125
+
126
+ def fetch_issues(api_token, username, repo):
127
+ issues = fetch_github_issues(api_token, username, repo)
128
+ chatbot.issues = issues
129
+ return gr.Dropdown(choices=[f"{i+1}. {issue['title']}" for i, issue in enumerate(issues)])
130
+
131
+ # Connect button events
132
+ fetch_issues_button.click(
133
+ fetch_issues,
134
+ inputs=[github_api_token, github_username, github_repository],
135
+ outputs=[issue_dropdown]
136
+ )
137
+
138
+ clear_button.click(
139
+ clear_chat,
140
+ outputs=[chatbot, state]
141
+ )
142
+
143
+ submit_button.click(
144
  user,
145
  [msg, chatbot],
146
  [msg, chatbot]
 
162
  [chatbot]
163
  )
164
 
165
+ # Add message input handler
166
+ msg.submit(
167
+ user,
168
+ [msg, chatbot],
169
+ [msg, chatbot]
170
+ ).then(
171
+ bot,
172
+ [
173
+ chatbot,
174
+ system_message,
175
+ gr.Slider(minimum=1, maximum=8192, value=2048, step=1, label="Max new tokens"),
176
+ gr.Slider(minimum=0.1, maximum=4.0, value=0.71, step=0.1, label="Temperature"),
177
+ gr.Slider(minimum=0.1, maximum=1.0, value=0.95, step=0.01, label="Top-p"),
178
+ github_api_token,
179
+ github_username,
180
+ github_repository,
181
+ model_dropdown,
182
+ severity_dropdown,
183
+ programming_language_textbox
184
+ ],
185
+ [chatbot]
186
  )
187
 
188
+ # Issue selection handler
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
189
  issue_dropdown.change(
190
  select_issue,
191
  inputs=[issue_dropdown, chatbot],
192
  outputs=[chatbot]
193
  )
194
 
195
+ # Issue resolution handler
 
 
 
 
 
 
 
 
 
196
  resolve_issue_button.click(
197
  resolve_selected_issue,
198
  inputs=[