acecalisto3 commited on
Commit
e7a7e84
·
verified ·
1 Parent(s): 5ae398b

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +12 -35
app.py CHANGED
@@ -15,17 +15,16 @@ import warnings
15
  import webbrowser
16
  import spaces
17
 
18
-
19
- device = "cuda"
20
  @spaces.GPU()
21
  def stream_chat(
22
- message: str,
23
  history: list,
24
  system_prompt: str,
25
- temperature: float = 0.8,
26
- max_new_tokens: int = 1024,
27
- top_p: float = 1.0,
28
- top_k: int = 20,
29
  penalty: float = 1.2,
30
  ):
31
  print(f'message: {message}')
@@ -36,18 +35,18 @@ def stream_chat(
36
  ]
37
  for prompt, answer in history:
38
  conversation.extend([
39
- {"role": "user", "content": prompt},
40
  {"role": "assistant", "content": answer},
41
  ])
42
 
43
  conversation.append({"role": "user", "content": message})
44
 
45
  input_ids = tokenizer.apply_chat_template(conversation, add_generation_prompt=True, return_tensors="pt").to(model.device)
46
-
47
  streamer = TextIteratorStreamer(tokenizer, timeout=60.0, skip_prompt=True, skip_special_tokens=True)
48
-
49
  generate_kwargs = dict(
50
- input_ids=input_ids,
51
  max_new_tokens = max_new_tokens,
52
  do_sample = False if temperature == 0 else True,
53
  top_p = top_p,
@@ -244,7 +243,7 @@ custom_html = """
244
  color: #e0e0e0;
245
  font-family: 'Roboto', sans-serif;
246
  overflow-x: hidden; /* Prevent horizontal scrollbar */
247
-
248
  }
249
  .card {
250
  border-radius: 1.5rem;
@@ -256,12 +255,10 @@ custom_html = """
256
  border-radius: 0.75rem;
257
  padding-inline: 1.5rem;
258
  padding-block: 0.75rem;
259
-
260
  }
261
  h1, h2, h3 {
262
  color: #e0e0e0;
263
  }
264
-
265
  .output-area {
266
  padding: 1.5rem;
267
  border-radius: 0.75rem;
@@ -270,7 +267,6 @@ custom_html = """
270
  border-radius: 0.75rem;
271
  padding-block: 0.75rem;
272
  padding-inline: 1.5rem;
273
-
274
  }
275
  .btn-primary {
276
  background-color: #7928CA;
@@ -286,9 +282,7 @@ custom_html = """
286
  </head>
287
  <body class="bg-gray-900">
288
  <div class="container mx-auto p-4" >
289
-
290
  <h1 class="text-4xl md:text-5xl font-extrabold text-center mb-8">GitHub Issue Manager</h1>
291
-
292
  <!-- GitHub Token & Repo URL -->
293
  <div class="card bg-gray-800 p-8">
294
  <div class="form-control">
@@ -304,13 +298,10 @@ custom_html = """
304
  <input type="text" placeholder="Enter the full GitHub repository URL" class="input input-bordered input-primary" id="repo-url">
305
  </div>
306
  </div>
307
-
308
  <!-- Fetch & Resolve Section -->
309
  <div class="card bg-gray-800 p-8">
310
  <div class="flex justify-between gap-4">
311
-
312
  <button class="btn btn-primary" id="fetch-issues">Fetch Issues</button>
313
-
314
  <select class="select select-primary w-full max-w-xs" id="issue-dropdown" >
315
  <option disabled selected>Select Issue</option>
316
  </select>
@@ -331,7 +322,6 @@ custom_html = """
331
  <button class="btn btn-success" id="resolve-issue">Resolve Issue</button>
332
  </div>
333
  </div>
334
-
335
  <!-- Output Area -->
336
  <div class="card bg-gray-800 p-8 mt-4" >
337
  <label class="label">
@@ -339,7 +329,6 @@ custom_html = """
339
  </label>
340
  <textarea class="textarea textarea-primary h-48" id="output-textarea" readonly></textarea>
341
  </div>
342
-
343
  <!-- URL to Extract -->
344
  <div class="card bg-gray-800 p-8 mt-4">
345
  <div class="form-control">
@@ -352,7 +341,6 @@ custom_html = """
352
  <button class="btn btn-primary" id="extract-info">Extract Info</button>
353
  </div>
354
  </div>
355
-
356
  </div>
357
  <script>
358
  const githubTokenInput = document.getElementById('github-token');
@@ -365,7 +353,6 @@ custom_html = """
365
  const outputTextarea = document.getElementById('output-textarea');
366
  const urlTextbox = document.getElementById('url-textbox');
367
  const extractInfoButton = document.getElementById('extract-info');
368
-
369
  fetchIssuesButton.addEventListener('click', async () => {
370
  const token = githubTokenInput.value;
371
  const repoUrl = repoUrlInput.value;
@@ -381,11 +368,9 @@ custom_html = """
381
  },
