Spaces:
Runtime error
Runtime error
Update app.py
Browse files
app.py
CHANGED
@@ -10,12 +10,8 @@ import requests
|
|
10 |
import gradio as gr
|
11 |
import atexit
|
12 |
import subprocess
|
13 |
-
import
|
14 |
-
import urllib.parse
|
15 |
import warnings
|
16 |
-
import torch
|
17 |
-
import spaces
|
18 |
-
from accelerate import Accelerator
|
19 |
|
20 |
# Constants
|
21 |
INPUT_DIRECTORY = 'input'
|
@@ -37,12 +33,15 @@ def initialize_logger():
|
|
37 |
)
|
38 |
return logging.getLogger(__name__)
|
39 |
|
|
|
|
|
|
|
40 |
# Set up environment
|
41 |
def initialize_environment(input_file, output_directory):
|
42 |
directories = [LOGS_DIRECTORY, RESOLUTIONS_DIRECTORY, REPOS_DIRECTORY, input_file, output_directory]
|
43 |
for directory in directories:
|
44 |
os.makedirs(directory, exist_ok=True)
|
45 |
-
|
46 |
|
47 |
# GitHub API handler
|
48 |
class GitHubAPI:
|
@@ -98,6 +97,7 @@ class GitHubAPI:
|
|
98 |
logger.error(f"Error fetching issues: {str(e)}")
|
99 |
return []
|
100 |
|
|
|
101 |
# GitHub Bot
|
102 |
class GitHubBot:
|
103 |
def __init__(self):
|
@@ -150,11 +150,13 @@ class GitHubBot:
|
|
150 |
logger.error(error_msg)
|
151 |
return error_msg
|
152 |
|
|
|
153 |
def handle_issue_selection(token, owner, repo, issue_number, resolution, forked_repo):
|
154 |
bot = GitHubBot()
|
155 |
result = bot.resolve_issue(token, owner, repo, issue_number, resolution, forked_repo)
|
156 |
return result
|
157 |
|
|
|
158 |
def extract_info_from_url(url: str) -> Dict[str, Any]:
|
159 |
info = {}
|
160 |
try:
|
@@ -164,16 +166,6 @@ def extract_info_from_url(url: str) -> Dict[str, Any]:
|
|
164 |
info['headers'] = dict(response.headers)
|
165 |
info['content'] = response.text[:500] # Limit content to first 500 characters for brevity
|
166 |
|
167 |
-
if 'github.com' in url:
|
168 |
-
parts = url.split('/')
|
169 |
-
if len(parts) > 4:
|
170 |
-
owner = parts[3]
|
171 |
-
repo = parts[4]
|
172 |
-
issues = bot.fetch_issues(github_token, owner, repo)
|
173 |
-
info['issues'] = issues
|
174 |
-
elif 'huggingface.co' in url:
|
175 |
-
# Add Hugging Face specific handling if needed
|
176 |
-
pass
|
177 |
|
178 |
except requests.HTTPError as e:
|
179 |
info['error'] = f"HTTP error: {str(e)}"
|
@@ -181,37 +173,43 @@ def extract_info_from_url(url: str) -> Dict[str, Any]:
|
|
181 |
info['error'] = f"Error: {str(e)}"
|
182 |
return info
|
183 |
|
|
|
184 |
custom_css = """
|
185 |
/* DaisyUI and Tailwind are loaded from CDN */
|
186 |
@import url('https://cdn.jsdelivr.net/npm/[email protected]/dist/full.css');
|
187 |
@import url('https://cdn.tailwindcss.com');
|
188 |
-
|
|
|
189 |
body {
|
190 |
-
background: linear-gradient(to bottom right, #
|
|
|
|
|
191 |
}
|
192 |
-
/* Card styling */
|
193 |
.container {
|
194 |
max-width: 800px;
|
195 |
margin: 2rem auto;
|
196 |
padding: 0 1rem;
|
197 |
}
|
|
|
|
|
|
|
|
|
198 |
.card {
|
199 |
-
background:
|
200 |
border-radius: 1rem;
|
201 |
-
box-shadow: 0 10px 15px -3px rgba(0, 0, 0, 0.
|
202 |
padding: 2rem;
|
|
|
203 |
}
|
204 |
-
/* Form controls */
|
205 |
.input, .select, .textarea {
|
206 |
-
background:
|
207 |
-
border: 1px solid #
|
208 |
-
color: #
|
209 |
border-radius: 0.5rem;
|
210 |
padding: 0.75rem;
|
211 |
width: 100%;
|
212 |
margin-bottom: 1rem;
|
213 |
}
|
214 |
-
/* Buttons */
|
215 |
.button {
|
216 |
width: 100%;
|
217 |
padding: 0.75rem;
|
@@ -219,82 +217,111 @@ custom_css = """
|
|
219 |
font-weight: bold;
|
220 |
cursor: pointer;
|
221 |
transition: all 0.2s;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
222 |
}
|
|
|
223 |
.button-primary {
|
224 |
-
background: #
|
225 |
-
color:
|
|
|
|
|
|
|
|
|
|
|
|
|
226 |
}
|
227 |
.button-success {
|
228 |
-
background: #
|
229 |
-
color:
|
|
|
230 |
}
|
231 |
-
|
232 |
-
|
233 |
-
color: #
|
234 |
-
|
235 |
-
display: block;
|
236 |
}
|
237 |
-
/* Output area */
|
238 |
.output-area {
|
239 |
margin-top: 2rem;
|
240 |
padding: 1rem;
|
241 |
-
background:
|
242 |
border-radius: 0.5rem;
|
243 |
-
color: #
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
244 |
}
|
|
|
245 |
"""
|
246 |
|
247 |
def create_gradio_interface():
|
248 |
bot = GitHubBot()
|
249 |
|
250 |
with gr.Blocks(css=custom_css, theme=gr.themes.Base()) as demo:
|
251 |
-
gr.HTML("""
|
252 |
-
<div class="container">
|
253 |
-
<h1 class="text-4xl font-bold text-white mb-8 text-center">GitHub Issue Manager</h1>
|
254 |
-
<div class="card">
|
255 |
-
""")
|
256 |
-
|
257 |
-
with gr.Group():
|
258 |
-
github_token = gr.Textbox(
|
259 |
-
label="GitHub Token",
|
260 |
-
placeholder="Enter your GitHub token",
|
261 |
-
type="password",
|
262 |
-
elem_classes="input input-bordered input-primary"
|
263 |
-
)
|
264 |
-
repo_link = gr.Textbox(
|
265 |
-
label="Repository Link",
|
266 |
-
placeholder="Enter repository link (e.g., https://github.com/owner/repo)",
|
267 |
-
elem_classes="input input-bordered input-primary"
|
268 |
-
)
|
269 |
-
|
270 |
-
with gr.Group():
|
271 |
-
fetch_button = gr.Button(
|
272 |
-
"Fetch Issues",
|
273 |
-
elem_classes="button button-primary"
|
274 |
-
)
|
275 |
-
issue_dropdown = gr.Dropdown(
|
276 |
-
choices=[],
|
277 |
-
label="Select Issue",
|
278 |
-
interactive=True,
|
279 |
-
elem_classes="select select-primary"
|
280 |
-
)
|
281 |
|
282 |
-
|
283 |
-
|
284 |
-
|
285 |
-
|
286 |
-
|
287 |
-
|
288 |
-
|
289 |
-
|
290 |
-
|
291 |
-
|
292 |
-
|
293 |
-
|
294 |
-
|
295 |
-
|
296 |
-
|
297 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
298 |
|
299 |
output_text = gr.Textbox(
|
300 |
label="Output",
|
@@ -302,24 +329,26 @@ def create_gradio_interface():
|
|
302 |
elem_classes="output-area"
|
303 |
)
|
304 |
|
|
|
305 |
url_textbox = gr.Textbox(
|
306 |
label="URL",
|
307 |
placeholder="Enter a URL to extract information",
|
308 |
elem_classes="input input-bordered input-primary"
|
309 |
)
|
|
|
310 |
extract_button = gr.Button(
|
311 |
"Extract Info",
|
312 |
elem_classes="button button-primary"
|
313 |
)
|
314 |
|
315 |
-
gr.HTML("</div></div>") # Close card and container divs
|
316 |
-
|
317 |
def fetch_issues_handler(token, repo_link):
|
318 |
if not all([token, repo_link]):
|
319 |
return gr.Dropdown.update(choices=["Please provide all required fields"])
|
320 |
|
321 |
owner, repo = repo_link.split('/')[-2:]
|
|
|
322 |
issues = bot.fetch_issues(token, owner, repo)
|
|
|
323 |
if not issues:
|
324 |
return gr.Dropdown.update(choices=["No issues found or error occurred"])
|
325 |
|
@@ -340,9 +369,8 @@ def create_gradio_interface():
|
|
340 |
|
341 |
def extract_info_handler(url):
|
342 |
info = extract_info_from_url(url)
|
343 |
-
return info
|
344 |
|
345 |
-
# Connect components
|
346 |
fetch_button.click(
|
347 |
fetch_issues_handler,
|
348 |
inputs=[github_token, repo_link],
|
@@ -351,13 +379,7 @@ def create_gradio_interface():
|
|
351 |
|
352 |
resolve_button.click(
|
353 |
resolve_issue_handler,
|
354 |
-
inputs=[
|
355 |
-
github_token,
|
356 |
-
repo_link,
|
357 |
-
issue_dropdown,
|
358 |
-
resolution_text,
|
359 |
-
forked_repo
|
360 |
-
],
|
361 |
outputs=[output_text]
|
362 |
)
|
363 |
|
@@ -367,8 +389,11 @@ def create_gradio_interface():
|
|
367 |
outputs=[output_text]
|
368 |
)
|
369 |
|
|
|
370 |
return demo
|
371 |
|
|
|
|
|
372 |
# Cleanup function
|
373 |
def cleanup():
|
374 |
try:
|
@@ -380,12 +405,14 @@ def cleanup():
|
|
380 |
except Exception as e:
|
381 |
print(f"Error during cleanup: {str(e)}")
|
382 |
|
|
|
383 |
# Signal handler
|
384 |
def signal_handler(signum, frame):
|
385 |
logger.info(f"Received signal {signum}")
|
386 |
cleanup()
|
387 |
sys.exit(0)
|
388 |
|
|
|
389 |
if __name__ == "__main__":
|
390 |
# Register cleanup handlers
|
391 |
atexit.register(cleanup)
|
@@ -393,7 +420,7 @@ if __name__ == "__main__":
|
|
393 |
signal.signal(signal.SIGTERM, signal_handler)
|
394 |
|
395 |
# Initialize logger
|
396 |
-
|
397 |
|
398 |
# Create Gradio interface
|
399 |
demo = create_gradio_interface()
|
|
|
10 |
import gradio as gr
|
11 |
import atexit
|
12 |
import subprocess
|
13 |
+
from urllib.parse import urlparse
|
|
|
14 |
import warnings
|
|
|
|
|
|
|
15 |
|
16 |
# Constants
|
17 |
INPUT_DIRECTORY = 'input'
|
|
|
33 |
)
|
34 |
return logging.getLogger(__name__)
|
35 |
|
36 |
+
logger = initialize_logger() # Initialize logger globally
|
37 |
+
|
38 |
+
|
39 |
# Set up environment
|
40 |
def initialize_environment(input_file, output_directory):
|
41 |
directories = [LOGS_DIRECTORY, RESOLUTIONS_DIRECTORY, REPOS_DIRECTORY, input_file, output_directory]
|
42 |
for directory in directories:
|
43 |
os.makedirs(directory, exist_ok=True)
|
44 |
+
|
45 |
|
46 |
# GitHub API handler
|
47 |
class GitHubAPI:
|
|
|
97 |
logger.error(f"Error fetching issues: {str(e)}")
|
98 |
return []
|
99 |
|
100 |
+
|
101 |
# GitHub Bot
|
102 |
class GitHubBot:
|
103 |
def __init__(self):
|
|
|
150 |
logger.error(error_msg)
|
151 |
return error_msg
|
152 |
|
153 |
+
|
154 |
def handle_issue_selection(token, owner, repo, issue_number, resolution, forked_repo):
|
155 |
bot = GitHubBot()
|
156 |
result = bot.resolve_issue(token, owner, repo, issue_number, resolution, forked_repo)
|
157 |
return result
|
158 |
|
159 |
+
|
160 |
def extract_info_from_url(url: str) -> Dict[str, Any]:
|
161 |
info = {}
|
162 |
try:
|
|
|
166 |
info['headers'] = dict(response.headers)
|
167 |
info['content'] = response.text[:500] # Limit content to first 500 characters for brevity
|
168 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
169 |
|
170 |
except requests.HTTPError as e:
|
171 |
info['error'] = f"HTTP error: {str(e)}"
|
|
|
173 |
info['error'] = f"Error: {str(e)}"
|
174 |
return info
|
175 |
|
176 |
+
|
177 |
custom_css = """
|
178 |
/* DaisyUI and Tailwind are loaded from CDN */
|
179 |
@import url('https://cdn.jsdelivr.net/npm/[email protected]/dist/full.css');
|
180 |
@import url('https://cdn.tailwindcss.com');
|
181 |
+
|
182 |
+
/* Futuristic Cyberpunk Style */
|
183 |
body {
|
184 |
+
background: linear-gradient(to bottom right, #1e1e1e, #303030) !important;
|
185 |
+
color: #f0f0f0;
|
186 |
+
font-family: 'Roboto Mono', monospace;
|
187 |
}
|
|
|
188 |
.container {
|
189 |
max-width: 800px;
|
190 |
margin: 2rem auto;
|
191 |
padding: 0 1rem;
|
192 |
}
|
193 |
+
h1 {
|
194 |
+
color: #00c0ff;
|
195 |
+
text-shadow: 0 0 10px #00c0ff; /* Glow effect */
|
196 |
+
}
|
197 |
.card {
|
198 |
+
background: rgba(20,20,20, 0.8);
|
199 |
border-radius: 1rem;
|
200 |
+
box-shadow: 0 10px 15px -3px rgba(0, 0, 0, 0.5);
|
201 |
padding: 2rem;
|
202 |
+
border: 2px solid #00c0ff;
|
203 |
}
|
|
|
204 |
.input, .select, .textarea {
|
205 |
+
background: rgba(20,20,20, 0.9);
|
206 |
+
border: 1px solid #00c0ff;
|
207 |
+
color: #f0f0f0;
|
208 |
border-radius: 0.5rem;
|
209 |
padding: 0.75rem;
|
210 |
width: 100%;
|
211 |
margin-bottom: 1rem;
|
212 |
}
|
|
|
213 |
.button {
|
214 |
width: 100%;
|
215 |
padding: 0.75rem;
|
|
|
217 |
font-weight: bold;
|
218 |
cursor: pointer;
|
219 |
transition: all 0.2s;
|
220 |
+
background: rgba(20, 20, 20, 0.8);
|
221 |
+
border: 2px solid #00c0ff;
|
222 |
+
color: #f0f0f0;
|
223 |
+
}
|
224 |
+
.button:hover {
|
225 |
+
background: rgba(10,10,10, 0.9);
|
226 |
+
border-color: #00ff00; /* Green on hover */
|
227 |
}
|
228 |
+
|
229 |
.button-primary {
|
230 |
+
background: #2c2c2c;
|
231 |
+
color: #f0f0f0;
|
232 |
+
border-color: #00c0ff;
|
233 |
+
}
|
234 |
+
.button-primary:hover {
|
235 |
+
background: #4c4c4c;
|
236 |
+
color: #f0f0f0;
|
237 |
+
border-color: #00ff00;
|
238 |
}
|
239 |
.button-success {
|
240 |
+
background: #2c2c2c;
|
241 |
+
color: #f0f0f0;
|
242 |
+
border-color: #00c0ff;
|
243 |
}
|
244 |
+
.button-success:hover {
|
245 |
+
background: #4c4c4c;
|
246 |
+
color: #f0f0f0;
|
247 |
+
border-color: #00ff00;
|
|
|
248 |
}
|
|
|
249 |
.output-area {
|
250 |
margin-top: 2rem;
|
251 |
padding: 1rem;
|
252 |
+
background: rgba(20, 20, 20, 0.9);
|
253 |
border-radius: 0.5rem;
|
254 |
+
color: #f0f0f0;
|
255 |
+
border: 2px solid #00c0ff;
|
256 |
+
overflow-y: auto;
|
257 |
+
max-height: 300px;
|
258 |
+
}
|
259 |
+
.label {
|
260 |
+
color: #a3a3a3;
|
261 |
+
margin-bottom: 0.5rem;
|
262 |
+
display: block;
|
263 |
}
|
264 |
+
/* Add more styling as needed to refine the look */
|
265 |
"""
|
266 |
|
267 |
def create_gradio_interface():
|
268 |
bot = GitHubBot()
|
269 |
|
270 |
with gr.Blocks(css=custom_css, theme=gr.themes.Base()) as demo:
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
271 |
|
272 |
+
gr.Markdown("<h1 style='color: #00c0ff; text-shadow: 0 0 10px #00c0ff;'>GitHub Issue Manager</h1>")
|
273 |
+
|
274 |
+
with gr.Row():
|
275 |
+
with gr.Column(scale=1):
|
276 |
+
github_token = gr.Textbox(
|
277 |
+
label="GitHub Token",
|
278 |
+
placeholder="Enter your GitHub token",
|
279 |
+
type="password",
|
280 |
+
elem_classes="input input-bordered input-primary"
|
281 |
+
)
|
282 |
+
repo_link = gr.Textbox(
|
283 |
+
label="Repository Link",
|
284 |
+
placeholder="Enter repository link (e.g., https://github.com/owner/repo)",
|
285 |
+
elem_classes="input input-bordered input-primary"
|
286 |
+
)
|
287 |
+
|
288 |
+
with gr.Column(scale=1):
|
289 |
+
fetch_button = gr.Button(
|
290 |
+
"Fetch Issues",
|
291 |
+
elem_classes="button button-primary"
|
292 |
+
)
|
293 |
+
|
294 |
+
with gr.Row():
|
295 |
+
with gr.Column(scale=1):
|
296 |
+
issue_dropdown = gr.Dropdown(
|
297 |
+
choices=[],
|
298 |
+
label="Select Issue",
|
299 |
+
interactive=True,
|
300 |
+
elem_classes="select select-primary"
|
301 |
+
)
|
302 |
+
|
303 |
+
with gr.Column(scale=1):
|
304 |
+
resolution_text = gr.Textbox(
|
305 |
+
label="Resolution",
|
306 |
+
placeholder="Enter your resolution here...",
|
307 |
+
lines=5,
|
308 |
+
elem_classes="textarea textarea-primary"
|
309 |
+
)
|
310 |
+
|
311 |
+
|
312 |
+
with gr.Row():
|
313 |
+
with gr.Column(scale=1):
|
314 |
+
forked_repo = gr.Textbox(
|
315 |
+
label="Forked Repository Path",
|
316 |
+
placeholder="Enter the path of the forked repository",
|
317 |
+
elem_classes="input input-bordered input-primary"
|
318 |
+
)
|
319 |
+
|
320 |
+
with gr.Column(scale=1):
|
321 |
+
resolve_button = gr.Button(
|
322 |
+
"Resolve Issue",
|
323 |
+
elem_classes="button button-success"
|
324 |
+
)
|
325 |
|
326 |
output_text = gr.Textbox(
|
327 |
label="Output",
|
|
|
329 |
elem_classes="output-area"
|
330 |
)
|
331 |
|
332 |
+
|
333 |
url_textbox = gr.Textbox(
|
334 |
label="URL",
|
335 |
placeholder="Enter a URL to extract information",
|
336 |
elem_classes="input input-bordered input-primary"
|
337 |
)
|
338 |
+
|
339 |
extract_button = gr.Button(
|
340 |
"Extract Info",
|
341 |
elem_classes="button button-primary"
|
342 |
)
|
343 |
|
|
|
|
|
344 |
def fetch_issues_handler(token, repo_link):
|
345 |
if not all([token, repo_link]):
|
346 |
return gr.Dropdown.update(choices=["Please provide all required fields"])
|
347 |
|
348 |
owner, repo = repo_link.split('/')[-2:]
|
349 |
+
bot.initialize_api(token)
|
350 |
issues = bot.fetch_issues(token, owner, repo)
|
351 |
+
|
352 |
if not issues:
|
353 |
return gr.Dropdown.update(choices=["No issues found or error occurred"])
|
354 |
|
|
|
369 |
|
370 |
def extract_info_handler(url):
|
371 |
info = extract_info_from_url(url)
|
372 |
+
return str(info)
|
373 |
|
|
|
374 |
fetch_button.click(
|
375 |
fetch_issues_handler,
|
376 |
inputs=[github_token, repo_link],
|
|
|
379 |
|
380 |
resolve_button.click(
|
381 |
resolve_issue_handler,
|
382 |
+
inputs=[github_token, repo_link, issue_dropdown, resolution_text, forked_repo],
|
|
|
|
|
|
|
|
|
|
|
|
|
383 |
outputs=[output_text]
|
384 |
)
|
385 |
|
|
|
389 |
outputs=[output_text]
|
390 |
)
|
391 |
|
392 |
+
|
393 |
return demo
|
394 |
|
395 |
+
|
396 |
+
|
397 |
# Cleanup function
|
398 |
def cleanup():
|
399 |
try:
|
|
|
405 |
except Exception as e:
|
406 |
print(f"Error during cleanup: {str(e)}")
|
407 |
|
408 |
+
|
409 |
# Signal handler
|
410 |
def signal_handler(signum, frame):
|
411 |
logger.info(f"Received signal {signum}")
|
412 |
cleanup()
|
413 |
sys.exit(0)
|
414 |
|
415 |
+
|
416 |
if __name__ == "__main__":
|
417 |
# Register cleanup handlers
|
418 |
atexit.register(cleanup)
|
|
|
420 |
signal.signal(signal.SIGTERM, signal_handler)
|
421 |
|
422 |
# Initialize logger
|
423 |
+
initialize_environment(INPUT_DIRECTORY, OUTPUT_DIRECTORY)
|
424 |
|
425 |
# Create Gradio interface
|
426 |
demo = create_gradio_interface()
|