Spaces:
Runtime error
Runtime error
Update app.py
Browse files
app.py
CHANGED
@@ -14,47 +14,6 @@ from urllib.parse import urlparse, quote
|
|
14 |
import webbrowser
|
15 |
import spaces
|
16 |
|
17 |
-
device = "cuda"
|
18 |
-
|
19 |
-
@spaces.GPU()
|
20 |
-
def stream_chat(
|
21 |
-
message: str,
|
22 |
-
history: list,
|
23 |
-
system_prompt: str,
|
24 |
-
temperature: float = 0.5,
|
25 |
-
max_new_tokens: int = 16000,
|
26 |
-
top_p: float = 1.0,
|
27 |
-
top_k: int = 15,
|
28 |
-
penalty: float = 0.9,
|
29 |
-
):
|
30 |
-
print(f'message: {message}')
|
31 |
-
print(f'history: {history}')
|
32 |
-
|
33 |
-
conversation = [
|
34 |
-
{"role": "system", "content": system_prompt}
|
35 |
-
]
|
36 |
-
for prompt, answer in history:
|
37 |
-
conversation.extend([
|
38 |
-
{"role": "user", "content": prompt},
|
39 |
-
{"role": "assistant", "content": answer},
|
40 |
-
])
|
41 |
-
|
42 |
-
conversation.append({"role": "user", "content": message})
|
43 |
-
|
44 |
-
input_ids = tokenizer.apply_chat_template(conversation, add_generation_prompt=True, return_tensors="pt").to(model.device)
|
45 |
-
|
46 |
-
streamer = TextIteratorStreamer(tokenizer, timeout=60.0, skip_prompt=True, skip_special_tokens=True)
|
47 |
-
|
48 |
-
generate_kwargs = dict(
|
49 |
-
input_ids=input_ids,
|
50 |
-
max_new_tokens = max_new_tokens,
|
51 |
-
do_sample = False if temperature == 0 else True,
|
52 |
-
top_p = top_p,
|
53 |
-
top_k = top_k,
|
54 |
-
temperature = temperature,
|
55 |
-
eos_token_id=[128001,128008,128009],
|
56 |
-
streamer=streamer,
|
57 |
-
)
|
58 |
# Constants
|
59 |
INPUT_DIRECTORY = 'input'
|
60 |
OUTPUT_DIRECTORY = 'output'
|
@@ -81,13 +40,6 @@ def initialize_environment():
|
|
81 |
for directory in directories:
|
82 |
os.makedirs(directory, exist_ok=True)
|
83 |
|
84 |
-
# Check if constants are defined
|
85 |
-
def check_constants():
|
86 |
-
constants = ['LOGS_DIRECTORY', 'RESOLUTIONS_DIRECTORY', 'REPOS_DIRECTORY', 'INPUT_DIRECTORY', 'OUTPUT_DIRECTORY']
|
87 |
-
for constant in constants:
|
88 |
-
if constant not in globals():
|
89 |
-
raise NameError(f"Constant '{constant}' is not defined")
|
90 |
-
|
91 |
# GitHub API handler
|
92 |
class GitHubAPI:
|
93 |
def __init__(self, token: str):
|
@@ -401,12 +353,12 @@ custom_html = """
|
|
401 |
return;
|
402 |
}
|
403 |
try {
|
404 |
-
const response = await fetch('/
|
405 |
method: 'POST',
|
406 |
headers: {
|
407 |
'Content-Type': 'application/json',
|
408 |
},
|
409 |
-
body: JSON.stringify({
|
410 |
});
|
411 |
if (!response.ok) {
|
412 |
throw new Error(`HTTP error! status: ${response.status}`);
|
@@ -439,12 +391,12 @@ custom_html = """
|
|
439 |
return;
|
440 |
}
|
441 |
try {
|
442 |
-
const response = await fetch('/
|
443 |
method: 'POST',
|
444 |
headers: {
|
445 |
'Content-Type': 'application/json',
|
446 |
},
|
447 |
-
body: JSON.stringify({
|
448 |
});
|
449 |
if (!response.ok) {
|
450 |
throw new Error(`HTTP error! status: ${response.status}`);
|
@@ -453,7 +405,7 @@ custom_html = """
|
|
453 |
if (data.error) {
|
454 |
outputTextarea.value = data.error;
|
455 |
} else {
|
456 |
-
outputTextarea.value = data.
|
457 |
}
|
458 |
} catch (error) {
|
459 |
outputTextarea.value = `Error resolving issue: ${error.message}`;
|
@@ -467,7 +419,7 @@ custom_html = """
|
|
467 |
return;
|
468 |
}
|
469 |
try {
|
470 |
-
const response = await fetch('/
|
471 |
method: 'POST',
|
472 |
headers: {
|
473 |
'Content-Type': 'application/json',
|
@@ -514,18 +466,20 @@ def signal_handler(signum, frame):
|
|
514 |
cleanup()
|
515 |
sys.exit(0)
|
516 |
|
517 |
-
|
518 |
-
|
519 |
-
check_constants()
|
520 |
-
|
521 |
# Initialize environment and logger
|
522 |
initialize_environment()
|
523 |
-
logger = initialize_logger()
|
524 |
|
525 |
# Register cleanup handlers
|
526 |
atexit.register(cleanup)
|
527 |
signal.signal(signal.SIGINT, signal_handler)
|
|
|
528 |
|
529 |
-
# Create
|
530 |
demo = create_gradio_interface()
|
531 |
-
demo.launch()
|
|
|
|
|
|
|
|
14 |
import webbrowser
|
15 |
import spaces
|
16 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
17 |
# Constants
|
18 |
INPUT_DIRECTORY = 'input'
|
19 |
OUTPUT_DIRECTORY = 'output'
|
|
|
40 |
for directory in directories:
|
41 |
os.makedirs(directory, exist_ok=True)
|
42 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
43 |
# GitHub API handler
|
44 |
class GitHubAPI:
|
45 |
def __init__(self, token: str):
|
|
|
353 |
return;
|
354 |
}
|
355 |
try {
|
356 |
+
const response = await fetch('/fetch-issues', {
|
357 |
method: 'POST',
|
358 |
headers: {
|
359 |
'Content-Type': 'application/json',
|
360 |
},
|
361 |
+
body: JSON.stringify({ githubToken: token, repoUrl: repoUrl }),
|
362 |
});
|
363 |
if (!response.ok) {
|
364 |
throw new Error(`HTTP error! status: ${response.status}`);
|
|
|
391 |
return;
|
392 |
}
|
393 |
try {
|
394 |
+
const response = await fetch('/resolve-issue', {
|
395 |
method: 'POST',
|
396 |
headers: {
|
397 |
'Content-Type': 'application/json',
|
398 |
},
|
399 |
+
body: JSON.stringify({ githubToken: token, repoUrl: repoUrl, issueNumber: issueNumber, resolution: resolution, forkedRepoUrl: forkedRepoUrl }),
|
400 |
});
|
401 |
if (!response.ok) {
|
402 |
throw new Error(`HTTP error! status: ${response.status}`);
|
|
|
405 |
if (data.error) {
|
406 |
outputTextarea.value = data.error;
|
407 |
} else {
|
408 |
+
outputTextarea.value = data.output;
|
409 |
}
|
410 |
} catch (error) {
|
411 |
outputTextarea.value = `Error resolving issue: ${error.message}`;
|
|
|
419 |
return;
|
420 |
}
|
421 |
try {
|
422 |
+
const response = await fetch('/extract-info', {
|
423 |
method: 'POST',
|
424 |
headers: {
|
425 |
'Content-Type': 'application/json',
|
|
|
466 |
cleanup()
|
467 |
sys.exit(0)
|
468 |
|
469 |
+
@spaces.GPU()
|
470 |
+
def main():
|
|
|
|
|
471 |
# Initialize environment and logger
|
472 |
initialize_environment()
|
473 |
+
logger = initialize_logger()
|
474 |
|
475 |
# Register cleanup handlers
|
476 |
atexit.register(cleanup)
|
477 |
signal.signal(signal.SIGINT, signal_handler)
|
478 |
+
signal.signal(signal.SIGTERM, signal_handler)
|
479 |
|
480 |
+
# Create Gradio interface
|
481 |
demo = create_gradio_interface()
|
482 |
+
demo.launch()
|
483 |
+
|
484 |
+
if __name__ == "__main__":
|
485 |
+
main()
|