382
  body: JSON.stringify({ token: token, repoUrl: repoUrl }),
383
  });
384
-
385
  if (!response.ok) {
386
  throw new Error(`HTTP error! status: ${response.status}`);
387
  }
388
-
389
  const data = await response.json();
390
  if (data.error) {
391
  outputTextarea.value = data.error;
@@ -398,19 +383,16 @@ custom_html = """
398
  issueDropdown.add(option);
399
  });
400
  }
401
-
402
  } catch (error) {
403
  outputTextarea.value = `Error fetching issues: ${error.message}`;
404
  }
405
  });
406
-
407
  resolveIssueButton.addEventListener('click', async () => {
408
  const token = githubTokenInput.value;
409
  const repoUrl = repoUrlInput.value;
410
  const issueNumber = issueDropdown.value;
411
  const resolution = resolutionTextarea.value;
412
  const forkedRepoUrl = forkedRepoUrlInput.value;
413
-
414
  if (!token || !repoUrl || !issueNumber || !resolution) {
415
  outputTextarea.value ="Please provide all required fields.";
416
  return;
@@ -423,11 +405,9 @@ custom_html = """
423
  },
424
  body: JSON.stringify({ token: token, repoUrl: repoUrl, issueNumber: issueNumber, resolution: resolution, forkedRepoUrl: forkedRepoUrl }),
425
  });
426
-
427
  if (!response.ok) {
428
  throw new Error(`HTTP error! status: ${response.status}`);
429
  }
430
-
431
  const data = await response.json();
432
  if (data.error) {
433
  outputTextarea.value = data.error;
@@ -438,7 +418,6 @@ custom_html = """
438
  outputTextarea.value = `Error resolving issue: ${error.message}`;
439
  }
440
  });
441
-
442
  extractInfoButton.addEventListener('click', async () => {
443
  const url = urlTextbox.value;
444
  if (!url) {
@@ -453,11 +432,9 @@ custom_html = """
453
  },
454
  body: JSON.stringify({ url: url }),
455
  });
456
-
457
  if (!response.ok) {
458
  throw new Error(`HTTP error! status: ${response.status}`);
459
  }
460
-
461
  const data = await response.json();
