Spaces:
Runtime error
Runtime error
Update app.py
Browse files
app.py
CHANGED
@@ -12,16 +12,14 @@ import atexit
|
|
12 |
import subprocess
|
13 |
from urllib.parse import urlparse, quote
|
14 |
import webbrowser
|
15 |
-
import spaces
|
16 |
|
17 |
-
@spaces.GPU(
|
18 |
# Constants
|
19 |
-
INPUT_DIRECTORY = 'input'
|
20 |
-
OUTPUT_DIRECTORY = 'output'
|
21 |
-
LOGS_DIRECTORY = 'logs'
|
22 |
-
RESOLUTIONS_DIRECTORY = 'resolutions'
|
23 |
-
REPOS_DIRECTORY = 'repos'
|
24 |
-
|
25 |
# Set up logging
|
26 |
def initialize_logger() -> logging.Logger:
|
27 |
log_file = f"{LOGS_DIRECTORY}/github_bot_{datetime.now().strftime('%Y%m%d_%H%M%S')}.log"
|
@@ -41,8 +39,12 @@ def initialize_environment():
|
|
41 |
for directory in directories:
|
42 |
os.makedirs(directory, exist_ok=True)
|
43 |
|
44 |
-
|
45 |
-
|
|
|
|
|
|
|
|
|
46 |
|
47 |
# GitHub API handler
|
48 |
class GitHubAPI:
|
@@ -338,7 +340,7 @@ custom_html = """
|
|
338 |
</div>
|
339 |
</div>
|
340 |
<script>
|
341 |
-
const githubTokenInput = document.getElementById('
|
342 |
const repoUrlInput = document.getElementById('repo-url');
|
343 |
const fetchIssuesButton = document.getElementById('fetch-issues');
|
344 |
const issueDropdown = document.getElementById('issue-dropdown');
|
@@ -357,12 +359,12 @@ custom_html = """
|
|
357 |
return;
|
358 |
}
|
359 |
try {
|
360 |
-
const response = await fetch('/
|
361 |
method: 'POST',
|
362 |
headers: {
|
363 |
'Content-Type': 'application/json',
|
364 |
},
|
365 |
-
body: JSON.stringify({
|
366 |
});
|
367 |
if (!response.ok) {
|
368 |
throw new Error(`HTTP error! status: ${response.status}`);
|
@@ -395,12 +397,12 @@ custom_html = """
|
|
395 |
return;
|
396 |
}
|
397 |
try {
|
398 |
-
const response = await fetch('/
|
399 |
method: 'POST',
|
400 |
headers: {
|
401 |
'Content-Type': 'application/json',
|
402 |
},
|
403 |
-
body: JSON.stringify({
|
404 |
});
|
405 |
if (!response.ok) {
|
406 |
throw new Error(`HTTP error! status: ${response.status}`);
|
@@ -409,7 +411,7 @@ custom_html = """
|
|
409 |
if (data.error) {
|
410 |
outputTextarea.value = data.error;
|
411 |
} else {
|
412 |
-
outputTextarea.value = data.
|
413 |
}
|
414 |
} catch (error) {
|
415 |
outputTextarea.value = `Error resolving issue: ${error.message}`;
|
@@ -423,7 +425,7 @@ custom_html = """
|
|
423 |
return;
|
424 |
}
|
425 |
try {
|
426 |
-
const response = await fetch('/
|
427 |
method: 'POST',
|
428 |
headers: {
|
429 |
'Content-Type': 'application/json',
|
@@ -470,12 +472,18 @@ def signal_handler(signum, frame):
|
|
470 |
cleanup()
|
471 |
sys.exit(0)
|
472 |
|
473 |
-
if __name__ == "
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
474 |
# Register cleanup handlers
|
475 |
atexit.register(cleanup)
|
476 |
signal.signal(signal.SIGINT, signal_handler)
|
477 |
-
signal.signal(signal.SIGTERM, signal_handler)
|
478 |
|
479 |
-
# Create Gradio interface
|
480 |
demo = create_gradio_interface()
|
481 |
demo.launch()
|
|
|
12 |
import subprocess
|
13 |
from urllib.parse import urlparse, quote
|
14 |
import webbrowser
|
|
|
15 |
|
|
|
16 |
# Constants
|
17 |
+
INPUT_DIRECTORY = 'input'
|
18 |
+
OUTPUT_DIRECTORY = 'output'
|
19 |
+
LOGS_DIRECTORY = 'logs'
|
20 |
+
RESOLUTIONS_DIRECTORY = 'resolutions'
|
21 |
+
REPOS_DIRECTORY = 'repos'
|
22 |
+
|
23 |
# Set up logging
|
24 |
def initialize_logger() -> logging.Logger:
|
25 |
log_file = f"{LOGS_DIRECTORY}/github_bot_{datetime.now().strftime('%Y%m%d_%H%M%S')}.log"
|
|
|
39 |
for directory in directories:
|
40 |
os.makedirs(directory, exist_ok=True)
|
41 |
|
42 |
+
# Check if constants are defined
|
43 |
+
def check_constants():
|
44 |
+
constants = ['LOGS_DIRECTORY', 'RESOLUTIONS_DIRECTORY', 'REPOS_DIRECTORY', 'INPUT_DIRECTORY', 'OUTPUT_DIRECTORY']
|
45 |
+
for constant in constants:
|
46 |
+
if constant not in globals():
|
47 |
+
raise NameError(f"Constant '{constant}' is not defined")
|
48 |
|
49 |
# GitHub API handler
|
50 |
class GitHubAPI:
|
|
|
340 |
</div>
|
341 |
</div>
|
342 |
<script>
|
343 |
+
const githubTokenInput = document.getElementById('github-token');
|
344 |
const repoUrlInput = document.getElementById('repo-url');
|
345 |
const fetchIssuesButton = document.getElementById('fetch-issues');
|
346 |
const issueDropdown = document.getElementById('issue-dropdown');
|
|
|
359 |
return;
|
360 |
}
|
361 |
try {
|
362 |
+
const response = await fetch('/fetch_issues', {
|
363 |
method: 'POST',
|
364 |
headers: {
|
365 |
'Content-Type': 'application/json',
|
366 |
},
|
367 |
+
body: JSON.stringify({ token: token, repoUrl: repoUrl }),
|
368 |
});
|
369 |
if (!response.ok) {
|
370 |
throw new Error(`HTTP error! status: ${response.status}`);
|
|
|
397 |
return;
|
398 |
}
|
399 |
try {
|
400 |
+
const response = await fetch('/resolve_issue', {
|
401 |
method: 'POST',
|
402 |
headers: {
|
403 |
'Content-Type': 'application/json',
|
404 |
},
|
405 |
+
body: JSON.stringify({ token: token, repoUrl: repoUrl, issueNumber: issueNumber, resolution: resolution, forkedRepoUrl: forkedRepoUrl }),
|
406 |
});
|
407 |
if (!response.ok) {
|
408 |
throw new Error(`HTTP error! status: ${response.status}`);
|
|
|
411 |
if (data.error) {
|
412 |
outputTextarea.value = data.error;
|
413 |
} else {
|
414 |
+
outputTextarea.value = data.result;
|
415 |
}
|
416 |
} catch (error) {
|
417 |
outputTextarea.value = `Error resolving issue: ${error.message}`;
|
|
|
425 |
return;
|
426 |
}
|
427 |
try {
|
428 |
+
const response = await fetch('/extract_info', {
|
429 |
method: 'POST',
|
430 |
headers: {
|
431 |
'Content-Type': 'application/json',
|
|
|
472 |
cleanup()
|
473 |
sys.exit(0)
|
474 |
|
475 |
+
if __name__ == "__main__":
|
476 |
+
# Check if constants are defined
|
477 |
+
check_constants()
|
478 |
+
|
479 |
+
# Initialize environment and logger
|
480 |
+
initialize_environment()
|
481 |
+
logger = initialize_logger() # Initialize logger globally
|
482 |
+
|
483 |
# Register cleanup handlers
|
484 |
atexit.register(cleanup)
|
485 |
signal.signal(signal.SIGINT, signal_handler)
|
|
|
486 |
|
487 |
+
# Create and launch the Gradio interface
|
488 |
demo = create_gradio_interface()
|
489 |
demo.launch()
|