462
  if (data.error) {
463
  outputTextarea.value = data.error;
@@ -468,7 +445,7 @@ custom_html = """
468
  outputTextarea.value = `Error extracting info: ${error.message}`;
469
  }
470
  });
471
-
472
  </script>
473
  </body>
474
  </html>
 
15
  import webbrowser
16
  import spaces
17
 
18
+ device = "cuda"
 
19
  @spaces.GPU()
20
  def stream_chat(
21
+ message: str,
22
  history: list,
23
  system_prompt: str,
24
+ temperature: float = 0.8,
25
+ max_new_tokens: int = 1024,
26
+ top_p: float = 1.0,
27
+ top_k: int = 20,
28
  penalty: float = 1.2,
29
  ):
30
  print(f'message: {message}')
 
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,
 
243
  color: #e0e0e0;
244
  font-family: 'Roboto', sans-serif;
245
  overflow-x: hidden; /* Prevent horizontal scrollbar */
246
+
247
  }
248
  .card {
249
  border-radius: 1.5rem;
 
255
  border-radius: 0.75rem;
256
  padding-inline: 1.5rem;
257
  padding-block: 0.75rem;
 
258
  }
259
  h1, h2, h3 {
260
  color: #e0e0e0;
261
  }
 
262
  .output-area {
263
  padding: 1.5rem;
264
  border-radius: 0.75rem;
 
267
  border-radius: 0.75rem;
268
  padding-block: 0.75rem;
269
  padding-inline: 1.5rem;
 
270
  }
271
  .btn-primary {
272
  background-color: #7928CA;
 
282
  </head>
283
  <body class="bg-gray-900">
284
  <div class="container mx-auto p-4" >
 
285
  <h1 class="text-4xl md:text-5xl font-extrabold text-center mb-8">GitHub Issue Manager</h1>
 
286
  <!-- GitHub Token & Repo URL -->
287
  <div class="card bg-gray-800 p-8">
288
  <div class="form-control">
 
298
  <input type="text" placeholder="Enter the full GitHub repository URL" class="input input-bordered input-primary" id="repo-url">
299
  </div>
300
  </div>
 
301
  <!-- Fetch & Resolve Section -->
302
  <div class="card bg-gray-800 p-8">
303
  <div class="flex justify-between gap-4">
 
304
  <button class="btn btn-primary" id="fetch-issues">Fetch Issues</button>
 
305
  <select class="select select-primary w-full max-w-xs" id="issue-dropdown" >
306
  <option disabled selected>Select Issue</option>
307
  </select>
 
322
  <button class="btn btn-success" id="resolve-issue">Resolve Issue</button>
323
  </div>
324
  </div>
 
325
  <!-- Output Area -->
326
  <div class="card bg-gray-800 p-8 mt-4" >
327
  <label class="label">
 
329
  </label>
330
  <textarea class="textarea textarea-primary h-48" id="output-textarea" readonly></textarea>
331
  </div>
 
332
  <!-- URL to Extract -->
333
  <div class="card bg-gray-800 p-8 mt-4">
334
  <div class="form-control">
 
341
  <button class="btn btn-primary" id="extract-info">Extract Info</button>
342
  </div>
343
  </div>
 
344
  </div>
345
  <script>
346
  const githubTokenInput = document.getElementById('github-token');
 
353
  const outputTextarea = document.getElementById('output-textarea');
354
  const urlTextbox = document.getElementById('url-textbox');
355
  const extractInfoButton = document.getElementById('extract-info');
 
356
  fetchIssuesButton.addEventListener('click', async () => {
357
  const token = githubTokenInput.value;
358
  const repoUrl = repoUrlInput.value;
 
368
  },
369
  body: JSON.stringify({ token: token, repoUrl: repoUrl }),
370
  });
 
371
  if (!response.ok) {
372
  throw new Error(`HTTP error! status: ${response.status}`);
373
  }
 
374
  const data = await response.json();
375
  if (data.error) {
376
  outputTextarea.value = data.error;
 
383
  issueDropdown.add(option);
384
  });
385
  }
 
386
  } catch (error) {
387
  outputTextarea.value = `Error fetching issues: ${error.message}`;
388
  }
389
  });
 
390
  resolveIssueButton.addEventListener('click', async () => {
391
  const token = githubTokenInput.value;
392
  const repoUrl = repoUrlInput.value;
393
  const issueNumber = issueDropdown.value;
394
  const resolution = resolutionTextarea.value;
395
  const forkedRepoUrl = forkedRepoUrlInput.value;
 
396
  if (!token || !repoUrl || !issueNumber || !resolution) {
397
  outputTextarea.value ="Please provide all required fields.";
398
  return;
 
405
  },
406
  body: JSON.stringify({ token: token, repoUrl: repoUrl, issueNumber: issueNumber, resolution: resolution, forkedRepoUrl: forkedRepoUrl }),
407
  });
 
408
  if (!response.ok) {
409
  throw new Error(`HTTP error! status: ${response.status}`);
410
  }
 
411
  const data = await response.json();
412
  if (data.error) {
413
  outputTextarea.value = data.error;
 
418
  outputTextarea.value = `Error resolving issue: ${error.message}`;
419
  }
420
  });
 
421
  extractInfoButton.addEventListener('click', async () => {
422
  const url = urlTextbox.value;
423
  if (!url) {
 
432
  },
433
  body: JSON.stringify({ url: url }),
434
  });
 
435
  if (!response.ok) {
436
  throw new Error(`HTTP error! status: ${response.status}`);
437
  }
 
438
  const data = await response.json();
439
  if (data.error) {
440
  outputTextarea.value = data.error;
 
445
  outputTextarea.value = `Error extracting info: ${error.message}`;
446
  }
447
  });
448
+
449
  </script>
450
  </body>
451
  </html>